Skip to content

Commit d13b4c1

Browse files
committed
chore: run cargo +nightly fmt
1 parent 4ed60ee commit d13b4c1

File tree

3 files changed

+64
-32
lines changed

3 files changed

+64
-32
lines changed

crates/q_cli/src/cli/chat/chat_state.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::collections::VecDeque;
2+
23
use fig_api_client::model::ChatMessage;
34

45
/// Character count warning levels for conversation size
@@ -33,12 +34,12 @@ impl SummarizationState {
3334
show_summary: false,
3435
}
3536
}
36-
37+
3738
pub fn with_prompt(prompt: Option<String>) -> Self {
3839
Self {
3940
original_history: None,
4041
custom_prompt: prompt,
4142
show_summary: false,
4243
}
4344
}
44-
}
45+
}

crates/q_cli/src/cli/chat/command.rs

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,35 @@ use eyre::Result;
99

1010
#[derive(Debug, PartialEq, Eq)]
1111
pub enum Command {
12-
Ask { prompt: String },
13-
Execute { command: String },
12+
Ask {
13+
prompt: String,
14+
},
15+
Execute {
16+
command: String,
17+
},
1418
Clear,
1519
Help,
16-
Issue { prompt: Option<String> },
20+
Issue {
21+
prompt: Option<String>,
22+
},
1723
Quit,
18-
Profile { subcommand: ProfileSubcommand },
19-
Context { subcommand: ContextSubcommand },
20-
PromptEditor { initial_text: Option<String> },
21-
Compact { prompt: Option<String>, show_summary: bool, help: bool },
22-
Tools { subcommand: Option<ToolsSubcommand> },
24+
Profile {
25+
subcommand: ProfileSubcommand,
26+
},
27+
Context {
28+
subcommand: ContextSubcommand,
29+
},
30+
PromptEditor {
31+
initial_text: Option<String>,
32+
},
33+
Compact {
34+
prompt: Option<String>,
35+
show_summary: bool,
36+
help: bool,
37+
},
38+
Tools {
39+
subcommand: Option<ToolsSubcommand>,
40+
},
2341
}
2442

