diff --git a/.husky/pre-push b/.husky/pre-push new file mode 100755 index 0000000000..943239a9d3 --- /dev/null +++ b/.husky/pre-push @@ -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 diff --git a/Cargo.lock b/Cargo.lock index 4a3206a8f2..43a1a3efd4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -66,7 +66,7 @@ dependencies = [ [[package]] name = "alacritty_terminal" -version = "1.8.0" +version = "1.8.1" dependencies = [ "bitflags 2.9.0", "camino", @@ -283,7 +283,7 @@ checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" [[package]] name = "appkit-nsworkspace-bindings" -version = "1.8.0" +version = "1.8.1" dependencies = [ "bindgen 0.71.1", "objc", @@ -2090,7 +2090,7 @@ checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" [[package]] name = "dbus" -version = "1.8.0" +version = "1.8.1" dependencies = [ "async_zip", "fig_os_shim", @@ -2603,7 +2603,7 @@ dependencies = [ [[package]] name = "fig-api-mock" -version = "1.8.0" +version = "1.8.1" dependencies = [ "async-trait", "clap", @@ -2616,7 +2616,7 @@ dependencies = [ [[package]] name = "fig_api_client" -version = "1.8.0" +version = "1.8.1" dependencies = [ "amzn-codewhisperer-client", "amzn-codewhisperer-streaming-client", @@ -2652,7 +2652,7 @@ dependencies = [ [[package]] name = "fig_auth" -version = "1.8.0" +version = "1.8.1" dependencies = [ "async-trait", "aws-credential-types", @@ -2686,7 +2686,7 @@ dependencies = [ [[package]] name = "fig_aws_common" -version = "1.8.0" +version = "1.8.1" dependencies = [ "aws-runtime", "aws-smithy-runtime", @@ -2700,7 +2700,7 @@ dependencies = [ [[package]] name = "fig_desktop" -version = "1.8.0" +version = "1.8.1" dependencies = [ "accessibility-sys", "anyhow", @@ -2792,7 +2792,7 @@ dependencies = [ [[package]] name = "fig_desktop_api" -version = "1.8.0" +version = "1.8.1" dependencies = [ "anstream", "async-trait", @@ -2828,7 +2828,7 @@ dependencies = [ [[package]] name = "fig_diagnostic" -version = "1.8.0" +version = "1.8.1" dependencies = [ "cfg-if", "clap", @@ -2848,7 +2848,7 @@ dependencies = [ [[package]] name = "fig_input_method" -version = "1.8.0" +version = "1.8.1" dependencies = [ "apple-bundle", "fig_ipc", @@ -2869,7 +2869,7 @@ dependencies = [ [[package]] name = "fig_install" -version = "1.8.0" +version = "1.8.1" dependencies = [ "bitflags 2.9.0", "bytes", @@ -2908,7 +2908,7 @@ dependencies = [ [[package]] name = "fig_integrations" -version = "1.8.0" +version = "1.8.1" dependencies = [ "accessibility-sys", "async-trait", @@ -2941,7 +2941,7 @@ dependencies = [ [[package]] name = "fig_ipc" -version = "1.8.0" +version = "1.8.1" dependencies = [ "async-trait", "base64 0.22.1", @@ -2964,7 +2964,7 @@ dependencies = [ [[package]] name = "fig_log" -version = "1.8.0" +version = "1.8.1" dependencies = [ "fig_util", "parking_lot", @@ -2977,7 +2977,7 @@ dependencies = [ [[package]] name = "fig_os_shim" -version = "1.8.0" +version = "1.8.1" dependencies = [ "cfg-if", "dirs", @@ -2990,7 +2990,7 @@ dependencies = [ [[package]] name = "fig_proto" -version = "1.8.0" +version = "1.8.1" dependencies = [ "arbitrary", "bytes", @@ -3013,7 +3013,7 @@ dependencies = [ [[package]] name = "fig_remote_ipc" -version = "1.8.0" +version = "1.8.1" dependencies = [ "anyhow", "async-trait", @@ -3031,7 +3031,7 @@ dependencies = [ [[package]] name = "fig_request" -version = "1.8.0" +version = "1.8.1" dependencies = [ "bytes", "cfg-if", @@ -3056,7 +3056,7 @@ dependencies = [ [[package]] name = "fig_settings" -version = "1.8.0" +version = "1.8.1" dependencies = [ "fd-lock", "fig_test", @@ -3077,7 +3077,7 @@ dependencies = [ [[package]] name = "fig_telemetry" -version = "1.8.0" +version = "1.8.1" dependencies = [ "amzn-codewhisperer-client", "amzn-toolkit-telemetry", @@ -3111,7 +3111,7 @@ dependencies = [ [[package]] name = "fig_telemetry_core" -version = "1.8.0" +version = "1.8.1" dependencies = [ "amzn-codewhisperer-client", "amzn-toolkit-telemetry", @@ -3125,7 +3125,7 @@ dependencies = [ [[package]] name = "fig_test" -version = "1.8.0" +version = "1.8.1" dependencies = [ "fig_test_macro", "tokio", @@ -3133,7 +3133,7 @@ dependencies = [ [[package]] name = "fig_test_macro" -version = "1.8.0" +version = "1.8.1" dependencies = [ "quote", "syn 2.0.100", @@ -3141,7 +3141,7 @@ dependencies = [ [[package]] name = "fig_test_utils" -version = "1.8.0" +version = "1.8.1" dependencies = [ "bytes", "fig_os_shim", @@ -3159,7 +3159,7 @@ dependencies = [ [[package]] name = "fig_util" -version = "1.8.0" +version = "1.8.1" dependencies = [ "appkit-nsworkspace-bindings", "bstr", @@ -3199,7 +3199,7 @@ dependencies = [ [[package]] name = "figterm" -version = "1.8.0" +version = "1.8.1" dependencies = [ "alacritty_terminal", "anyhow", @@ -3262,7 +3262,7 @@ dependencies = [ [[package]] name = "figterm2" -version = "1.8.0" +version = "1.8.1" dependencies = [ "anyhow", "async-trait", @@ -4972,7 +4972,7 @@ dependencies = [ [[package]] name = "macos-utils" -version = "1.8.0" +version = "1.8.1" dependencies = [ "accessibility", "accessibility-sys", @@ -6798,7 +6798,7 @@ dependencies = [ [[package]] name = "q_chat" -version = "1.8.0" +version = "1.8.1" dependencies = [ "anstream", "aws-smithy-types", @@ -6843,7 +6843,7 @@ dependencies = [ [[package]] name = "q_cli" -version = "1.8.0" +version = "1.8.1" dependencies = [ "amzn-codewhisperer-client", "amzn-codewhisperer-streaming-client", @@ -8013,7 +8013,7 @@ dependencies = [ [[package]] name = "shell-color" -version = "1.8.0" +version = "1.8.1" dependencies = [ "bitflags 2.9.0", "fig_test", diff --git a/Cargo.toml b/Cargo.toml index a6907420ae..9a06331a33 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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] diff --git a/crates/q_chat/src/consts.rs b/crates/q_chat/src/consts.rs index 6850f7efab..4ea56aa604 100644 --- a/crates/q_chat/src/consts.rs +++ b/crates/q_chat/src/consts.rs @@ -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"; diff --git a/crates/q_chat/src/lib.rs b/crates/q_chat/src/lib.rs index 5d2a1929ab..6e6b821149 100644 --- a/crates/q_chat/src/lib.rs +++ b/crates/q_chat/src/lib.rs @@ -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, @@ -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 { @@ -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); diff --git a/docs/samples/git-pre-push-hook/git-hook-installation.md b/docs/samples/git-pre-push-hook/git-hook-installation.md new file mode 100644 index 0000000000..497e7a2794 --- /dev/null +++ b/docs/samples/git-pre-push-hook/git-hook-installation.md @@ -0,0 +1,96 @@ +# Amazon Q Git Hook Installation + +This document provides instructions for installing a sample git hook that prevents accidental `git push` operations while using Amazon Q chat. + +Note - Git hooks do not chain. If you need more than one hook installed, you will require other tools to link more than one into a single hook. Follow the install instructions for those other tools instead. + +## What This Hook Does + +The `pre-push` hook checks if the `QCHAT_PROCESS_ID` environment variable is set (which indicates an active Amazon Q chat session). If the variable is set, the hook blocks the push operation and displays an error message. + +## Installation Instructions + +1. Copy the hook file to your git hooks directory: + +```bash +# Navigate to your git repository +cd /path/to/your/repo + +# Create hooks directory if it doesn't exist +mkdir -p .git/hooks + +# Copy the hook file +cp /path/to/pre-push-hook .git/hooks/pre-push + +# Make the hook executable +chmod +x .git/hooks/pre-push +``` + +2. Verify the installation: + +```bash +ls -la .git/hooks/pre-push +``` + +## Testing the Hook + +To test if the hook is working correctly: + +1. Start an Amazon Q chat session: +```bash +q chat +``` + +2. From within q chat, as it to push to a git repository: +```bash +> git push this repo +``` + +You should see an error message indicating that the push is blocked while Amazon Q chat is active. + +## Global Installation + +To install this hook for all repositories: + +1. Configure git to use a global hooks directory: + +```bash +# Create a global hooks directory +mkdir -p ~/.git-hooks + +# Configure git to use this directory +git config --global core.hooksPath ~/.git-hooks +``` + +2. Install the pre-push hook in the global directory: + +```bash +cp /path/to/pre-push-hook ~/.git-hooks/pre-push +chmod +x ~/.git-hooks/pre-push +``` + +## Uninstalling the Hook + +To remove the hook: + +```bash +# Delete the hook file +rm .git/hooks/pre-push +``` + +To remove a globally installed hook: + +```bash +# Delete the hook file +rm ~/.git-hooks/pre-push +``` + + +## Troubleshooting + +If the hook isn't working: + +1. Ensure the hook file is executable (`chmod +x .git/hooks/pre-push`) +2. Verify the hook path is correct (check `git config core.hooksPath`) +3. Make sure the hook doesn't have Windows line endings if you're on Unix/Linux +4. Check if you have other git configurations that might override hooks diff --git a/docs/samples/git-pre-push-hook/pre-push-hook b/docs/samples/git-pre-push-hook/pre-push-hook new file mode 100644 index 0000000000..5a5fc26ac3 --- /dev/null +++ b/docs/samples/git-pre-push-hook/pre-push-hook @@ -0,0 +1,14 @@ +#!/bin/bash + +# Git hook is a sample, designed to show how you can prevent pushing +# when QCHAT_PROCESS_ID is set +# This prevents accidental pushes while using Amazon Q chat + +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 diff --git a/feed.json b/feed.json index eac8aa204b..c42b964bcc 100644 --- a/feed.json +++ b/feed.json @@ -10,6 +10,18 @@ "hidden": true, "changes": [] }, + { + "type": "release", + "date": "2025-04-25", + "version": "1.8.1", + "title": "Version 1.8.1", + "changes": [ + { + "type": "fixed", + "description": "An issue with `/compact` failing in `q chat`" + } + ] + }, { "type": "release", "date": "2025-04-22",