Skip to content

Commit 979db66

Browse files
committed
feat: QCHAT_PROCESS_ID and pre-push hook
1 parent 06b1bfb commit 979db66

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

.husky/pre-push

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Check if Amazon Q chat is active
2+
if [ -n "$QCHAT_PROCESS_ID" ]; then
3+
echo "ERROR: Git push blocked while Amazon Q chat is active (QCHAT_PROCESS_ID=$QCHAT_PROCESS_ID)"
4+
echo "Please exit Amazon Q chat with '/quit' before pushing changes."
5+
exit 1
6+
fi
7+
8+
# Continue with push if QCHAT_PROCESS_ID is not set
9+
exit 0

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ pub const MAX_NUMBER_OF_IMAGES_PER_REQUEST: usize = 10;
2626

2727
/// In bytes - 10 MB
2828
pub const MAX_IMAGE_SIZE: usize = 10 * 1024 * 1024;
29+
30+
/// Environment variable containing the pid of the chat session.
31+
pub const QCHAT_PROCESS_ID: &str = "QCHAT_PROCESS_ID";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pub mod cli;
22
mod command;
3-
mod consts;
3+
pub mod consts;
44
mod context;
55
mod conversation_state;
66
mod hooks;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
mod chat;
1+
pub mod chat;
22
mod debug;
33
mod diagnostics;
44
mod feed;

crates/chat-cli/src/main.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use clap::Parser;
1717
use crossterm::style::Stylize;
1818
use eyre::Result;
1919
use logging::get_log_level_max;
20+
use platform::Context;
2021
use tracing::metadata::LevelFilter;
2122

2223
#[global_allocator]
@@ -33,6 +34,18 @@ fn main() -> Result<ExitCode> {
3334
},
3435
};
3536

37+
// Set the QCHAT_PROCESS_ID env var if we're launching chat.
38+
#[cfg(unix)]
39+
match parsed.subcommand {
40+
Some(cli::CliRootCommands::Chat(_)) | None => {
41+
let ctx = Context::new();
42+
let current_pid = nix::unistd::getpid().as_raw().to_string();
43+
// SAFETY: This is only executed in a single-threaded context.
44+
unsafe { ctx.env().set_var(cli::chat::consts::QCHAT_PROCESS_ID, current_pid) };
45+
},
46+
_ => (),
47+
}
48+
3649
let verbose = parsed.verbose > 0;
3750
let runtime = tokio::runtime::Builder::new_multi_thread().enable_all().build()?;
3851
let result = runtime.block_on(parsed.execute());

0 commit comments

Comments
 (0)