1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use crate::core::cache::SessionCache;
use crate::tools::{ctx_compress, CrpMode};
pub(crate) fn cmd_compress(args: &[String]) {
let signatures = args.iter().any(|a| a == "--signatures" || a == "-s");
let json = args.iter().any(|a| a == "--json");
#[cfg(unix)]
{
#[cfg(unix)]
if let Some(out) = crate::daemon_client::try_daemon_tool_call_blocking_text(
"ctx_compress",
Some(serde_json::json!({
"include_signatures": signatures
})),
) {
if json {
let payload = serde_json::json!({ "output": out });
println!(
"{}",
serde_json::to_string_pretty(&payload).unwrap_or_else(|_| out.clone())
);
} else {
println!("{out}");
}
return;
}
}
let cache = build_cli_cache();
let out = ctx_compress::handle(&cache, signatures, CrpMode::Off);
if json {
let payload = serde_json::json!({ "output": out });
println!(
"{}",
serde_json::to_string_pretty(&payload).unwrap_or_else(|_| out.clone())
);
} else {
println!("{out}");
}
}
fn build_cli_cache() -> SessionCache {
let mut cache = SessionCache::new();
if let Some(session) = crate::core::session::SessionState::load_latest() {
for ft in &session.files_touched {
if let Ok(content) = std::fs::read_to_string(&ft.path) {
cache.store(&ft.path, &content);
}
}
}
cache
}