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