Skip to content

Commit 0c42019

Browse files
fix: issues with /compact, bumping the version to v1.12.4 (#2272)
1 parent 68577a5 commit 0c42019

File tree

9 files changed

+486
-329
lines changed

9 files changed

+486
-329
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ authors = ["Amazon Q CLI Team (q-cli@amazon.com)", "Chay Nabors (nabochay@amazon
77
edition = "2024"
88
homepage = "https://aws.amazon.com/q/"
99
publish = false
10-
version = "1.12.3"
10+
version = "1.12.4"
1111
license = "MIT OR Apache-2.0"
1212

1313
[workspace.dependencies]

crates/chat-cli/src/cli/chat/cli/compact.rs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use clap::Args;
22

3+
use crate::cli::chat::consts::MAX_USER_MESSAGE_SIZE;
4+
use crate::cli::chat::message::UserMessageContent;
35
use crate::cli::chat::{
46
ChatError,
57
ChatSession,
@@ -24,17 +26,60 @@ How it works
2426
• Creates an AI-generated summary of your conversation
2527
• Retains key information, code, and tool executions in the summary
2628
• Clears the conversation history to free up space
27-
• The assistant will reference the summary context in future responses"
29+
• The assistant will reference the summary context in future responses
30+
31+
Compaction will be automatically performed whenever the context window overflows.
32+
To disable this behavior, run: `q settings chat.disableAutoCompaction true`"
2833
)]
2934
pub struct CompactArgs {
3035
/// The prompt to use when generating the summary
3136
prompt: Option<String>,
3237
#[arg(long)]
3338
show_summary: bool,
39+
/// The number of user and assistant message pairs to exclude from the summarization.
40+
#[arg(long)]
41+
messages_to_exclude: Option<usize>,
42+
/// Whether or not large messages should be truncated.
43+
#[arg(long)]
44+
truncate_large_messages: Option<bool>,
45+
/// Maximum allowed size of messages in the conversation history. Requires
46+
/// truncate_large_messages to be set.
47+
#[arg(long, requires = "truncate_large_messages")]
48+
max_message_length: Option<usize>,
3449
}
3550

3651
impl CompactArgs {
3752
pub async fn execute(self, os: &Os, session: &mut ChatSession) -> Result<ChatState, ChatError> {
38-
session.compact_history(os, self.prompt, self.show_summary, true).await
53+
let default = CompactStrategy::default();
54+
session
55+
.compact_history(os, self.prompt, self.show_summary, CompactStrategy {
56+
messages_to_exclude: self.messages_to_exclude.unwrap_or(default.messages_to_exclude),
57+
truncate_large_messages: self.truncate_large_messages.unwrap_or(default.truncate_large_messages),
58+
max_message_length: self.max_message_length.map_or(default.max_message_length, |v| {
59+
v.clamp(UserMessageContent::TRUNCATED_SUFFIX.len(), MAX_USER_MESSAGE_SIZE)
60+
}),
61+
})
62+
.await
63+
}
64+
}
65+
66+
/// Parameters for performing the history compaction request.
67+
#[derive(Debug, Copy, Clone)]
68+
pub struct CompactStrategy {
69+
/// Number of user/assistant pairs to exclude from the history as part of compaction.
70+
pub messages_to_exclude: usize,
71+
/// Whether or not to truncate large messages in the history.
72+
pub truncate_large_messages: bool,
73+
/// Maximum allowed size of messages in the conversation history.
74+
pub max_message_length: usize,
75+
}
76+
77+
impl Default for CompactStrategy {
78+
fn default() -> Self {
79+
Self {
80+
messages_to_exclude: Default::default(),
81+
truncate_large_messages: Default::default(),
82+
max_message_length: MAX_USER_MESSAGE_SIZE,
83+
}
3984
}
4085
}

0 commit comments

Comments
 (0)