Skip to main content

lean_ctx_cli/cli/
cheatsheet_cmd.rs

1// SPDX-License-Identifier: Apache-2.0
2pub fn cmd_cheatsheet() {
3    let ver = env!("CARGO_PKG_VERSION");
4    // Right-aligned in the 31 columns the title leaves inside the 62-column
5    // frame, minus the 2-space gutter before the border. A fixed literal run of
6    // spaces here drifts as soon as the version string changes length.
7    // ponytail: overflows past a 29-char version; cargo versions never get there.
8    let ver_pad = format!("v{ver}");
9    let header = format!(
10        "\x1b[1;36m╔══════════════════════════════════════════════════════════════╗\x1b[0m
11\x1b[1;36m║\x1b[0m  \x1b[1;37mlean-ctx Context Cheat Sheet\x1b[0m\x1b[2m{ver_pad:>30}\x1b[0m  \x1b[1;36m║\x1b[0m
12\x1b[1;36m╚══════════════════════════════════════════════════════════════╝\x1b[0m");
13    println!(
14        "{header}
15
16\x1b[1;33m━━━ BEFORE YOU START ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m
17  ctx_session load               \x1b[2m# restore previous session\x1b[0m
18  ctx_compose task=\"...\"          \x1b[2m# ranked files + symbols for a task\x1b[0m
19  ctx_graph action=build          \x1b[2m# index project (first time)\x1b[0m
20  ctx_knowledge action=recall     \x1b[2m# check stored project facts\x1b[0m
21
22\x1b[1;32m━━━ WHILE CODING ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m
23  ctx_read mode=full    \x1b[2m# exact source when you need it\x1b[0m
24  ctx_read mode=map     \x1b[2m# structure and dependencies first\x1b[0m
25  ctx_read mode=diff    \x1b[2m# inspect changes after editing\x1b[0m
26  ctx_read mode=sigs    \x1b[2m# API surface of large files\x1b[0m
27  ctx_search            \x1b[2m# focused search results with references\x1b[0m
28  ctx_shell             \x1b[2m# shape large CLI output with recovery\x1b[0m
29  ctx_read raw=true     \x1b[2m# escape hatch: exact bytes (CLI: lean-ctx raw \"cmd\")\x1b[0m
30
31\x1b[1;35m━━━ AFTER CODING ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m
32  ctx_session finding \"...\"       \x1b[2m# record what you discovered\x1b[0m
33  ctx_session decision \"...\"      \x1b[2m# record architectural choices\x1b[0m
34  ctx_knowledge action=remember   \x1b[2m# store permanent project facts\x1b[0m
35  ctx_knowledge action=consolidate \x1b[2m# import session + run lifecycle\x1b[0m
36  ctx_metrics                     \x1b[2m# see session statistics\x1b[0m
37
38\x1b[1;34m━━━ EXPERIMENTAL LOCAL COLLABORATION (OPT-IN) ━━━━━━━━━━━━━━━\x1b[0m
39  ctx_agent action=register       \x1b[2m# local development helper; not default MCP\x1b[0m
40  ctx_agent action=list           \x1b[2m# inspect local registrations\x1b[0m
41  ctx_agent action=post           \x1b[2m# share a local finding\x1b[0m
42  ctx_agent action=read           \x1b[2m# inspect local messages\x1b[0m
43
44\x1b[1;31m━━━ READ MODE DECISION TREE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m
45  Will edit?  → \x1b[1mfull\x1b[0m (eligible re-reads use cache references)  → after edit: \x1b[1mdiff\x1b[0m
46  API only?   → \x1b[1msignatures\x1b[0m
47  Deps/exports? → \x1b[1mmap\x1b[0m
48  Very large? → \x1b[1mentropy\x1b[0m (information-dense lines)
49  Browsing?   → \x1b[1maggressive\x1b[0m (syntax stripped)
50
51\x1b[1;36m━━━ MONITORING ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m
52  lean-ctx cockpit       \x1b[2m# Savings · Spend · Proof (localhost:3333)\x1b[0m
53  lean-ctx gain          \x1b[2m# terminal summary of local context-usage estimates\x1b[0m
54  lean-ctx gain --wrapped \x1b[2m# local usage summary (recap: Cockpit → #report)\x1b[0m
55  lean-ctx discover      \x1b[2m# find uncompressed commands\x1b[0m
56  lean-ctx doctor        \x1b[2m# diagnose installation\x1b[0m
57  lean-ctx update        \x1b[2m# self-update (or 'update 3.8.5' to pin)\x1b[0m
58
59\x1b[2m  Full guide: https://leanctx.com/docs/workflow\x1b[0m"
60    );
61}
62
63pub fn cmd_compression(args: &[String]) {
64    use lean_ctx::core::config::{CompressionLevel, Config};
65
66    let action = args.first().map(std::string::String::as_str);
67    if let Some(level @ ("off" | "lite" | "standard" | "max")) = action {
68        if let Err(e) = Config::update_global(|cfg| {
69            cfg.compression_level = match level {
70                "lite" => CompressionLevel::Lite,
71                "standard" => CompressionLevel::Standard,
72                "max" => CompressionLevel::Max,
73                _ => CompressionLevel::Off,
74            };
75        }) {
76            eprintln!("Error saving config: {e}");
77            std::process::exit(1);
78        }
79        let effective = CompressionLevel::from_str_label(level).unwrap_or(CompressionLevel::Off);
80        println!("Compression level: {level} — {}", effective.description());
81        let home = dirs::home_dir().unwrap_or_default();
82        let result = lean_ctx::rules_inject::inject_all_rules(&home);
83        if !result.updated.is_empty() {
84            println!(
85                "Updated {} rules file(s) with compression prompt.",
86                result.updated.len()
87            );
88        }
89        println!("Restart your agent/IDE for changes to take effect.");
90    } else {
91        let cfg = Config::load();
92        let effective = CompressionLevel::effective(&cfg);
93        println!("Compression level: {}", effective.label());
94        println!();
95        println!("Usage: lean-ctx compression <off|lite|standard|max>");
96        println!("       lean-ctx terse <off|lite|standard|max>  (alias)");
97        println!();
98        println!("  off      — {}", CompressionLevel::Off.description());
99        println!("  lite     — {}", CompressionLevel::Lite.description());
100        println!("  standard — {}", CompressionLevel::Standard.description());
101        println!("  max      — {}", CompressionLevel::Max.description());
102        println!();
103        println!("Override per session:  LEAN_CTX_COMPRESSION=standard");
104        println!("Override per project:  compression_level = \"standard\" in .lean-ctx.toml");
105        println!();
106
107        let (ta, od, crp, tm) = effective.to_components();
108        let ta_name = match ta {
109            lean_ctx::core::config::TerseAgent::Off => "off",
110            lean_ctx::core::config::TerseAgent::Lite => "lite",
111            lean_ctx::core::config::TerseAgent::Full => "full",
112            lean_ctx::core::config::TerseAgent::Ultra => "ultra",
113        };
114        let od_name = match od {
115            lean_ctx::core::config::OutputDensity::Normal => "normal",
116            lean_ctx::core::config::OutputDensity::Terse => "terse",
117            lean_ctx::core::config::OutputDensity::Ultra => "ultra",
118        };
119        println!("Active components:");
120        println!("  Agent prompt:    {ta_name}");
121        println!("  Output density:  {od_name}");
122        println!("  CRP mode:        {crp}");
123        println!("  Terse session:   {tm}");
124    }
125}