@@ -161,6 +161,7 @@ use crate::api_client::{
161
161
} ;
162
162
use crate :: auth:: AuthError ;
163
163
use crate :: auth:: builder_id:: is_idc_user;
164
+ use crate :: cli:: chat:: token_counter:: CharCount ;
164
165
use crate :: database:: Database ;
165
166
use crate :: database:: settings:: Setting ;
166
167
use crate :: mcp_client:: {
@@ -2988,13 +2989,19 @@ impl ChatContext {
2988
2989
}
2989
2990
2990
2991
let data = state. calculate_conversation_size ( ) ;
2992
+ let tool_specs_json: String = state
2993
+ . tools
2994
+ . values ( )
2995
+ . filter_map ( |s| serde_json:: to_string ( s) . ok ( ) )
2996
+ . collect ( ) ;
2991
2997
2992
2998
let context_token_count: TokenCount = data. context_messages . into ( ) ;
2993
2999
let assistant_token_count: TokenCount = data. assistant_messages . into ( ) ;
2994
3000
let user_token_count: TokenCount = data. user_messages . into ( ) ;
3001
+ let tools_char_count: CharCount = tool_specs_json. len ( ) . into ( ) ; // usize → CharCount
3002
+ let tools_token_count: TokenCount = tools_char_count. into ( ) ; // CharCount → TokenCount
2995
3003
let total_token_used: TokenCount =
2996
- ( data. context_messages + data. user_messages + data. assistant_messages ) . into ( ) ;
2997
-
3004
+ ( data. context_messages + data. user_messages + data. assistant_messages + tools_char_count) . into ( ) ;
2998
3005
let window_width = self . terminal_width ( ) ;
2999
3006
// set a max width for the progress bar for better aesthetic
3000
3007
let progress_bar_width = std:: cmp:: min ( window_width, 80 ) ;
@@ -3003,13 +3010,18 @@ impl ChatContext {
3003
3010
* progress_bar_width as f64 ) as usize ;
3004
3011
let assistant_width = ( ( assistant_token_count. value ( ) as f64 / CONTEXT_WINDOW_SIZE as f64 )
3005
3012
* progress_bar_width as f64 ) as usize ;
3013
+ let tools_width = ( ( tools_token_count. value ( ) as f64 / CONTEXT_WINDOW_SIZE as f64 )
3014
+ * progress_bar_width as f64 ) as usize ;
3006
3015
let user_width = ( ( user_token_count. value ( ) as f64 / CONTEXT_WINDOW_SIZE as f64 )
3007
3016
* progress_bar_width as f64 ) as usize ;
3008
3017
3009
3018
let left_over_width = progress_bar_width
3010
- - std:: cmp:: min ( context_width + assistant_width + user_width, progress_bar_width) ;
3019
+ - std:: cmp:: min (
3020
+ context_width + assistant_width + user_width + tools_width,
3021
+ progress_bar_width,
3022
+ ) ;
3011
3023
3012
- let is_overflow = ( context_width + assistant_width + user_width) > progress_bar_width;
3024
+ let is_overflow = ( context_width + assistant_width + user_width + tools_width ) > progress_bar_width;
3013
3025
3014
3026
if is_overflow {
3015
3027
queue ! (
@@ -3036,6 +3048,7 @@ impl ChatContext {
3036
3048
total_token_used,
3037
3049
CONTEXT_WINDOW_SIZE / 1000
3038
3050
) ) ,
3051
+ // Context files
3039
3052
style:: SetForegroundColor ( Color :: DarkCyan ) ,
3040
3053
// add a nice visual to mimic "tiny" progress, so the overral progress bar doesn't look too
3041
3054
// empty
@@ -3045,13 +3058,23 @@ impl ChatContext {
3045
3058
0
3046
3059
} ) ) ,
3047
3060
style:: Print ( "█" . repeat( context_width) ) ,
3061
+ // Tools
3062
+ style:: SetForegroundColor ( Color :: DarkRed ) ,
3063
+ style:: Print ( "|" . repeat( if tools_width == 0 && * tools_token_count > 0 {
3064
+ 1
3065
+ } else {
3066
+ 0
3067
+ } ) ) ,
3068
+ style:: Print ( "█" . repeat( tools_width) ) ,
3069
+ // Assistant responses
3048
3070
style:: SetForegroundColor ( Color :: Blue ) ,
3049
3071
style:: Print ( "|" . repeat( if assistant_width == 0 && * assistant_token_count > 0 {
3050
3072
1
3051
3073
} else {
3052
3074
0
3053
3075
} ) ) ,
3054
3076
style:: Print ( "█" . repeat( assistant_width) ) ,
3077
+ // User prompts
3055
3078
style:: SetForegroundColor ( Color :: Magenta ) ,
3056
3079
style:: Print ( "|" . repeat( if user_width == 0 && * user_token_count > 0 { 1 } else { 0 } ) ) ,
3057
3080
style:: Print ( "█" . repeat( user_width) ) ,
@@ -3079,6 +3102,14 @@ impl ChatContext {
3079
3102
context_token_count,
3080
3103
( context_token_count. value( ) as f32 / CONTEXT_WINDOW_SIZE as f32 ) * 100.0
3081
3104
) ) ,
3105
+ style:: SetForegroundColor ( Color :: DarkRed ) ,
3106
+ style:: Print ( "█ Tools: " ) ,
3107
+ style:: SetForegroundColor ( Color :: Reset ) ,
3108
+ style:: Print ( format!(
3109
+ " ~{} tokens ({:.2}%)\n " ,
3110
+ tools_token_count,
3111
+ ( tools_token_count. value( ) as f32 / CONTEXT_WINDOW_SIZE as f32 ) * 100.0
3112
+ ) ) ,
3082
3113
style:: SetForegroundColor ( Color :: Blue ) ,
3083
3114
style:: Print ( "█ Q responses: " ) ,
3084
3115
style:: SetForegroundColor ( Color :: Reset ) ,
0 commit comments