lean_ctx/cli/
cheatsheet_cmd.rs1pub 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 ctx_read raw=true \x1b[2m# escape hatch: exact bytes (CLI: lean-ctx raw \"cmd\")\x1b[0m
26
27\x1b[1;35m━━━ AFTER CODING ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m
28 ctx_session finding \"...\" \x1b[2m# record what you discovered\x1b[0m
29 ctx_session decision \"...\" \x1b[2m# record architectural choices\x1b[0m
30 ctx_knowledge action=remember \x1b[2m# store permanent project facts\x1b[0m
31 ctx_knowledge action=consolidate \x1b[2m# import session + run lifecycle\x1b[0m
32 ctx_metrics \x1b[2m# see session statistics\x1b[0m
33
34\x1b[1;34m━━━ MULTI-AGENT ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m
35 ctx_agent action=register \x1b[2m# announce yourself\x1b[0m
36 ctx_agent action=list \x1b[2m# see other active agents\x1b[0m
37 ctx_agent action=post \x1b[2m# share findings\x1b[0m
38 ctx_agent action=read \x1b[2m# check messages\x1b[0m
39
40\x1b[1;31m━━━ READ MODE DECISION TREE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m
41 Will edit? → \x1b[1mfull\x1b[0m (re-reads: 13 tokens) → after edit: \x1b[1mdiff\x1b[0m
42 API only? → \x1b[1msignatures\x1b[0m
43 Deps/exports? → \x1b[1mmap\x1b[0m
44 Very large? → \x1b[1mentropy\x1b[0m (information-dense lines)
45 Browsing? → \x1b[1maggressive\x1b[0m (syntax stripped)
46
47\x1b[1;36m━━━ MONITORING ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m
48 lean-ctx gain \x1b[2m# visual savings dashboard\x1b[0m
49 lean-ctx gain --live \x1b[2m# live auto-updating (Ctrl+C)\x1b[0m
50 lean-ctx dashboard \x1b[2m# web dashboard with charts\x1b[0m
51 lean-ctx gain --wrapped \x1b[2m# wrapped savings report\x1b[0m
52 lean-ctx discover \x1b[2m# find uncompressed commands\x1b[0m
53 lean-ctx doctor \x1b[2m# diagnose installation\x1b[0m
54 lean-ctx update \x1b[2m# self-update (or 'update 3.8.5' to pin)\x1b[0m
55
56\x1b[2m Full guide: https://leanctx.com/docs/workflow\x1b[0m"
57 );
58}
59
60pub fn cmd_compression(args: &[String]) {
61 use crate::core::config::{CompressionLevel, Config};
62
63 let action = args.first().map(std::string::String::as_str);
64 if let Some(level @ ("off" | "lite" | "standard" | "max")) = action {
65 if let Err(e) = Config::update_global(|cfg| {
66 cfg.compression_level = match level {
67 "lite" => CompressionLevel::Lite,
68 "standard" => CompressionLevel::Standard,
69 "max" => CompressionLevel::Max,
70 _ => CompressionLevel::Off,
71 };
72 }) {
73 eprintln!("Error saving config: {e}");
74 std::process::exit(1);
75 }
76 let effective = CompressionLevel::from_str_label(level).unwrap_or(CompressionLevel::Off);
77 println!("Compression level: {level} — {}", effective.description());
78 let home = dirs::home_dir().unwrap_or_default();
79 let result = crate::rules_inject::inject_all_rules(&home);
80 if !result.updated.is_empty() {
81 println!(
82 "Updated {} rules file(s) with compression prompt.",
83 result.updated.len()
84 );
85 }
86 println!("Restart your agent/IDE for changes to take effect.");
87 } else {
88 let cfg = Config::load();
89 let effective = CompressionLevel::effective(&cfg);
90 println!("Compression level: {}", effective.label());
91 println!();
92 println!("Usage: lean-ctx compression <off|lite|standard|max>");
93 println!(" lean-ctx terse <off|lite|standard|max> (alias)");
94 println!();
95 println!(" off — {}", CompressionLevel::Off.description());
96 println!(" lite — {}", CompressionLevel::Lite.description());
97 println!(" standard — {}", CompressionLevel::Standard.description());
98 println!(" max — {}", CompressionLevel::Max.description());
99 println!();
100 println!("Override per session: LEAN_CTX_COMPRESSION=standard");
101 println!("Override per project: compression_level = \"standard\" in .lean-ctx.toml");
102 println!();
103
104 let (ta, od, crp, tm) = effective.to_components();
105 let ta_name = match ta {
106 crate::core::config::TerseAgent::Off => "off",
107 crate::core::config::TerseAgent::Lite => "lite",
108 crate::core::config::TerseAgent::Full => "full",
109 crate::core::config::TerseAgent::Ultra => "ultra",
110 };
111 let od_name = match od {
112 crate::core::config::OutputDensity::Normal => "normal",
113 crate::core::config::OutputDensity::Terse => "terse",
114 crate::core::config::OutputDensity::Ultra => "ultra",
115 };
116 println!("Active components:");
117 println!(" Agent prompt: {ta_name}");
118 println!(" Output density: {od_name}");
119 println!(" CRP mode: {crp}");
120 println!(" Terse session: {tm}");
121 }
122}