Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@


# Check if Amazon Q chat is active
if [ -n "$QCHAT_PROCESS_ID" ]; then
echo "ERROR: Git push blocked while Amazon Q chat is active (QCHAT_PROCESS_ID=$QCHAT_PROCESS_ID)"
echo "Please exit Amazon Q chat with '/quit' before pushing changes."
exit 1
fi

# Continue with push if QCHAT_PROCESS_ID is not set
exit 0
64 changes: 32 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ authors = [
edition = "2021"
homepage = "https://aws.amazon.com/q/"
publish = false
version = "1.8.0"
version = "1.8.1"
license = "MIT OR Apache-2.0"

[workspace.dependencies]
Expand Down
2 changes: 2 additions & 0 deletions crates/q_chat/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ pub const MAX_USER_MESSAGE_SIZE: usize = 600_000;
pub const CONTEXT_WINDOW_SIZE: usize = 200_000;

pub const MAX_CHARS: usize = TokenCounter::token_to_chars(CONTEXT_WINDOW_SIZE); // Character-based warning threshold

pub const QCHAT_PROCESS_ID: &str = "QCHAT_PROCESS_ID";
42 changes: 40 additions & 2 deletions crates/q_chat/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ use command::{
Command,
ToolsSubcommand,
};
use consts::CONTEXT_WINDOW_SIZE;
use consts::{
CONTEXT_WINDOW_SIZE,
QCHAT_PROCESS_ID,
};
use context::ContextManager;
use conversation_state::{
ConversationState,
Expand Down Expand Up @@ -333,6 +336,11 @@ pub async fn chat(
}
}

let process_info = ctx.process_info();
let current_pid = process_info.current_pid().to_string();

unsafe { ctx.env().set_var(QCHAT_PROCESS_ID, current_pid) };

let tool_config = load_tools()?;
let mut tool_permissions = ToolPermissions::new(tool_config.len());
if accept_all || trust_all_tools {
Expand Down Expand Up @@ -1015,7 +1023,37 @@ impl ChatContext {
execute!(self.output, cursor::Hide, style::Print("\n"))?;
self.spinner = Some(Spinner::new(Spinners::Dots, "Creating summary...".to_string()));
}
let response = self.client.send_message(summary_state).await?;
let response = self.client.send_message(summary_state).await;

// TODO(brandonskiser): This is a temporary hotfix for failing compaction. We should instead
// retry except with less context included.
let response = match response {
Ok(res) => res,
Err(e) => match e {
fig_api_client::Error::ContextWindowOverflow => {
self.conversation_state.clear(true);
if self.interactive {
self.spinner.take();
execute!(
self.output,
terminal::Clear(terminal::ClearType::CurrentLine),
cursor::MoveToColumn(0),
style::SetForegroundColor(Color::Yellow),
style::Print(
"The context window usage has overflowed. Clearing the conversation history.\n\n"
),
style::SetAttribute(Attribute::Reset)
)?;
}
return Ok(ChatState::PromptUser {
tool_uses,
pending_tool_index,
skip_printing_tools: true,
});
},
e => return Err(e.into()),
},
};

let summary = {
let mut parser = ResponseParser::new(response);
Expand Down
Loading
Loading