Add real-time research completion notifications
When background research completes, g3 now immediately prints a status message instead of waiting for the next user interaction: - Added ResearchCompletionNotification and broadcast channel to PendingResearchManager for push-based notifications - Added spawn_research_notification_handler() in interactive mode that listens for completions in a background task - When idle (at prompt): clears line, prints status, reprints prompt - When busy (processing): prints status inline (interleaving is fine) - Added G3Status::research_complete() for consistent formatting - Added enable_research_notifications() method to Agent Output format: "g3: 1 research report ... [done]"
This commit is contained in:
@@ -38,6 +38,9 @@ pub use task_result::TaskResult;
|
||||
// Re-export context window types
|
||||
pub use context_window::{ContextWindow, ThinResult, ThinScope};
|
||||
|
||||
// Re-export pending research types for notification handling
|
||||
pub use pending_research::{PendingResearchManager, ResearchCompletionNotification, ResearchStatus};
|
||||
|
||||
// Export agent prompt generation for CLI use
|
||||
pub use prompts::get_agent_system_prompt;
|
||||
|
||||
@@ -1484,6 +1487,26 @@ impl<W: UiWriter> Agent<W> {
|
||||
&self.pending_research_manager
|
||||
}
|
||||
|
||||
/// Subscribe to research completion notifications.
|
||||
///
|
||||
/// Returns a receiver that will receive notifications when research tasks complete.
|
||||
/// Returns None if the agent was not configured with notifications enabled.
|
||||
/// Use this in interactive mode to get real-time updates when research finishes.
|
||||
pub fn subscribe_research_notifications(&self) -> Option<tokio::sync::broadcast::Receiver<pending_research::ResearchCompletionNotification>> {
|
||||
self.pending_research_manager.subscribe()
|
||||
}
|
||||
|
||||
/// Enable research completion notifications and return a receiver.
|
||||
///
|
||||
/// This replaces the internal research manager with one that sends notifications.
|
||||
/// Call this once during setup (e.g., in interactive mode) before any research tasks.
|
||||
/// Returns a receiver that will receive notifications when research tasks complete.
|
||||
pub fn enable_research_notifications(&mut self) -> tokio::sync::broadcast::Receiver<pending_research::ResearchCompletionNotification> {
|
||||
let (manager, rx) = pending_research::PendingResearchManager::with_notifications();
|
||||
self.pending_research_manager = manager;
|
||||
rx
|
||||
}
|
||||
|
||||
pub fn set_requirements_sha(&mut self, sha: String) {
|
||||
self.requirements_sha = Some(sha);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user