Skip to main content

lean_ctx/cli/
cheatsheet_cmd.rs

1pub fn cmd_cheatsheet() {
2    let ver = env!("CARGO_PKG_VERSION");
3    // Right-aligned in the 31 columns the title leaves inside the 62-column
4    // frame, minus the 2-space gutter before the border. A fixed literal run of
5    // spaces here drifts as soon as the version string changes length.
6    // ponytail: overflows past a 29-char version; cargo versions never get there.
7    let ver_pad = format!("v{ver}");
8    let header = format!(
9        "\x1b[1;36m╔══════════════════════════════════════════════════════════════╗\x1b[0m
10\x1b[1;36m║\x1b[0m  \x1b[1;37mlean-ctx Workflow Cheat Sheet\x1b[0m\x1b[2m{ver_pad:>29}\x1b[0m  \x1b[1;36m║\x1b[0m
11\x1b[1;36m╚══════════════════════════════════════════════════════════════╝\x1b[0m");
12    println!(
13        "{header}
14
15\x1b[1;33m━━━ BEFORE YOU START ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m
16  ctx_session load               \x1b[2m# restore previous session\x1b[0m
17  ctx_overview task=\"...\"         \x1b[2m# task-aware file map\x1b[0m
18  ctx_graph action=build          \x1b[2m# index project (first time)\x1b[0m
19  ctx_knowledge action=recall     \x1b[2m# check stored project facts\x1b[0m
20
21\x1b[1;32m━━━ WHILE CODING ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m
22  ctx_read mode=full    \x1b[2m# first read (cached, re-reads: 99% saved)\x1b[0m
23  ctx_read mode=map     \x1b[2m# context-only files (~93% saved)\x1b[0m
24  ctx_read mode=diff    \x1b[2m# after editing (~98% saved)\x1b[0m
25  ctx_read mode=sigs    \x1b[2m# API surface of large files (~95%)\x1b[0m
26  ctx_multi_read        \x1b[2m# read multiple files at once\x1b[0m
27  ctx_search            \x1b[2m# search with compressed results (~70%)\x1b[0m
28  ctx_shell             \x1b[2m# run CLI with compressed output (~60-90%)\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━━━ MULTI-AGENT ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m
39  ctx_agent action=register       \x1b[2m# announce yourself\x1b[0m
40  ctx_agent action=list           \x1b[2m# see other active agents\x1b[0m
41  ctx_agent action=post           \x1b[2m# share findings\x1b[0m
42  ctx_agent action=read           \x1b[2m# check messages\x1b[0m
43
44\x1b[1;31m━━━ READ MODE DECISION TREE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m
45  Will edit?  → \x1b[1mfull\x1b[0m (re-reads: 13 tokens)  → 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 gain          \x1b[2m# visual savings dashboard\x1b[0m
53  lean-ctx gain --live   \x1b[2m# live auto-updating (Ctrl+C)\x1b[0m
54  lean-ctx dashboard     \x1b[2m# web dashboard with charts\x1b[0m
55  lean-ctx gain --wrapped \x1b[2m# wrapped savings report\x1b[0m
56  lean-ctx discover      \x1b[2m# find uncompressed commands\x1b[0m
57  lean-ctx doctor        \x1b[2m# diagnose installation\x1b[0m
58  lean-ctx update        \x1b[2m# self-update (or 'update 3.8.5' to pin)\x1b[0m
59
60\x1b[2m  Full guide: https://leanctx.com/docs/workflow\x1b[0m"
61    );
62}
63
64pub fn cmd_compression(args: &[String]) {
65    use crate::core::config::{CompressionLevel, Config};
66
67    let action = args.first().map(std::string::String::as_str);
68    if let Some(level @ ("off" | "lite" | "standard" | "max")) = action {
69        if let Err(e) = Config::update_global(|cfg| {
70            cfg.compression_level = match level {
71                "lite" => CompressionLevel::Lite,
72                "standard" => CompressionLevel::Standard,
73                "max" => CompressionLevel::Max,
74                _ => CompressionLevel::Off,
75            };
76        }) {
77            eprintln!("Error saving config: {e}");
78            std::process::exit(1);
79        }
80        let effective = CompressionLevel::from_str_label(level).unwrap_or(CompressionLevel::Off);
81        println!("Compression level: {level} — {}", effective.description());
82        let home = dirs::home_dir().unwrap_or_default();
83        let result = crate::rules_inject::inject_all_rules(&home);
84        if !result.updated.is_empty() {
85            println!(
86                "Updated {} rules file(s) with compression prompt.",
87                result.updated.len()
88            );
89        }
90        println!("Restart your agent/IDE for changes to take effect.");
91    } else {
92        let cfg = Config::load();
93        let effective = CompressionLevel::effective(&cfg);
94        println!("Compression level: {}", effective.label());
95        println!();
96        println!("Usage: lean-ctx compression <off|lite|standard|max>");
97        println!("       lean-ctx terse <off|lite|standard|max>  (alias)");
98        println!();
99        println!("  off      — {}", CompressionLevel::Off.description());
100        println!("  lite     — {}", CompressionLevel::Lite.description());
101        println!("  standard — {}", CompressionLevel::Standard.description());
102        println!("  max      — {}", CompressionLevel::Max.description());
103        println!();
104        println!("Override per session:  LEAN_CTX_COMPRESSION=standard");
105        println!("Override per project:  compression_level = \"standard\" in .lean-ctx.toml");
106        println!();
107
108        let (ta, od, crp, tm) = effective.to_components();
109        let ta_name = match ta {
110            crate::core::config::TerseAgent::Off => "off",
111            crate::core::config::TerseAgent::Lite => "lite",
112            crate::core::config::TerseAgent::Full => "full",
113            crate::core::config::TerseAgent::Ultra => "ultra",
114        };
115        let od_name = match od {
116            crate::core::config::OutputDensity::Normal => "normal",
117            crate::core::config::OutputDensity::Terse => "terse",
118            crate::core::config::OutputDensity::Ultra => "ultra",
119        };
120        println!("Active components:");
121        println!("  Agent prompt:    {ta_name}");
122        println!("  Output density:  {od_name}");
123        println!("  CRP mode:        {crp}");
124        println!("  Terse session:   {tm}");
125    }
126}