@@ -14,6 +14,7 @@ use crate::cli::chat::consts::{
14
14
AGENT_FORMAT_HOOKS_DOC_URL ,
15
15
CONTEXT_FILES_MAX_SIZE ,
16
16
} ;
17
+ use crate :: cli:: chat:: context:: ContextFilePath ;
17
18
use crate :: cli:: chat:: token_counter:: TokenCounter ;
18
19
use crate :: cli:: chat:: util:: drop_matched_context_files;
19
20
use crate :: cli:: chat:: {
@@ -82,26 +83,37 @@ impl ContextSubcommand {
82
83
83
84
match self {
84
85
Self :: Show { expand } => {
85
- 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
+
86
95
execute ! (
87
96
session. stderr,
88
97
style:: SetAttribute ( Attribute :: Bold ) ,
89
98
style:: SetForegroundColor ( Color :: Magenta ) ,
90
- style:: Print ( format!( "\n 👤 Agent ({}):\n " , context_manager. current_profile) ) ,
99
+ style:: Print ( format!( "👤 Agent ({}):\n " , context_manager. current_profile) ) ,
91
100
style:: SetAttribute ( Attribute :: Reset ) ,
92
101
) ?;
93
102
94
- if context_manager . paths . is_empty ( ) {
103
+ if agent_owned_list . is_empty ( ) {
95
104
execute ! (
96
105
session. stderr,
97
106
style:: SetForegroundColor ( Color :: DarkGrey ) ,
98
107
style:: Print ( " <none>\n \n " ) ,
99
108
style:: SetForegroundColor ( Color :: Reset )
100
109
) ?;
101
110
} else {
102
- for path in & context_manager. paths {
103
- execute ! ( session. stderr, style:: Print ( format!( " {} " , path) ) ) ?;
104
- if let Ok ( context_files) = context_manager. get_context_files_by_path ( os, path) . await {
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
+ {
105
117
execute ! (
106
118
session. stderr,
107
119
style:: SetForegroundColor ( Color :: Green ) ,
@@ -112,6 +124,48 @@ impl ContextSubcommand {
112
124
) ) ,
113
125
style:: SetForegroundColor ( Color :: Reset )
114
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
+
135
+ execute ! (
136
+ session. stderr,
137
+ style:: SetAttribute ( Attribute :: Bold ) ,
138
+ style:: SetForegroundColor ( Color :: Magenta ) ,
139
+ style:: Print ( "💬 Session (temporary):\n " ) ,
140
+ style:: SetAttribute ( Attribute :: Reset ) ,
141
+ ) ?;
142
+
143
+ if session_owned_list. is_empty ( ) {
144
+ execute ! (
145
+ session. stderr,
146
+ style:: SetForegroundColor ( Color :: DarkGrey ) ,
147
+ style:: Print ( " <none>\n \n " ) ,
148
+ style:: SetForegroundColor ( Color :: Reset )
149
+ ) ?;
150
+ } else {
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
+ {
157
+ execute ! (
158
+ session. stderr,
159
+ style:: SetForegroundColor ( Color :: Green ) ,
160
+ style:: Print ( format!(
161
+ "({} match{})" ,
162
+ context_files. len( ) ,
163
+ if context_files. len( ) == 1 { "" } else { "es" }
164
+ ) ) ,
165
+ style:: SetForegroundColor ( Color :: Reset )
166
+ ) ?;
167
+ profile_context_files
168
+ . extend ( context_files. into_iter ( ) . map ( |( path, content) | ( path, content, true ) ) ) ;
115
169
}
116
170
execute ! ( session. stderr, style:: Print ( "\n " ) ) ?;
117
171
}
@@ -129,7 +183,7 @@ impl ContextSubcommand {
129
183
let total = profile_context_files. len ( ) ;
130
184
let total_tokens = profile_context_files
131
185
. iter ( )
132
- . map ( |( _, content) | TokenCounter :: count_tokens ( content) )
186
+ . map ( |( _, content, _ ) | TokenCounter :: count_tokens ( content) )
133
187
. sum :: < usize > ( ) ;
134
188
execute ! (
135
189
session. stderr,
@@ -144,11 +198,12 @@ impl ContextSubcommand {
144
198
style:: SetAttribute ( Attribute :: Reset )
145
199
) ?;
146
200
147
- for ( filename, content) in & profile_context_files {
201
+ for ( filename, content, is_temporary ) in & profile_context_files {
148
202
let est_tokens = TokenCounter :: count_tokens ( content) ;
203
+ let icon = if * is_temporary { "💬" } else { "👤" } ;
149
204
execute ! (
150
205
session. stderr,
151
- style:: Print ( format!( "👤 {} " , filename) ) ,
206
+ style:: Print ( format!( "{} {} " , icon , filename) ) ,
152
207
style:: SetForegroundColor ( Color :: DarkGrey ) ,
153
208
style:: Print ( format!( "(~{} tkns)\n " , est_tokens) ) ,
154
209
style:: SetForegroundColor ( Color :: Reset ) ,
@@ -167,7 +222,10 @@ impl ContextSubcommand {
167
222
execute ! ( session. stderr, style:: Print ( format!( "{}\n \n " , "▔" . repeat( 3 ) ) ) , ) ?;
168
223
}
169
224
170
- let mut files_as_vec = profile_context_files. iter ( ) . cloned ( ) . collect :: < Vec < _ > > ( ) ;
225
+ let mut files_as_vec = profile_context_files
226
+ . iter ( )
227
+ . map ( |( path, content, _) | ( path. clone ( ) , content. clone ( ) ) )
228
+ . collect :: < Vec < _ > > ( ) ;
171
229
let dropped_files = drop_matched_context_files ( & mut files_as_vec, CONTEXT_FILES_MAX_SIZE ) . ok ( ) ;
172
230
173
231
execute ! (
@@ -240,7 +298,8 @@ impl ContextSubcommand {
240
298
execute ! (
241
299
session. stderr,
242
300
style:: SetForegroundColor ( Color :: Green ) ,
243
- style:: Print ( format!( "\n Added {} path(s) to context.\n \n " , paths. len( ) ) ) ,
301
+ style:: Print ( format!( "\n Added {} path(s) to context.\n " , paths. len( ) ) ) ,
302
+ style:: Print ( "Note: Context modifications via slash command is temporary.\n \n " ) ,
244
303
style:: SetForegroundColor ( Color :: Reset )
245
304
) ?;
246
305
} ,
@@ -259,6 +318,7 @@ impl ContextSubcommand {
259
318
session. stderr,
260
319
style:: SetForegroundColor ( Color :: Green ) ,
261
320
style:: Print ( format!( "\n Removed {} path(s) from context.\n \n " , paths. len( ) , ) ) ,
321
+ style:: Print ( "Note: Context modifications via slash command is temporary.\n \n " ) ,
262
322
style:: SetForegroundColor ( Color :: Reset )
263
323
) ?;
264
324
} ,
@@ -276,7 +336,8 @@ impl ContextSubcommand {
276
336
execute ! (
277
337
session. stderr,
278
338
style:: SetForegroundColor ( Color :: Green ) ,
279
- style:: Print ( "\n Cleared context\n \n " ) ,
339
+ style:: Print ( "\n Cleared context\n " ) ,
340
+ style:: Print ( "Note: Context modifications via slash command is temporary.\n \n " ) ,
280
341
style:: SetForegroundColor ( Color :: Reset )
281
342
) ?;
282
343
} ,
0 commit comments