Skip to main content

lean_ctx/cli/
cheatsheet_cmd.rs

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