Skip to content

feat(context): improve hooks execution UI #1280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 21, 2025
Merged
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
15 changes: 7 additions & 8 deletions crates/q_cli/src/cli/chat/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,10 +524,10 @@ impl ContextManager {
/// Run all the currently enabled hooks from both the global and profile contexts.
/// Skipped hooks (disabled) will not appear in the output.
/// # Arguments
/// * `updates` - output stream to write hook run status to
/// * `updates` - output stream to write hook run status to if Some, else do nothing if None
/// # Returns
/// A vector containing pairs of a [`Hook`] definition and its execution output
pub async fn run_hooks(&mut self, updates: &mut impl Write) -> Vec<(Hook, String)> {
pub async fn run_hooks(&mut self, updates: Option<&mut impl Write>) -> Vec<(Hook, String)> {
let mut hooks: Vec<&Hook> = Vec::new();

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

#[cfg(test)]
mod tests {
use std::io::Stdout;

use super::*;
use crate::cli::chat::hooks::HookTrigger;

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

// Create a buffer to capture the output
let mut output = Vec::new();

// Run the hooks
let results = manager.run_hooks(&mut output).await;
let results = manager.run_hooks(None::<&mut Stdout>).await;
assert_eq!(results.len(), 2); // Should include both hooks

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

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

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

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

Expand Down
Loading
Loading