@@ -71,7 +71,7 @@ impl ContextSubcommand {
7171 pub async fn execute ( self , ctx : & Context , session : & mut ChatSession ) -> Result < ChatState , ChatError > {
7272 let Some ( context_manager) = & mut session. conversation . context_manager else {
7373 execute ! (
74- session. output ,
74+ session. stderr ,
7575 style:: SetForegroundColor ( Color :: Red ) ,
7676 style:: Print ( "\n Context management is not available.\n \n " ) ,
7777 style:: SetForegroundColor ( Color :: Reset )
@@ -86,7 +86,7 @@ impl ContextSubcommand {
8686 Self :: Show { expand } => {
8787 // Display global context
8888 execute ! (
89- session. output ,
89+ session. stderr ,
9090 style:: SetAttribute ( Attribute :: Bold ) ,
9191 style:: SetForegroundColor ( Color :: Magenta ) ,
9292 style:: Print ( "\n 🌍 global:\n " ) ,
@@ -96,17 +96,17 @@ impl ContextSubcommand {
9696 let mut profile_context_files = HashSet :: new ( ) ;
9797 if context_manager. global_config . paths . is_empty ( ) {
9898 execute ! (
99- session. output ,
99+ session. stderr ,
100100 style:: SetForegroundColor ( Color :: DarkGrey ) ,
101101 style:: Print ( " <none>\n " ) ,
102102 style:: SetForegroundColor ( Color :: Reset )
103103 ) ?;
104104 } else {
105105 for path in & context_manager. global_config . paths {
106- execute ! ( session. output , style:: Print ( format!( " {} " , path) ) ) ?;
106+ execute ! ( session. stderr , style:: Print ( format!( " {} " , path) ) ) ?;
107107 if let Ok ( context_files) = context_manager. get_context_files_by_path ( ctx, path) . await {
108108 execute ! (
109- session. output ,
109+ session. stderr ,
110110 style:: SetForegroundColor ( Color :: Green ) ,
111111 style:: Print ( format!(
112112 "({} match{})" ,
@@ -117,13 +117,13 @@ impl ContextSubcommand {
117117 ) ?;
118118 global_context_files. extend ( context_files) ;
119119 }
120- execute ! ( session. output , style:: Print ( "\n " ) ) ?;
120+ execute ! ( session. stderr , style:: Print ( "\n " ) ) ?;
121121 }
122122 }
123123
124124 // Display profile context
125125 execute ! (
126- session. output ,
126+ session. stderr ,
127127 style:: SetAttribute ( Attribute :: Bold ) ,
128128 style:: SetForegroundColor ( Color :: Magenta ) ,
129129 style:: Print ( format!( "\n 👤 profile ({}):\n " , context_manager. current_profile) ) ,
@@ -132,17 +132,17 @@ impl ContextSubcommand {
132132
133133 if context_manager. profile_config . paths . is_empty ( ) {
134134 execute ! (
135- session. output ,
135+ session. stderr ,
136136 style:: SetForegroundColor ( Color :: DarkGrey ) ,
137137 style:: Print ( " <none>\n \n " ) ,
138138 style:: SetForegroundColor ( Color :: Reset )
139139 ) ?;
140140 } else {
141141 for path in & context_manager. profile_config . paths {
142- execute ! ( session. output , style:: Print ( format!( " {} " , path) ) ) ?;
142+ execute ! ( session. stderr , style:: Print ( format!( " {} " , path) ) ) ?;
143143 if let Ok ( context_files) = context_manager. get_context_files_by_path ( ctx, path) . await {
144144 execute ! (
145- session. output ,
145+ session. stderr ,
146146 style:: SetForegroundColor ( Color :: Green ) ,
147147 style:: Print ( format!(
148148 "({} match{})" ,
@@ -153,14 +153,14 @@ impl ContextSubcommand {
153153 ) ?;
154154 profile_context_files. extend ( context_files) ;
155155 }
156- execute ! ( session. output , style:: Print ( "\n " ) ) ?;
156+ execute ! ( session. stderr , style:: Print ( "\n " ) ) ?;
157157 }
158- execute ! ( session. output , style:: Print ( "\n " ) ) ?;
158+ execute ! ( session. stderr , style:: Print ( "\n " ) ) ?;
159159 }
160160
161161 if global_context_files. is_empty ( ) && profile_context_files. is_empty ( ) {
162162 execute ! (
163- session. output ,
163+ session. stderr ,
164164 style:: SetForegroundColor ( Color :: DarkGrey ) ,
165165 style:: Print ( "No files in the current directory matched the rules above.\n \n " ) ,
166166 style:: SetForegroundColor ( Color :: Reset )
@@ -176,7 +176,7 @@ impl ContextSubcommand {
176176 . map ( |( _, content) | TokenCounter :: count_tokens ( content) )
177177 . sum :: < usize > ( ) ;
178178 execute ! (
179- session. output ,
179+ session. stderr ,
180180 style:: SetForegroundColor ( Color :: Green ) ,
181181 style:: SetAttribute ( Attribute :: Bold ) ,
182182 style:: Print ( format!(
@@ -191,15 +191,15 @@ impl ContextSubcommand {
191191 for ( filename, content) in & global_context_files {
192192 let est_tokens = TokenCounter :: count_tokens ( content) ;
193193 execute ! (
194- session. output ,
194+ session. stderr ,
195195 style:: Print ( format!( "🌍 {} " , filename) ) ,
196196 style:: SetForegroundColor ( Color :: DarkGrey ) ,
197197 style:: Print ( format!( "(~{} tkns)\n " , est_tokens) ) ,
198198 style:: SetForegroundColor ( Color :: Reset ) ,
199199 ) ?;
200200 if expand {
201201 execute ! (
202- session. output ,
202+ session. stderr ,
203203 style:: SetForegroundColor ( Color :: DarkGrey ) ,
204204 style:: Print ( format!( "{}\n \n " , content) ) ,
205205 style:: SetForegroundColor ( Color :: Reset )
@@ -210,15 +210,15 @@ impl ContextSubcommand {
210210 for ( filename, content) in & profile_context_files {
211211 let est_tokens = TokenCounter :: count_tokens ( content) ;
212212 execute ! (
213- session. output ,
213+ session. stderr ,
214214 style:: Print ( format!( "👤 {} " , filename) ) ,
215215 style:: SetForegroundColor ( Color :: DarkGrey ) ,
216216 style:: Print ( format!( "(~{} tkns)\n " , est_tokens) ) ,
217217 style:: SetForegroundColor ( Color :: Reset ) ,
218218 ) ?;
219219 if expand {
220220 execute ! (
221- session. output ,
221+ session. stderr ,
222222 style:: SetForegroundColor ( Color :: DarkGrey ) ,
223223 style:: Print ( format!( "{}\n \n " , content) ) ,
224224 style:: SetForegroundColor ( Color :: Reset )
@@ -227,7 +227,7 @@ impl ContextSubcommand {
227227 }
228228
229229 if expand {
230- execute ! ( session. output , style:: Print ( format!( "{}\n \n " , "▔" . repeat( 3 ) ) ) , ) ?;
230+ execute ! ( session. stderr , style:: Print ( format!( "{}\n \n " , "▔" . repeat( 3 ) ) ) , ) ?;
231231 }
232232
233233 let mut combined_files: Vec < ( String , String ) > = global_context_files
@@ -239,14 +239,14 @@ impl ContextSubcommand {
239239 let dropped_files = drop_matched_context_files ( & mut combined_files, CONTEXT_FILES_MAX_SIZE ) . ok ( ) ;
240240
241241 execute ! (
242- session. output ,
242+ session. stderr ,
243243 style:: Print ( format!( "\n Total: ~{} tokens\n \n " , total_tokens) )
244244 ) ?;
245245
246246 if let Some ( dropped_files) = dropped_files {
247247 if !dropped_files. is_empty ( ) {
248248 execute ! (
249- session. output ,
249+ session. stderr ,
250250 style:: SetForegroundColor ( Color :: DarkYellow ) ,
251251 style:: Print ( format!(
252252 "Total token count exceeds limit: {}. The following files will be automatically dropped when interacting with Q. Consider removing them. \n \n " ,
@@ -261,7 +261,7 @@ impl ContextSubcommand {
261261 for ( filename, content) in truncated_dropped_files {
262262 let est_tokens = TokenCounter :: count_tokens ( content) ;
263263 execute ! (
264- session. output ,
264+ session. stderr ,
265265 style:: Print ( format!( "{} " , filename) ) ,
266266 style:: SetForegroundColor ( Color :: DarkGrey ) ,
267267 style:: Print ( format!( "(~{} tkns)\n " , est_tokens) ) ,
@@ -271,22 +271,22 @@ impl ContextSubcommand {
271271
272272 if total_files > 10 {
273273 execute ! (
274- session. output ,
274+ session. stderr ,
275275 style:: Print ( format!( "({} more files)\n " , total_files - 10 ) )
276276 ) ?;
277277 }
278278 }
279279 }
280280
281- execute ! ( session. output , style:: Print ( "\n " ) ) ?;
281+ execute ! ( session. stderr , style:: Print ( "\n " ) ) ?;
282282 }
283283
284284 // Show last cached session.conversation summary if available, otherwise regenerate it
285285 if expand {
286286 if let Some ( summary) = session. conversation . latest_summary ( ) {
287287 let border = "═" . repeat ( session. terminal_width ( ) . min ( 80 ) ) ;
288288 execute ! (
289- session. output ,
289+ session. stderr ,
290290 style:: Print ( "\n " ) ,
291291 style:: SetForegroundColor ( Color :: Cyan ) ,
292292 style:: Print ( & border) ,
@@ -308,15 +308,15 @@ impl ContextSubcommand {
308308 Ok ( _) => {
309309 let target = if global { "global" } else { "profile" } ;
310310 execute ! (
311- session. output ,
311+ session. stderr ,
312312 style:: SetForegroundColor ( Color :: Green ) ,
313313 style:: Print ( format!( "\n Added {} path(s) to {} context.\n \n " , paths. len( ) , target) ) ,
314314 style:: SetForegroundColor ( Color :: Reset )
315315 ) ?;
316316 } ,
317317 Err ( e) => {
318318 execute ! (
319- session. output ,
319+ session. stderr ,
320320 style:: SetForegroundColor ( Color :: Red ) ,
321321 style:: Print ( format!( "\n Error: {}\n \n " , e) ) ,
322322 style:: SetForegroundColor ( Color :: Reset )
@@ -328,7 +328,7 @@ impl ContextSubcommand {
328328 Ok ( _) => {
329329 let target = if global { "global" } else { "profile" } ;
330330 execute ! (
331- session. output ,
331+ session. stderr ,
332332 style:: SetForegroundColor ( Color :: Green ) ,
333333 style:: Print ( format!(
334334 "\n Removed {} path(s) from {} context.\n \n " ,
@@ -340,7 +340,7 @@ impl ContextSubcommand {
340340 } ,
341341 Err ( e) => {
342342 execute ! (
343- session. output ,
343+ session. stderr ,
344344 style:: SetForegroundColor ( Color :: Red ) ,
345345 style:: Print ( format!( "\n Error: {}\n \n " , e) ) ,
346346 style:: SetForegroundColor ( Color :: Reset )
@@ -355,15 +355,15 @@ impl ContextSubcommand {
355355 format ! ( "profile '{}'" , context_manager. current_profile)
356356 } ;
357357 execute ! (
358- session. output ,
358+ session. stderr ,
359359 style:: SetForegroundColor ( Color :: Green ) ,
360360 style:: Print ( format!( "\n Cleared context for {}\n \n " , target) ) ,
361361 style:: SetForegroundColor ( Color :: Reset )
362362 ) ?;
363363 } ,
364364 Err ( e) => {
365365 execute ! (
366- session. output ,
366+ session. stderr ,
367367 style:: SetForegroundColor ( Color :: Red ) ,
368368 style:: Print ( format!( "\n Error: {}\n \n " , e) ) ,
369369 style:: SetForegroundColor ( Color :: Reset )
0 commit comments