diff --git a/README.md b/README.md index 68116b7..263f99f 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,8 @@ hidden_agents = ["codex"] # abtop also auto-discovers ~/.claude and ~/.claude-* roots that contain # both sessions/ and projects/. claude_config_dirs = ["~/.claude-personal", "~/.claude-work-team"] +# Models with a 1M context window by default (matched by prefix). +context_1m_models = ["claude-fable-5", "claude-opus-5", "claude-sonnet-5", "claude-haiku-5"] # UI language. Omit or leave empty to auto-detect from LANG. language = "zh" ``` diff --git a/src/collector/mod.rs b/src/collector/mod.rs index 930caf1..1811e21 100644 --- a/src/collector/mod.rs +++ b/src/collector/mod.rs @@ -144,8 +144,41 @@ pub(crate) fn context_window_for_model( configured_model: &str, max_context_tokens: u64, ) -> u64 { + context_window_with_1m_models( + transcript_model, + configured_model, + max_context_tokens, + configured_1m_models(), + ) +} + +/// `context_1m_models` from config.toml, for models that are 1M by default and +/// so never show a `[1m]` suffix. Empty in tests. +fn configured_1m_models() -> &'static [String] { + #[cfg(test)] + { + &[] + } + #[cfg(not(test))] + { + static MODELS: std::sync::OnceLock> = std::sync::OnceLock::new(); + MODELS.get_or_init(|| crate::config::load_config().context_1m_models) + } +} + +fn context_window_with_1m_models( + transcript_model: &str, + configured_model: &str, + max_context_tokens: u64, + one_m_models: &[String], +) -> u64 { + let model_lower = transcript_model.to_ascii_lowercase(); + let listed_1m = one_m_models + .iter() + .any(|prefix| model_lower.starts_with(&prefix.to_ascii_lowercase())); if transcript_model.contains("[1m]") || configured_model.contains("[1m]") + || listed_1m || max_context_tokens > 200_000 { 1_000_000 @@ -566,3 +599,39 @@ mod tests { assert!(!scanner.should_start(&[42])); } } + +#[cfg(test)] +mod context_window_tests { + use super::context_window_with_1m_models; + + #[test] + fn listed_prefix_selects_1m_window() { + let models = vec!["claude-fable-5".to_string()]; + assert_eq!( + context_window_with_1m_models("claude-fable-5-1", "fable", 50_000, &models), + 1_000_000 + ); + } + + #[test] + fn prefix_match_is_case_insensitive() { + let models = vec!["Claude-Fable-5".to_string()]; + assert_eq!( + context_window_with_1m_models("claude-fable-5-2", "", 0, &models), + 1_000_000 + ); + } + + #[test] + fn unlisted_model_keeps_200k_default() { + let models = vec!["claude-fable-5".to_string()]; + assert_eq!( + context_window_with_1m_models("claude-opus-4-6", "", 50_000, &models), + 200_000 + ); + assert_eq!( + context_window_with_1m_models("claude-fable-5-1", "", 50_000, &[]), + 200_000 + ); + } +} diff --git a/src/config.rs b/src/config.rs index 4cd5532..28ea45f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -33,6 +33,8 @@ pub struct AppConfig { /// Additional Claude config directories to scan for sessions. /// Useful for multi-profile setups that use separate CLAUDE_CONFIG_DIR roots. pub claude_config_dirs: Vec, + /// Model-name prefixes that get a 1M context window, e.g. ["claude-fable-5"]. + pub context_1m_models: Vec, pub panels: PanelVisibility, /// UI language override. Empty string means auto-detect from `LANG`. /// Recognized values: "en", "zh" (anything starting with "zh" maps to Simplified Chinese). @@ -45,6 +47,7 @@ impl Default for AppConfig { theme: "btop".to_string(), hidden_agents: Vec::new(), claude_config_dirs: Vec::new(), + context_1m_models: Vec::new(), panels: PanelVisibility::default(), language: String::new(), } @@ -93,6 +96,10 @@ fn parse_config_body(content: &str) -> AppConfig { config.claude_config_dirs = parse_path_array(val); continue; } + if key == "context_1m_models" { + config.context_1m_models = parse_string_array(val); + continue; + } let val = val.trim_matches('"').trim_matches('\''); match key { "theme" => config.theme = val.to_string(), @@ -262,6 +269,17 @@ mod tests { assert_eq!(cfg.claude_config_dirs, vec![home.join(".claude-personal")]); } + #[test] + fn parse_config_body_loads_context_1m_models() { + let cfg = + parse_config_body(r#"context_1m_models = ["claude-fable-5", "claude-opus-5"]"#); + + assert_eq!( + cfg.context_1m_models, + vec!["claude-fable-5", "claude-opus-5"] + ); + } + fn theme_update(name: &str) -> Vec<(&'static str, String)> { vec![("theme", format!("\"{}\"", name))] }