@@ -11,7 +11,10 @@ use crossterm::{
1111} ;
1212
1313use crate :: cli:: chat:: consts:: AGENT_FORMAT_HOOKS_DOC_URL ;
14- use crate :: cli:: chat:: context:: calc_max_context_files_size;
14+ use crate :: cli:: chat:: context:: {
15+ ContextFilePath ,
16+ calc_max_context_files_size,
17+ } ;
1518use crate :: cli:: chat:: token_counter:: TokenCounter ;
1619use crate :: cli:: chat:: util:: drop_matched_context_files;
1720use crate :: cli:: chat:: {
@@ -80,26 +83,77 @@ impl ContextSubcommand {
8083
8184 match self {
8285 Self :: Show { expand } => {
83- let profile_context_files = HashSet :: < ( String , String ) > :: new ( ) ;
86+ // the bool signifies if the resources is temporary (i.e. is it session based as
87+ // opposed to agent based)
88+ let mut profile_context_files = HashSet :: < ( String , String , bool ) > :: new ( ) ;
89+
90+ let ( agent_owned_list, session_owned_list) = context_manager
91+ . paths
92+ . iter ( )
93+ . partition :: < Vec < _ > , _ > ( |p| matches ! ( * * p, ContextFilePath :: Agent ( _) ) ) ;
94+
95+ execute ! (
96+ session. stderr,
97+ style:: SetAttribute ( Attribute :: Bold ) ,
98+ style:: SetForegroundColor ( Color :: Magenta ) ,
99+ style:: Print ( format!( "👤 Agent ({}):\n " , context_manager. current_profile) ) ,
100+ style:: SetAttribute ( Attribute :: Reset ) ,
101+ ) ?;
102+
103+ if agent_owned_list. is_empty ( ) {
104+ execute ! (
105+ session. stderr,
106+ style:: SetForegroundColor ( Color :: DarkGrey ) ,
107+ style:: Print ( " <none>\n \n " ) ,
108+ style:: SetForegroundColor ( Color :: Reset )
109+ ) ?;
110+ } else {
111+ for path in & agent_owned_list {
112+ execute ! ( session. stderr, style:: Print ( format!( " {} " , path. get_path_as_str( ) ) ) ) ?;
113+ if let Ok ( context_files) = context_manager
114+ . get_context_files_by_path ( os, path. get_path_as_str ( ) )
115+ . await
116+ {
117+ execute ! (
118+ session. stderr,
119+ style:: SetForegroundColor ( Color :: Green ) ,
120+ style:: Print ( format!(
121+ "({} match{})" ,
122+ context_files. len( ) ,
123+ if context_files. len( ) == 1 { "" } else { "es" }
124+ ) ) ,
125+ style:: SetForegroundColor ( Color :: Reset )
126+ ) ?;
127+ profile_context_files
128+ . extend ( context_files. into_iter ( ) . map ( |( path, content) | ( path, content, false ) ) ) ;
129+ }
130+ execute ! ( session. stderr, style:: Print ( "\n " ) ) ?;
131+ }
132+ execute ! ( session. stderr, style:: Print ( "\n " ) ) ?;
133+ }
134+
84135 execute ! (
85136 session. stderr,
86137 style:: SetAttribute ( Attribute :: Bold ) ,
87138 style:: SetForegroundColor ( Color :: Magenta ) ,
88- style:: Print ( format! ( " \n 👤 Agent ({} ):\n ", context_manager . current_profile ) ) ,
139+ style:: Print ( "💬 Session (temporary ):\n ") ,
89140 style:: SetAttribute ( Attribute :: Reset ) ,
90141 ) ?;
91142
92- if context_manager . paths . is_empty ( ) {
143+ if session_owned_list . is_empty ( ) {
93144 execute ! (
94145 session. stderr,
95146 style:: SetForegroundColor ( Color :: DarkGrey ) ,
96147 style:: Print ( " <none>\n \n " ) ,
97148 style:: SetForegroundColor ( Color :: Reset )
98149 ) ?;
99150 } else {
100- for path in & context_manager. paths {
101- execute ! ( session. stderr, style:: Print ( format!( " {} " , path) ) ) ?;
102- if let Ok ( context_files) = context_manager. get_context_files_by_path ( os, path) . await {
151+ for path in & session_owned_list {
152+ execute ! ( session. stderr, style:: Print ( format!( " {} " , path. get_path_as_str( ) ) ) ) ?;
153+ if let Ok ( context_files) = context_manager
154+ . get_context_files_by_path ( os, path. get_path_as_str ( ) )
155+ . await
156+ {
103157 execute ! (
104158 session. stderr,
105159 style:: SetForegroundColor ( Color :: Green ) ,
@@ -110,6 +164,8 @@ impl ContextSubcommand {
110164 ) ) ,
111165 style:: SetForegroundColor ( Color :: Reset )
112166 ) ?;
167+ profile_context_files
168+ . extend ( context_files. into_iter ( ) . map ( |( path, content) | ( path, content, true ) ) ) ;
113169 }
114170 execute ! ( session. stderr, style:: Print ( "\n " ) ) ?;
115171 }
@@ -127,7 +183,7 @@ impl ContextSubcommand {
127183 let total = profile_context_files. len ( ) ;
128184 let total_tokens = profile_context_files
129185 . iter ( )
130- . map ( |( _, content) | TokenCounter :: count_tokens ( content) )
186+ . map ( |( _, content, _ ) | TokenCounter :: count_tokens ( content) )
131187 . sum :: < usize > ( ) ;
132188 execute ! (
133189 session. stderr,
@@ -142,11 +198,12 @@ impl ContextSubcommand {
142198 style:: SetAttribute ( Attribute :: Reset )
143199 ) ?;
144200
145- for ( filename, content) in & profile_context_files {
201+ for ( filename, content, is_temporary ) in & profile_context_files {
146202 let est_tokens = TokenCounter :: count_tokens ( content) ;
203+ let icon = if * is_temporary { "💬" } else { "👤" } ;
147204 execute ! (
148205 session. stderr,
149- style:: Print ( format!( "👤 {} " , filename) ) ,
206+ style:: Print ( format!( "{} {} " , icon , filename) ) ,
150207 style:: SetForegroundColor ( Color :: DarkGrey ) ,
151208 style:: Print ( format!( "(~{} tkns)\n " , est_tokens) ) ,
152209 style:: SetForegroundColor ( Color :: Reset ) ,
@@ -166,7 +223,10 @@ impl ContextSubcommand {
166223 }
167224
168225 let context_files_max_size = calc_max_context_files_size ( session. conversation . model . as_deref ( ) ) ;
169- let mut files_as_vec = profile_context_files. iter ( ) . cloned ( ) . collect :: < Vec < _ > > ( ) ;
226+ let mut files_as_vec = profile_context_files
227+ . iter ( )
228+ . map ( |( path, content, _) | ( path. clone ( ) , content. clone ( ) ) )
229+ . collect :: < Vec < _ > > ( ) ;
170230 let dropped_files = drop_matched_context_files ( & mut files_as_vec, context_files_max_size) . ok ( ) ;
171231
172232 execute ! (
@@ -239,7 +299,8 @@ impl ContextSubcommand {
239299 execute ! (
240300 session. stderr,
241301 style:: SetForegroundColor ( Color :: Green ) ,
242- style:: Print ( format!( "\n Added {} path(s) to context.\n \n " , paths. len( ) ) ) ,
302+ style:: Print ( format!( "\n Added {} path(s) to context.\n " , paths. len( ) ) ) ,
303+ style:: Print ( "Note: Context modifications via slash command is temporary.\n \n " ) ,
243304 style:: SetForegroundColor ( Color :: Reset )
244305 ) ?;
245306 } ,
@@ -258,6 +319,7 @@ impl ContextSubcommand {
258319 session. stderr,
259320 style:: SetForegroundColor ( Color :: Green ) ,
260321 style:: Print ( format!( "\n Removed {} path(s) from context.\n \n " , paths. len( ) , ) ) ,
322+ style:: Print ( "Note: Context modifications via slash command is temporary.\n \n " ) ,
261323 style:: SetForegroundColor ( Color :: Reset )
262324 ) ?;
263325 } ,
@@ -275,7 +337,8 @@ impl ContextSubcommand {
275337 execute ! (
276338 session. stderr,
277339 style:: SetForegroundColor ( Color :: Green ) ,
278- style:: Print ( "\n Cleared context\n \n " ) ,
340+ style:: Print ( "\n Cleared context\n " ) ,
341+ style:: Print ( "Note: Context modifications via slash command is temporary.\n \n " ) ,
279342 style:: SetForegroundColor ( Color :: Reset )
280343 ) ?;
281344 } ,
0 commit comments