lean_ctx/core/value/mod.rs
1//! Value surface: makes what lean-ctx did visible outside the dashboard —
2//! subtly, outside the model's context, and with every number provable.
3//!
4//! * [`snapshot`] — a tiny per-session file the MCP server keeps current, so
5//! status lines and prompt segments render in microseconds without touching
6//! the ledger.
7//! * [`mod@format`] — the shared one-line renderer.
8//! * [`proof`] — recomputes each number from the hash-chained savings ledger
9//! and audit trail and verifies both chains (`lean-ctx value`).
10//! * [`recap`] — when a host hook speaks up (turn and session recaps, weekly
11//! digest), always as a user-only message, never into the model's context.
12//! * [`milestones`] — a native desktop notification ([`notify`]) when a
13//! verified lifetime threshold is first crossed; at most one a day.
14
15pub mod format;
16pub mod milestones;
17pub mod notify;
18pub mod proof;
19pub mod recap;
20pub mod snapshot;
21
22use std::sync::RwLock;
23
24static CURRENT_SESSION: RwLock<Option<String>> = RwLock::new(None);
25
26/// Marks `id` as the session this process is serving. Ledger events and
27/// security events recorded afterwards commit it into their hashes.
28pub fn set_current_session(id: &str) {
29 if id.is_empty() {
30 return;
31 }
32 if let Ok(mut guard) = CURRENT_SESSION.write()
33 && guard.as_deref() != Some(id)
34 {
35 *guard = Some(id.to_string());
36 }
37}
38
39/// The session this process is serving, if it is an MCP server that has
40/// handled a tool call. `None` for CLI, hook and proxy processes.
41pub fn current_session() -> Option<String> {
42 CURRENT_SESSION.read().ok().and_then(|guard| guard.clone())
43}
44
45/// Whether any value display is on (`[value_display] mode`, overridable via
46/// `LEAN_CTX_VALUE_DISPLAY`). The proof chains are written regardless; this
47/// only gates the display snapshot and the user-facing channels.
48pub fn display_enabled() -> bool {
49 crate::core::config::Config::load_arc()
50 .value_display
51 .effective_mode()
52 != crate::core::config::ValueDisplayMode::Off
53}