2543
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -229,13 +247,13 @@ impl Command {
229247
let mut prompt = None;
230248
let mut show_summary = false;
231249
let mut help = false;
232-
250+
233251
// Check if "help" is the first subcommand
234252
if parts.len() > 1 && parts[1].to_lowercase() == "help" {
235253
help = true;
236254
} else {
237255
let mut remaining_parts = Vec::new();
238-
256+
239257
// Parse the parts to handle both prompt and flags
240258
for part in &parts[1..] {
241259
if *part == "--summary" {
@@ -244,7 +262,7 @@ impl Command {
244262
remaining_parts.push(*part);
245263
}
246264
}
247-
265+
248266
// Check if the last word is "--summary" (which would have been captured as part of the prompt)
249267
if !remaining_parts.is_empty() {
250268
let last_idx = remaining_parts.len() - 1;
@@ -253,14 +271,14 @@ impl Command {
253271
show_summary = true;
254272
}
255273
}
256-
274+
257275
// If we have remaining parts after parsing flags, join them as the prompt
258276
if !remaining_parts.is_empty() {
259277
prompt = Some(remaining_parts.join(" "));
260278
}
261279
}
262-
263-
Self::Compact {
280+
281+
Self::Compact {
264282
prompt,
265283
show_summary,
266284
help,
@@ -573,9 +591,18 @@ mod tests {
573591
let tests = &[
574592
("/compact", compact!(None, false)),
575593
("/compact --summary", compact!(None, true)),
576-
("/compact custom prompt", compact!(Some("custom prompt".to_string()), false)),
577-
("/compact --summary custom prompt", compact!(Some("custom prompt".to_string()), true)),
578-
("/compact custom prompt --summary", compact!(Some("custom prompt".to_string()), true)),
594+
(
595+
"/compact custom prompt",
596+
compact!(Some("custom prompt".to_string()), false),
597+
),
598+
(
599+
"/compact --summary custom prompt",
600+
compact!(Some("custom prompt".to_string()), true),
601+
),
602+
(
603+
"/compact custom prompt --summary",
604+
compact!(Some("custom prompt".to_string()), true),
605+
),
579606
("/profile list", profile!(ProfileSubcommand::List)),
580607
(
581608
"/profile create new_profile",

crates/q_cli/src/cli/chat/conversation_state.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ use tracing::{
3232
warn,
3333
};
3434

35-
use super::chat_state::{MAX_CHARS, TokenWarningLevel};
35+
use super::chat_state::{
36+
MAX_CHARS,
37+
TokenWarningLevel,
38+
};
3639
use super::context::ContextManager;
3740
use super::tools::{
3841
QueuedTool,
@@ -124,12 +127,12 @@ impl ConversationState {
124127
pub fn history_as_vec(&self) -> Vec<ChatMessage> {
125128
self.history.iter().cloned().collect()
126129
}
127-
130+
128131
/// Returns the length of the conversation history
129132
pub fn history_len(&self) -> usize {
130133
self.history.len()
131134
}
132-
135+
133136
/// Clears the conversation history and optionally the summary.
134137
pub fn clear(&mut self, preserve_summary: bool) {
135138
self.next_message = None;
@@ -415,17 +418,18 @@ impl ConversationState {
415418
pub async fn context_messages(&self) -> Option<(UserInputMessage, AssistantResponseMessage)> {
416419
let mut context_content = String::new();
417420
let mut has_content = false;
418-
421+
419422
// Add summary if available - emphasize its importance more strongly
420423
if let Some(summary) = &self.latest_summary {
421-
context_content.push_str("--- CRITICAL: PREVIOUS CONVERSATION SUMMARY - THIS IS YOUR PRIMARY CONTEXT ---\n");
424+
context_content
425+
.push_str("--- CRITICAL: PREVIOUS CONVERSATION SUMMARY - THIS IS YOUR PRIMARY CONTEXT ---\n");
422426
context_content.push_str("This summary contains ALL relevant information from our previous conversation including tool uses, results, code analysis, and file operations. YOU MUST reference this information when answering questions and explicitly acknowledge specific details from the summary when they're relevant to the current question.\n\n");
423427
context_content.push_str("SUMMARY CONTENT:\n");
424428
context_content.push_str(summary);
425429
context_content.push_str("\n--- END SUMMARY - YOU MUST USE THIS INFORMATION IN YOUR RESPONSES ---\n\n");
426430
has_content = true;
427431
}
428-
432+
429433
// Add context files if available
430434
if let Some(context_manager) = &self.context_manager {
431435
match context_manager.get_context_files(true).await {
@@ -444,7 +448,7 @@ impl ConversationState {
444448
},
445449
}
446450
}
447-
451+
448452
if has_content {
449453
let user_msg = UserInputMessage {
450454
content: format!(
@@ -474,7 +478,7 @@ impl ConversationState {
474478
pub fn calculate_char_count(&self) -> usize {
475479
// Calculate total character count in all messages
476480
let mut total_chars = 0;
477-
481+
478482
// Count characters in history
479483
for message in &self.history {
480484
match message {
@@ -494,7 +498,7 @@ impl ConversationState {
494498
// Approximate JSON size
495499
total_chars += 100;
496500
}
497-
}
501+
},
498502
}
499503
}
500504
}
@@ -508,22 +512,22 @@ impl ConversationState {
508512
// Approximation for tool uses
509513
total_chars += tool_uses.len() * 200;
510514
}
511-
}
515+
},
512516
}
513517
}
514-
518+
515519
// Add summary if it exists (it's also in the context sent to the model)
516520
if let Some(summary) = &self.latest_summary {
517521
total_chars += summary.len();
518522
}
519-
523+
520524
total_chars
521525
}
522526

523527
/// Get the current token warning level
524528
pub fn get_token_warning_level(&self) -> TokenWarningLevel {
525529
let total_chars = self.calculate_char_count();
526-
530+
527531
if total_chars >= MAX_CHARS {
528532
TokenWarningLevel::Critical
529533
} else {

0 commit comments

Comments
 (0)