Skip to content

Commit 61c953c

Browse files
authored
feat(context): improve hooks execution UI (#1280)
1 parent 4e14852 commit 61c953c

File tree

4 files changed

+239
-166
lines changed

4 files changed

+239
-166
lines changed

crates/q_cli/src/cli/chat/context.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -524,10 +524,10 @@ impl ContextManager {
524524
/// Run all the currently enabled hooks from both the global and profile contexts.
525525
/// Skipped hooks (disabled) will not appear in the output.
526526
/// # Arguments
527-
/// * `updates` - output stream to write hook run status to
527+
/// * `updates` - output stream to write hook run status to if Some, else do nothing if None
528528
/// # Returns
529529
/// A vector containing pairs of a [`Hook`] definition and its execution output
530-
pub async fn run_hooks(&mut self, updates: &mut impl Write) -> Vec<(Hook, String)> {
530+
pub async fn run_hooks(&mut self, updates: Option<&mut impl Write>) -> Vec<(Hook, String)> {
531531
let mut hooks: Vec<&Hook> = Vec::new();
532532

533533
// Set internal hook states
@@ -753,6 +753,8 @@ fn validate_profile_name(name: &str) -> Result<()> {
753753

754754
#[cfg(test)]
755755
mod tests {
756+
use std::io::Stdout;
757+
756758
use super::*;
757759
use crate::cli::chat::hooks::HookTrigger;
758760

@@ -945,11 +947,8 @@ mod tests {
945947
manager.add_hook("hook1".to_string(), hook1, false).await?;
946948
manager.add_hook("hook2".to_string(), hook2, false).await?;
947949

948-
// Create a buffer to capture the output
949-
let mut output = Vec::new();
950-
951950
// Run the hooks
952-
let results = manager.run_hooks(&mut output).await;
951+
let results = manager.run_hooks(None::<&mut Stdout>).await;
953952
assert_eq!(results.len(), 2); // Should include both hooks
954953

955954
Ok(())
@@ -964,14 +963,14 @@ mod tests {
964963
manager.add_hook("profile_hook".to_string(), hook1, false).await?;
965964
manager.add_hook("global_hook".to_string(), hook2, true).await?;
966965

967-
let results = manager.run_hooks(&mut Vec::new()).await;
966+
let results = manager.run_hooks(None::<&mut Stdout>).await;
968967
assert_eq!(results.len(), 2); // Should include both hooks
969968

970969
// Create and switch to a new profile
971970
manager.create_profile("test_profile").await?;
972971
manager.switch_profile("test_profile").await?;
973972

974-
let results = manager.run_hooks(&mut Vec::new()).await;
973+
let results = manager.run_hooks(None::<&mut Stdout>).await;
975974
assert_eq!(results.len(), 1); // Should include global hook
976975
assert_eq!(results[0].0.name, "global_hook");
977976

0 commit comments

Comments
 (0)