Skip to content

Commit b258c01

Browse files
authored
refactor: slash command rewrite (#223)
* checkpoint * checkpoint 2 * checkpoint 3 * checkpoint 4 * checkpoint 5 * checkpoint 6
1 parent a1adeaf commit b258c01

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+4638
-5843
lines changed

crates/chat-cli/src/api_client/clients/streaming_client.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,13 @@ impl StreamingClient {
9696
Ok(Self { inner, profile })
9797
}
9898

99-
pub async fn send_message(
100-
&self,
101-
conversation_state: ConversationState,
102-
) -> Result<SendMessageOutput, ApiClientError> {
103-
debug!("Sending conversation: {:#?}", conversation_state);
99+
pub async fn send_message(&self, conversation: ConversationState) -> Result<SendMessageOutput, ApiClientError> {
100+
debug!("Sending conversation: {:#?}", conversation);
104101
let ConversationState {
105102
conversation_id,
106103
user_input_message,
107104
history,
108-
} = conversation_state;
105+
} = conversation;
109106

110107
match &self.inner {
111108
inner::Inner::Codewhisperer(client) => {
@@ -124,7 +121,8 @@ impl StreamingClient {
124121
.transpose()?,
125122
)
126123
.build()
127-
.expect("building conversation_state should not fail");
124+
.expect("building conversation should not fail");
125+
128126
let response = client
129127
.generate_assistant_response()
130128
.conversation_state(conversation_state)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
use clap::Args;
2+
use crossterm::style::{
3+
self,
4+
Color,
5+
Stylize,
6+
};
7+
use crossterm::{
8+
cursor,
9+
execute,
10+
};
11+
12+
use crate::cli::chat::{
13+
ChatError,
14+
ChatSession,
15+
ChatState,
16+
};
17+
18+
#[deny(missing_docs)]
19+
#[derive(Debug, PartialEq, Args)]
20+
pub struct ClearArgs;
21+
22+
impl ClearArgs {
23+
pub async fn execute(self, session: &mut ChatSession) -> Result<ChatState, ChatError> {
24+
execute!(
25+
session.output,
26+
style::SetForegroundColor(Color::DarkGrey),
27+
style::Print(
28+
"\nAre you sure? This will erase the conversation history and context from hooks for the current session. "
29+
),
30+
style::Print("["),
31+
style::SetForegroundColor(Color::Green),
32+
style::Print("y"),
33+
style::SetForegroundColor(Color::DarkGrey),
34+
style::Print("/"),
35+
style::SetForegroundColor(Color::Green),
36+
style::Print("n"),
37+
style::SetForegroundColor(Color::DarkGrey),
38+
style::Print("]:\n\n"),
39+
style::SetForegroundColor(Color::Reset),
40+
cursor::Show,
41+
)?;
42+
43+
// Setting `exit_on_single_ctrl_c` for better ux: exit the confirmation dialog rather than the CLI
44+
let user_input = match session.read_user_input("> ".yellow().to_string().as_str(), true) {
45+
Some(input) => input,
46+
None => "".to_string(),
47+
};
48+
49+
if ["y", "Y"].contains(&user_input.as_str()) {
50+
session.conversation.clear(true);
51+
if let Some(cm) = session.conversation.context_manager.as_mut() {
52+
cm.hook_executor.global_cache.clear();
53+
cm.hook_executor.profile_cache.clear();
54+
}
55+
execute!(
56+
session.output,
57+
style::SetForegroundColor(Color::Green),
58+
style::Print("\nConversation history cleared.\n\n"),
59+
style::SetForegroundColor(Color::Reset)
60+
)?;
61+
}
62+
63+
Ok(ChatState::default())
64+
}
65+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use clap::Args;
2+
3+
use crate::cli::chat::{
4+
ChatError,
5+
ChatSession,
6+
ChatState,
7+
};
8+
use crate::database::Database;
9+
use crate::platform::Context;
10+
use crate::telemetry::TelemetryThread;
11+
12+
#[deny(missing_docs)]
13+
#[derive(Debug, PartialEq, Args)]
14+
#[command(
15+
before_long_help = "/compact summarizes the conversation history to free up context space
16+
while preserving essential information. This is useful for long-running conversations
17+
that may eventually reach memory constraints.
18+
19+
When to use
20+
• When you see the memory constraint warning message
21+
• When a conversation has been running for a long time
22+
• Before starting a new topic within the same session
23+
• After completing complex tool operations
24+
25+
How it works
26+
• Creates an AI-generated summary of your conversation
27+
• Retains key information, code, and tool executions in the summary
28+
• Clears the conversation history to free up space
29+
• The assistant will reference the summary context in future responses"
30+
)]
31+
pub struct CompactArgs {
32+
/// The prompt to use when generating the summary
33+
prompt: Option<String>,
34+
show_summary: bool,
35+
}
36+
37+
impl CompactArgs {
38+
pub async fn execute(
39+
self,
40+
ctx: &Context,
41+
database: &mut Database,
42+
telemetry: &TelemetryThread,
43+
session: &mut ChatSession,
44+
) -> Result<ChatState, ChatError> {
45+
session
46+
.compact_history(ctx, database, telemetry, self.prompt, self.show_summary)
47+
.await
48+
}
49+
}

0 commit comments

Comments
 (0)