diff --git a/.husky/pre-push b/.husky/pre-push new file mode 100644 index 0000000000..d2b1d22762 --- /dev/null +++ b/.husky/pre-push @@ -0,0 +1,9 @@ +# 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/crates/chat-cli/src/cli/chat/consts.rs b/crates/chat-cli/src/cli/chat/consts.rs index 521f5b583e..97c1ee4c17 100644 --- a/crates/chat-cli/src/cli/chat/consts.rs +++ b/crates/chat-cli/src/cli/chat/consts.rs @@ -26,3 +26,6 @@ pub const MAX_NUMBER_OF_IMAGES_PER_REQUEST: usize = 10; /// In bytes - 10 MB pub const MAX_IMAGE_SIZE: usize = 10 * 1024 * 1024; + +/// Environment variable containing the pid of the chat session. +pub const QCHAT_PROCESS_ID: &str = "QCHAT_PROCESS_ID"; diff --git a/crates/chat-cli/src/cli/chat/mod.rs b/crates/chat-cli/src/cli/chat/mod.rs index 68a62e088c..1a317c4ed1 100644 --- a/crates/chat-cli/src/cli/chat/mod.rs +++ b/crates/chat-cli/src/cli/chat/mod.rs @@ -1,6 +1,6 @@ pub mod cli; mod command; -mod consts; +pub mod consts; mod context; mod conversation_state; mod hooks; diff --git a/crates/chat-cli/src/cli/mod.rs b/crates/chat-cli/src/cli/mod.rs index 57fc2b458f..77de91274f 100644 --- a/crates/chat-cli/src/cli/mod.rs +++ b/crates/chat-cli/src/cli/mod.rs @@ -1,4 +1,4 @@ -mod chat; +pub mod chat; mod debug; mod diagnostics; mod feed; diff --git a/crates/chat-cli/src/main.rs b/crates/chat-cli/src/main.rs index a00fc087f2..17815d8372 100644 --- a/crates/chat-cli/src/main.rs +++ b/crates/chat-cli/src/main.rs @@ -17,6 +17,7 @@ use clap::Parser; use crossterm::style::Stylize; use eyre::Result; use logging::get_log_level_max; +use platform::Context; use tracing::metadata::LevelFilter; #[global_allocator] @@ -33,6 +34,18 @@ fn main() -> Result { }, }; + // Set the QCHAT_PROCESS_ID env var if we're launching chat. + #[cfg(unix)] + match parsed.subcommand { + Some(cli::CliRootCommands::Chat(_)) | None => { + let ctx = Context::new(); + let current_pid = nix::unistd::getpid().as_raw().to_string(); + // SAFETY: This is only executed in a single-threaded context. + unsafe { ctx.env().set_var(cli::chat::consts::QCHAT_PROCESS_ID, current_pid) }; + }, + _ => (), + } + let verbose = parsed.verbose > 0; let runtime = tokio::runtime::Builder::new_multi_thread().enable_all().build()?; let result = runtime.block_on(parsed.execute());