@@ -71,7 +71,7 @@ impl ContextSubcommand {
71
71
pub async fn execute ( self , ctx : & Context , session : & mut ChatSession ) -> Result < ChatState , ChatError > {
72
72
let Some ( context_manager) = & mut session. conversation . context_manager else {
73
73
execute ! (
74
- session. output ,
74
+ session. stderr ,
75
75
style:: SetForegroundColor ( Color :: Red ) ,
76
76
style:: Print ( "\n Context management is not available.\n \n " ) ,
77
77
style:: SetForegroundColor ( Color :: Reset )
@@ -86,7 +86,7 @@ impl ContextSubcommand {
86
86
Self :: Show { expand } => {
87
87
// Display global context
88
88
execute ! (
89
- session. output ,
89
+ session. stderr ,
90
90
style:: SetAttribute ( Attribute :: Bold ) ,
91
91
style:: SetForegroundColor ( Color :: Magenta ) ,
92
92
style:: Print ( "\n 🌍 global:\n " ) ,
@@ -96,17 +96,17 @@ impl ContextSubcommand {
96
96
let mut profile_context_files = HashSet :: new ( ) ;
97
97
if context_manager. global_config . paths . is_empty ( ) {
98
98
execute ! (
99
- session. output ,
99
+ session. stderr ,
100
100
style:: SetForegroundColor ( Color :: DarkGrey ) ,
101
101
style:: Print ( " <none>\n " ) ,
102
102
style:: SetForegroundColor ( Color :: Reset )
103
103
) ?;
104
104
} else {
105
105
for path in & context_manager. global_config . paths {
106
- execute ! ( session. output , style:: Print ( format!( " {} " , path) ) ) ?;
106
+ execute ! ( session. stderr , style:: Print ( format!( " {} " , path) ) ) ?;
107
107
if let Ok ( context_files) = context_manager. get_context_files_by_path ( ctx, path) . await {
108
108
execute ! (
109
- session. output ,
109
+ session. stderr ,
110
110
style:: SetForegroundColor ( Color :: Green ) ,
111
111
style:: Print ( format!(
112
112
"({} match{})" ,
@@ -117,13 +117,13 @@ impl ContextSubcommand {
117
117
) ?;
118
118
global_context_files. extend ( context_files) ;
119
119
}
120
- execute ! ( session. output , style:: Print ( "\n " ) ) ?;
120
+ execute ! ( session. stderr , style:: Print ( "\n " ) ) ?;
121
121
}
122
122
}
123
123
124
124
// Display profile context
125
125
execute ! (
126
- session. output ,
126
+ session. stderr ,
127
127
style:: SetAttribute ( Attribute :: Bold ) ,
128
128
style:: SetForegroundColor ( Color :: Magenta ) ,
129
129
style:: Print ( format!( "\n 👤 profile ({}):\n " , context_manager. current_profile) ) ,
@@ -132,17 +132,17 @@ impl ContextSubcommand {
132
132
133
133
if context_manager. profile_config . paths . is_empty ( ) {
134
134
execute ! (
135
- session. output ,
135
+ session. stderr ,
136
136
style:: SetForegroundColor ( Color :: DarkGrey ) ,
137
137
style:: Print ( " <none>\n \n " ) ,
138
138
style:: SetForegroundColor ( Color :: Reset )
139
139
) ?;
140
140
} else {
141
141
for path in & context_manager. profile_config . paths {
142
- execute ! ( session. output , style:: Print ( format!( " {} " , path) ) ) ?;
142
+ execute ! ( session. stderr , style:: Print ( format!( " {} " , path) ) ) ?;
143
143
if let Ok ( context_files) = context_manager. get_context_files_by_path ( ctx, path) . await {
144
144
execute ! (
145
- session. output ,
145
+ session. stderr ,
146
146
style:: SetForegroundColor ( Color :: Green ) ,
147
147
style:: Print ( format!(
148
148
"({} match{})" ,
@@ -153,14 +153,14 @@ impl ContextSubcommand {
153
153
) ?;
154
154
profile_context_files. extend ( context_files) ;
155
155
}
156
- execute ! ( session. output , style:: Print ( "\n " ) ) ?;
156
+ execute ! ( session. stderr , style:: Print ( "\n " ) ) ?;
157
157
}
158
- execute ! ( session. output , style:: Print ( "\n " ) ) ?;
158
+ execute ! ( session. stderr , style:: Print ( "\n " ) ) ?;
159
159
}
160
160
161
161
if global_context_files. is_empty ( ) && profile_context_files. is_empty ( ) {
162
162
execute ! (
163
- session. output ,
163
+ session. stderr ,
164
164
style:: SetForegroundColor ( Color :: DarkGrey ) ,
165
165
style:: Print ( "No files in the current directory matched the rules above.\n \n " ) ,
166
166
style:: SetForegroundColor ( Color :: Reset )
@@ -176,7 +176,7 @@ impl ContextSubcommand {
176
176
. map ( |( _, content) | TokenCounter :: count_tokens ( content) )
177
177
. sum :: < usize > ( ) ;
178
178
execute ! (
179
- session. output ,
179
+ session. stderr ,
180
180
style:: SetForegroundColor ( Color :: Green ) ,
181
181
style:: SetAttribute ( Attribute :: Bold ) ,
182
182
style:: Print ( format!(
@@ -191,15 +191,15 @@ impl ContextSubcommand {
191
191
for ( filename, content) in & global_context_files {
192
192
let est_tokens = TokenCounter :: count_tokens ( content) ;
193
193
execute ! (
194
- session. output ,
194
+ session. stderr ,
195
195
style:: Print ( format!( "🌍 {} " , filename) ) ,
196
196
style:: SetForegroundColor ( Color :: DarkGrey ) ,
197
197
style:: Print ( format!( "(~{} tkns)\n " , est_tokens) ) ,
198
198
style:: SetForegroundColor ( Color :: Reset ) ,
199
199
) ?;
200
200
if expand {
201
201
execute ! (
202
- session. output ,
202
+ session. stderr ,
203
203
style:: SetForegroundColor ( Color :: DarkGrey ) ,
204
204
style:: Print ( format!( "{}\n \n " , content) ) ,
205
205
style:: SetForegroundColor ( Color :: Reset )
@@ -210,15 +210,15 @@ impl ContextSubcommand {
210
210
for ( filename, content) in & profile_context_files {
211
211
let est_tokens = TokenCounter :: count_tokens ( content) ;
212
212
execute ! (
213
- session. output ,
213
+ session. stderr ,
214
214
style:: Print ( format!( "👤 {} " , filename) ) ,
215
215
style:: SetForegroundColor ( Color :: DarkGrey ) ,
216
216
style:: Print ( format!( "(~{} tkns)\n " , est_tokens) ) ,
217
217
style:: SetForegroundColor ( Color :: Reset ) ,
218
218
) ?;
219
219
if expand {
220
220
execute ! (
221
- session. output ,
221
+ session. stderr ,
222
222
style:: SetForegroundColor ( Color :: DarkGrey ) ,
223
223
style:: Print ( format!( "{}\n \n " , content) ) ,
224
224
style:: SetForegroundColor ( Color :: Reset )
@@ -227,7 +227,7 @@ impl ContextSubcommand {
227
227
}
228
228
229
229
if expand {
230
- execute ! ( session. output , style:: Print ( format!( "{}\n \n " , "▔" . repeat( 3 ) ) ) , ) ?;
230
+ execute ! ( session. stderr , style:: Print ( format!( "{}\n \n " , "▔" . repeat( 3 ) ) ) , ) ?;
231
231
}
232
232
233
233
let mut combined_files: Vec < ( String , String ) > = global_context_files
@@ -239,14 +239,14 @@ impl ContextSubcommand {
239
239
let dropped_files = drop_matched_context_files ( & mut combined_files, CONTEXT_FILES_MAX_SIZE ) . ok ( ) ;
240
240
241
241
execute ! (
242
- session. output ,
242
+ session. stderr ,
243
243
style:: Print ( format!( "\n Total: ~{} tokens\n \n " , total_tokens) )
244
244
) ?;
245
245
246
246
if let Some ( dropped_files) = dropped_files {
247
247
if !dropped_files. is_empty ( ) {
248
248
execute ! (
249
- session. output ,
249
+ session. stderr ,
250
250
style:: SetForegroundColor ( Color :: DarkYellow ) ,
251
251
style:: Print ( format!(
252
252
"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 {
261
261
for ( filename, content) in truncated_dropped_files {
262
262
let est_tokens = TokenCounter :: count_tokens ( content) ;
263
263
execute ! (
264
- session. output ,
264
+ session. stderr ,
265
265
style:: Print ( format!( "{} " , filename) ) ,
266
266
style:: SetForegroundColor ( Color :: DarkGrey ) ,
267
267
style:: Print ( format!( "(~{} tkns)\n " , est_tokens) ) ,
@@ -271,22 +271,22 @@ impl ContextSubcommand {
271
271
272
272
if total_files > 10 {
273
273
execute ! (
274
- session. output ,
274
+ session. stderr ,
275
275
style:: Print ( format!( "({} more files)\n " , total_files - 10 ) )
276
276
) ?;
277
277
}
278
278
}
279
279
}
280
280
281
- execute ! ( session. output , style:: Print ( "\n " ) ) ?;
281
+ execute ! ( session. stderr , style:: Print ( "\n " ) ) ?;
282
282
}
283
283
284
284
// Show last cached session.conversation summary if available, otherwise regenerate it
285
285
if expand {
286
286
if let Some ( summary) = session. conversation . latest_summary ( ) {
287
287
let border = "═" . repeat ( session. terminal_width ( ) . min ( 80 ) ) ;
288
288
execute ! (
289
- session. output ,
289
+ session. stderr ,
290
290
style:: Print ( "\n " ) ,
291
291
style:: SetForegroundColor ( Color :: Cyan ) ,
292
292
style:: Print ( & border) ,
@@ -308,15 +308,15 @@ impl ContextSubcommand {
308
308
Ok ( _) => {
309
309
let target = if global { "global" } else { "profile" } ;
310
310
execute ! (
311
- session. output ,
311
+ session. stderr ,
312
312
style:: SetForegroundColor ( Color :: Green ) ,
313
313
style:: Print ( format!( "\n Added {} path(s) to {} context.\n \n " , paths. len( ) , target) ) ,
314
314
style:: SetForegroundColor ( Color :: Reset )
315
315
) ?;
316
316
} ,
317
317
Err ( e) => {
318
318
execute ! (
319
- session. output ,
319
+ session. stderr ,
320
320
style:: SetForegroundColor ( Color :: Red ) ,
321
321
style:: Print ( format!( "\n Error: {}\n \n " , e) ) ,
322
322
style:: SetForegroundColor ( Color :: Reset )
@@ -328,7 +328,7 @@ impl ContextSubcommand {
328
328
Ok ( _) => {
329
329
let target = if global { "global" } else { "profile" } ;
330
330
execute ! (
331
- session. output ,
331
+ session. stderr ,
332
332
style:: SetForegroundColor ( Color :: Green ) ,
333
333
style:: Print ( format!(
334
334
"\n Removed {} path(s) from {} context.\n \n " ,
@@ -340,7 +340,7 @@ impl ContextSubcommand {
340
340
} ,
341
341
Err ( e) => {
342
342
execute ! (
343
- session. output ,
343
+ session. stderr ,
344
344
style:: SetForegroundColor ( Color :: Red ) ,
345
345
style:: Print ( format!( "\n Error: {}\n \n " , e) ) ,
346
346
style:: SetForegroundColor ( Color :: Reset )
@@ -355,15 +355,15 @@ impl ContextSubcommand {
355
355
format ! ( "profile '{}'" , context_manager. current_profile)
356
356
} ;
357
357
execute ! (
358
- session. output ,
358
+ session. stderr ,
359
359
style:: SetForegroundColor ( Color :: Green ) ,
360
360
style:: Print ( format!( "\n Cleared context for {}\n \n " , target) ) ,
361
361
style:: SetForegroundColor ( Color :: Reset )
362
362
) ?;
363
363
} ,
364
364
Err ( e) => {
365
365
execute ! (
366
- session. output ,
366
+ session. stderr ,
367
367
style:: SetForegroundColor ( Color :: Red ) ,
368
368
style:: Print ( format!( "\n Error: {}\n \n " , e) ) ,
369
369
style:: SetForegroundColor ( Color :: Reset )
0 commit comments