diff --git a/src-tauri/src/commands/agent.rs b/src-tauri/src/commands/agent.rs index b7e1ddf..ee495f8 100644 --- a/src-tauri/src/commands/agent.rs +++ b/src-tauri/src/commands/agent.rs @@ -9,6 +9,10 @@ pub fn agent_query( state: State<'_, AppState>, options: AgentQueryOptions, ) -> Result<(), String> { + // Run pre-dispatch hooks (budget enforcement, branch policy, etc.) + for hook in &state.pre_dispatch_hooks { + hook(&options)?; + } state.sidecar_manager.query(&options) } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 55295de..f7af146 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -29,6 +29,10 @@ use std::path::{Path, PathBuf}; use std::sync::Arc; use tauri::Manager; +/// Pre-dispatch hook for agent task middleware (budget enforcement, branch policy, etc.) +/// Returns Ok(()) to allow dispatch, Err(reason) to block it. +pub type PreDispatchHook = Box Result<(), String> + Send + Sync>; + pub(crate) struct AppState { pub pty_manager: Arc, pub sidecar_manager: Arc, @@ -40,6 +44,7 @@ pub(crate) struct AppState { pub remote_manager: Arc, pub search_db: Arc, pub app_config: Arc, + pub pre_dispatch_hooks: Vec, _telemetry: telemetry::TelemetryGuard, } @@ -413,6 +418,7 @@ pub fn run() { remote_manager, search_db, app_config: config, + pre_dispatch_hooks: Vec::new(), _telemetry: telemetry_guard, });