diff --git a/crates/maestro-acp/src/lib.rs b/crates/maestro-acp/src/lib.rs index 1bfb439..455bafe 100644 --- a/crates/maestro-acp/src/lib.rs +++ b/crates/maestro-acp/src/lib.rs @@ -64,7 +64,7 @@ pub use agent_client_protocol::schema::v1 as schema; #[derive(Debug)] pub enum AcpUpdate { /// A raw `session/update` notification from the adapter. - Notification(SessionNotification), + Notification(Box), /// The prompt response for `turn` arrived. All notifications for this /// turn precede this marker on the wire, and therefore in this channel. /// The event pump must fire `done` after persisting every preceding @@ -818,7 +818,7 @@ async fn run_connection( return Ok(()); } // A dropped receiver only means nobody wants updates any more. - let _ = received_updates.send(AcpUpdate::Notification(notification)); + let _ = received_updates.send(AcpUpdate::Notification(Box::new(notification))); Ok(()) }, agent_client_protocol::on_receive_notification!(), @@ -934,18 +934,18 @@ async fn run_connection( models.as_ref(), ))); if let Some(modes) = &modes { - let _ = updates_tx.send(AcpUpdate::Notification(SessionNotification::new( + let _ = updates_tx.send(AcpUpdate::Notification(Box::new(SessionNotification::new( SessionId::new(session_id.as_str()), SessionUpdate::CurrentModeUpdate(CurrentModeUpdate::new( modes.current_mode_id.clone(), )), - ))); + )))); } if !config_options.lock().expect("config options").is_empty() { - let _ = updates_tx.send(AcpUpdate::Notification(config_notification( + let _ = updates_tx.send(AcpUpdate::Notification(Box::new(config_notification( &session_id, config_options.lock().expect("config options").clone(), - ))); + )))); } let _ = ready_tx.send(Ok(session_id.clone())); @@ -1023,7 +1023,7 @@ async fn run_connection( }).on_receiving_result(move |result| async move { if result.is_ok() { let options = replace_config_value(&callback_options, &callback_config_id, &callback_value); - let _ = callback_updates.send(AcpUpdate::Notification(config_notification(&callback_session, options))); + let _ = callback_updates.send(AcpUpdate::Notification(Box::new(config_notification(&callback_session, options)))); } if let Some(done) = callback_done.lock().expect("config sender").take() { let _ = done.send(result.map(|_| ()).map_err(|error| error.to_string())); @@ -1042,13 +1042,13 @@ async fn run_connection( )).on_receiving_result(move |result| async move { if result.is_ok() { let options = replace_config_value(&callback_options, &callback_config_id, &callback_value); - let _ = callback_updates.send(AcpUpdate::Notification(config_notification(&callback_session, options))); - let _ = callback_updates.send(AcpUpdate::Notification(SessionNotification::new( + let _ = callback_updates.send(AcpUpdate::Notification(Box::new(config_notification(&callback_session, options)))); + let _ = callback_updates.send(AcpUpdate::Notification(Box::new(SessionNotification::new( SessionId::new(callback_session.as_str()), SessionUpdate::CurrentModeUpdate(CurrentModeUpdate::new( callback_value.as_value_id().expect("checked mode value").0.clone(), )), - ))); + )))); } if let Some(done) = callback_done.lock().expect("config sender").take() { let _ = done.send(result.map(|_| ()).map_err(|error| error.to_string())); @@ -1066,7 +1066,7 @@ async fn run_connection( let mut current = callback_options.lock().expect("config options"); current.retain(|option| option.id.0.as_ref().starts_with("__maestro_legacy_")); current.extend(response.config_options.clone()); - let _ = callback_updates.send(AcpUpdate::Notification(config_notification(&callback_session, current.clone()))); + let _ = callback_updates.send(AcpUpdate::Notification(Box::new(config_notification(&callback_session, current.clone())))); } if let Some(done) = callback_done.lock().expect("config sender").take() { let _ = done.send(result.map(|_| ()).map_err(|error| error.to_string())); diff --git a/crates/maestro-acp/tests/spawn.rs b/crates/maestro-acp/tests/spawn.rs index 015b139..ef5fe68 100644 --- a/crates/maestro-acp/tests/spawn.rs +++ b/crates/maestro-acp/tests/spawn.rs @@ -193,6 +193,9 @@ async fn session_updates_reach_the_taken_receiver() { .await .expect("update within 5s") .expect("channel open"); + let maestro_acp::AcpUpdate::Notification(first) = first else { + panic!("expected Notification"); + }; assert_eq!(first.session_id.0.as_ref(), session.session_id()); match first.update { SessionUpdate::AgentMessageChunk(chunk) => match chunk.content { @@ -221,7 +224,10 @@ async fn advertised_settings_are_normalized_and_mutable() { .await .expect("settings update") .expect("channel open"); - if let SessionUpdate::ConfigOptionUpdate(options) = update.update { + let maestro_acp::AcpUpdate::Notification(n) = update else { + continue; + }; + if let SessionUpdate::ConfigOptionUpdate(options) = n.update { break options.config_options; } }; @@ -390,7 +396,10 @@ async fn drop_terminates_and_reaps_the_child() { fake.wait_for_exit().await; } -fn chunk_text(n: &maestro_acp::schema::SessionNotification) -> String { +fn chunk_text(update: &maestro_acp::AcpUpdate) -> String { + let maestro_acp::AcpUpdate::Notification(n) = update else { + panic!("expected Notification, got {update:?}"); + }; match &n.update { SessionUpdate::AgentMessageChunk(chunk) => match &chunk.content { ContentBlock::Text(t) => t.text.clone(), diff --git a/crates/maestro-daemon/src/session.rs b/crates/maestro-daemon/src/session.rs index dfcdc68..1dae7a1 100644 --- a/crates/maestro-daemon/src/session.rs +++ b/crates/maestro-daemon/src/session.rs @@ -2408,7 +2408,7 @@ fn start_acp_event_pump( maestro_acp::AcpUpdate::Notification(notification) => { let append_error = { let mut events = events.lock().await; - let event = PersistedEvent::Notification(Box::new(notification)); + let event = PersistedEvent::Notification(notification); match events.log.append(&event) { Ok(seq) => { let logged = LoggedEvent { @@ -2436,7 +2436,11 @@ fn start_acp_event_pump( break; } } - maestro_acp::AcpUpdate::TurnDone { turn: _, result, done } => { + maestro_acp::AcpUpdate::TurnDone { + turn: _, + result, + done, + } => { // Every notification for this turn has been persisted and // broadcast above. Signal the done oneshot so // finish_queued_acp_turn runs with the transcript complete.