refactor: Renamed the compress_threshold setting to compression_threshold

This commit is contained in:
2025-11-07 11:06:20 -07:00
parent 5df435c21a
commit 304129d793
3 changed files with 30 additions and 25 deletions
+1 -1
View File
@@ -79,7 +79,7 @@ enabled_mcp_servers: null # Which MCP servers to enable by default (e.g.
# ---- Session ---- # ---- Session ----
# See the [Session documentation](./docs/SESSIONS.md) for more information # See the [Session documentation](./docs/SESSIONS.md) for more information
save_session: null # Controls the persistence of the session. If true, auto save; if false, don't auto-save save; if null, ask the user what to do save_session: null # Controls the persistence of the session. If true, auto save; if false, don't auto-save save; if null, ask the user what to do
compress_threshold: 4000 # Compress the session when the token count reaches or exceeds this threshold compression_threshold: 4000 # Compress the session when the token count reaches or exceeds this threshold
summarize_prompt: > # The text prompt used for creating a concise summary of session message summarize_prompt: > # The text prompt used for creating a concise summary of session message
'Summarize the discussion briefly in 200 words or less to use as a prompt for future context.' 'Summarize the discussion briefly in 200 words or less to use as a prompt for future context.'
summary_prompt: > # The text prompt used for including the summary of the entire session as context to the model summary_prompt: > # The text prompt used for including the summary of the entire session as context to the model
+19 -16
View File
@@ -144,7 +144,7 @@ pub struct Config {
pub agent_session: Option<String>, pub agent_session: Option<String>,
pub save_session: Option<bool>, pub save_session: Option<bool>,
pub compress_threshold: usize, pub compression_threshold: usize,
pub summarize_prompt: Option<String>, pub summarize_prompt: Option<String>,
pub summary_prompt: Option<String>, pub summary_prompt: Option<String>,
@@ -230,7 +230,7 @@ impl Default for Config {
agent_session: None, agent_session: None,
save_session: None, save_session: None,
compress_threshold: 4000, compression_threshold: 4000,
summarize_prompt: None, summarize_prompt: None,
summary_prompt: None, summary_prompt: None,
@@ -710,7 +710,10 @@ impl Config {
.unwrap_or_else(|| "null".into()), .unwrap_or_else(|| "null".into()),
), ),
("save_session", format_option_value(&self.save_session)), ("save_session", format_option_value(&self.save_session)),
("compress_threshold", self.compress_threshold.to_string()), (
"compression_threshold",
self.compression_threshold.to_string(),
),
( (
"rag_reranker_model", "rag_reranker_model",
format_option_value(&rag_reranker_model), format_option_value(&rag_reranker_model),
@@ -829,9 +832,9 @@ impl Config {
let value = parse_value(value)?; let value = parse_value(value)?;
config.write().set_save_session(value); config.write().set_save_session(value);
} }
"compress_threshold" => { "compression_threshold" => {
let value = parse_value(value)?; let value = parse_value(value)?;
config.write().set_compress_threshold(value); config.write().set_compression_threshold(value);
} }
"rag_reranker_model" => { "rag_reranker_model" => {
let value = parse_value(value)?; let value = parse_value(value)?;
@@ -1000,11 +1003,11 @@ impl Config {
} }
} }
pub fn set_compress_threshold(&mut self, value: Option<usize>) { pub fn set_compression_threshold(&mut self, value: Option<usize>) {
if let Some(session) = self.session.as_mut() { if let Some(session) = self.session.as_mut() {
session.set_compress_threshold(value); session.set_compression_threshold(value);
} else { } else {
self.compress_threshold = value.unwrap_or_default(); self.compression_threshold = value.unwrap_or_default();
} }
} }
@@ -1513,18 +1516,18 @@ impl Config {
} }
pub fn maybe_compress_session(config: GlobalConfig) { pub fn maybe_compress_session(config: GlobalConfig) {
let mut need_compress = false; let mut needs_compression = false;
{ {
let mut config = config.write(); let mut config = config.write();
let compress_threshold = config.compress_threshold; let compression_threshold = config.compression_threshold;
if let Some(session) = config.session.as_mut() { if let Some(session) = config.session.as_mut() {
if session.need_compress(compress_threshold) { if session.needs_compression(compression_threshold) {
session.set_compressing(true); session.set_compressing(true);
need_compress = true; needs_compression = true;
} }
} }
}; };
if !need_compress { if !needs_compression {
return; return;
} }
let color = if config.read().light_theme() { let color = if config.read().light_theme() {
@@ -2200,7 +2203,7 @@ impl Config {
"enabled_tools", "enabled_tools",
"enabled_mcp_servers", "enabled_mcp_servers",
"save_session", "save_session",
"compress_threshold", "compression_threshold",
"rag_reranker_model", "rag_reranker_model",
"rag_top_k", "rag_top_k",
"max_output_tokens", "max_output_tokens",
@@ -2773,8 +2776,8 @@ impl Config {
if let Some(v) = read_env_bool(&get_env_name("save_session")) { if let Some(v) = read_env_bool(&get_env_name("save_session")) {
self.save_session = v; self.save_session = v;
} }
if let Some(Some(v)) = read_env_value::<usize>(&get_env_name("compress_threshold")) { if let Some(Some(v)) = read_env_value::<usize>(&get_env_name("compression_threshold")) {
self.compress_threshold = v; self.compression_threshold = v;
} }
if let Some(v) = read_env_value::<String>(&get_env_name("summarize_prompt")) { if let Some(v) = read_env_value::<String>(&get_env_name("summarize_prompt")) {
self.summarize_prompt = v; self.summarize_prompt = v;
+10 -8
View File
@@ -31,7 +31,7 @@ pub struct Session {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
save_session: Option<bool>, save_session: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
compress_threshold: Option<usize>, compression_threshold: Option<usize>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
role_name: Option<String>, role_name: Option<String>,
@@ -216,8 +216,8 @@ impl Session {
items.push(("save_session", save_session.to_string())); items.push(("save_session", save_session.to_string()));
} }
if let Some(compress_threshold) = self.compress_threshold { if let Some(compression_threshold) = self.compression_threshold {
items.push(("compress_threshold", compress_threshold.to_string())); items.push(("compression_threshold", compression_threshold.to_string()));
} }
if let Some(max_input_tokens) = self.model().max_input_tokens() { if let Some(max_input_tokens) = self.model().max_input_tokens() {
@@ -320,18 +320,20 @@ impl Session {
self.save_session_this_time = true; self.save_session_this_time = true;
} }
pub fn set_compress_threshold(&mut self, value: Option<usize>) { pub fn set_compression_threshold(&mut self, value: Option<usize>) {
if self.compress_threshold != value { if self.compression_threshold != value {
self.compress_threshold = value; self.compression_threshold = value;
self.dirty = true; self.dirty = true;
} }
} }
pub fn need_compress(&self, global_compress_threshold: usize) -> bool { pub fn needs_compression(&self, global_compression_threshold: usize) -> bool {
if self.compressing { if self.compressing {
return false; return false;
} }
let threshold = self.compress_threshold.unwrap_or(global_compress_threshold); let threshold = self
.compression_threshold
.unwrap_or(global_compression_threshold);
if threshold < 1 { if threshold < 1 {
return false; return false;
} }