Skip to main content

Module stats

Module stats 

Source

Structs§

CepSessionSnapshot
Point-in-time snapshot of CEP scores for a single session.
CepStats
Aggregated CEP (Cognitive Efficiency Protocol) metrics across sessions.
CommandStats
Per-command token statistics: invocation count and input/output totals.
CompressionTotals
Token totals for traffic that lean-ctx can compress.
CostBreakdown
Detailed cost comparison: with vs. without lean-ctx compression.
CostModel
LLM pricing model for estimating dollar savings from token compression.
DayStats
Daily aggregate: command count and token totals for one calendar day.
GainSummary
High-level token savings summary for display.
StatsStore
Persistent store for all-time token savings, command stats, and daily history.

Enums§

TrafficClass
Whether a recorded command’s output is controlled by compression.

Constants§

DEFAULT_INPUT_PRICE_PER_M
Average LLM pricing per 1M tokens (blended across Claude, GPT, Gemini).
DEFAULT_OUTPUT_PRICE_PER_M

Functions§

adjust_savings
Adjust saved tokens after post-processing (terse, hints) changed the output size. Positive delta = savings were over-reported, negative = under-reported.
calls_saved_line
The one-line usage result, “N calls, X tokens saved”. Shown by lean-ctx status, lean-ctx doctor and once on MCP server exit; never part of a tool output body (#498).
classify_command
Classifies normalized stats keys, with an explicit passthrough default for control/listing tools so only read, shell, and search output drives the effective-compression denominator.
display_calls_saved_line
calls_saved_line over every data dir holding stats, like gain.
first_session_exit_notice
The stderr line an exiting MCP server prints once per install, after the first session that recorded calls. None when it was printed before, when nothing was recorded yet, or on any I/O error (silently). The numbers use the same data-dir resolution as status, doctor and gain (load_for_display), so all four show the same result.
flush
flush_if_due
Debounced flush: persists at most once per FLUSH_INTERVAL_SECS. Call from post_dispatch on every tool call to bound data loss on abrupt MCP termination to at most 2 seconds of events.
format_cep_report
Renders the full CEP (Cognitive Efficiency Protocol) report with themes.
format_gain
format_gain_body
The dashboard body without the trailing footer (tips / Context OS / hints). Used to compose gain --deep, where the extra themed sections must appear before the footer instead of in the middle of the output.
format_gain_daily
Renders a daily breakdown table of token savings with totals.
format_gain_footer
The standalone gain dashboard footer (contextual tip, Context OS, hints).
format_gain_graph
Renders a 30-day token savings bar chart with sparkline.
format_gain_hero
Renders the concise “hero” gain output — local observations, trend, and next actions.
format_gain_hero_themed
Hero gain with specific theme.
format_gain_json
Returns the full stats store as pretty-printed JSON.
format_gain_themed
Renders the local context-usage dashboard with a specific theme.
format_gain_themed_at
Renders the token savings dashboard at a specific animation tick (with footer).
load
load_all_projects
Every project store by its project key (for the device view’s split).
load_for_display
Loads stats for display, summing across every auto-resolved data dir that holds a stats.json (#500). When the MCP server process and the CLI resolve different XDG dirs — the documented #408/#414 split, common when an agent host (e.g. a containerised Hermes) launches the MCP server with a different HOME or XDG_* than the user’s shell — the bulk of the savings can land in a sibling tree. Reading only the primary dir then makes gain report 0 while the real data sits one directory over. Folding the siblings in keeps the headline honest regardless of which process wrote where.
load_for_project
The usage counters of one project: the stores of its project keys, summed.
load_stats
merge_additive
Additively merge two stores (used by data consolidation to combine split stats.json files without losing data from either side).
normalize_command
project_stores
Every project’s own store (<data>/project-stats/<key>) with its project key, sorted by key.
record
record_at_turn
Records a tool result against an observed provider turn. turn == 0 keeps daemon-free callers honest: first injection is known, re-read count is not.
record_cep_session
record_reread
reset_all
reset_cep
save