Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(agent-inmem): advertise slash commands over ACP (#6515)
Wolf Mermelstein16b84f9cfd2c
diff --git a/crates/agent_inmem/src/domain/agent.rs b/crates/agent_inmem/src/domain/agent.rsindex b607597fca..10dfb225e4 100644--- a/crates/agent_inmem/src/domain/agent.rs+++ b/crates/agent_inmem/src/domain/agent.rs@@ -16,7 +16,8 @@ use std::time::Duration;use agent::types::{AssistantMessagePart, ChatMessage};use agent::{StreamAccumulator, StreamPart, ToolResponse};use agent_client_protocol::schema::v1::{- AgentCapabilities, BooleanPropertySchema, CancelNotification, ContentBlock, ContentChunk,+ AgentCapabilities, AvailableCommand, AvailableCommandInput, AvailableCommandsUpdate,+ BooleanPropertySchema, CancelNotification, ContentBlock, ContentChunk,CreateElicitationRequest, ElicitationAction, ElicitationFormMode, ElicitationPropertySchema,ElicitationSchema, ElicitationSessionScope, EnumOption, Implementation, InitializeRequest,InitializeResponse, IntegerPropertySchema, Meta, NewSessionRequest, NewSessionResponse,@@ -25,7 +26,7 @@ use agent_client_protocol::schema::v1::{SessionId, SessionNotification, SessionResumeCapabilities, SessionUpdate,SetSessionConfigOptionRequest, SetSessionConfigOptionResponse, StopReason, StringFormat,StringPropertySchema, ToolCall as AcpToolCall, ToolCallId, ToolCallStatus, ToolCallUpdate,- ToolCallUpdateFields, ToolKind,+ ToolCallUpdateFields, ToolKind, UnstructuredCommandInput,};use agent_client_protocol::{Agent, Channel as AcpChannel, Client, ConnectionTo, Error as AcpError,@@ -516,15 +517,17 @@ pub async fn serve(state: Arc<AgentState>, acp: AcpChannel) -> Result<(), AcpErr.on_receive_request({let state = Arc::clone(&state);- async move |request: NewSessionRequest, responder, _connection| {+ async move |request: NewSessionRequest, responder, connection| {let state = Arc::clone(&state);let acp_id = SessionId::new(macro_uuid::generate_uuid_v7().to_string());state.bind_acp_session(acp_id.clone(), false);state.connect_mcp(request.mcp_servers).await;- responder.respond(- NewSessionResponse::new(acp_id)+ let responded = responder.respond(+ NewSessionResponse::new(acp_id.clone()).config_options(state.model_config_options()),- )+ );+ advertise_commands(&state, &connection, acp_id);+ responded}},agent_client_protocol::on_receive_request!(),@@ -532,17 +535,19 @@ pub async fn serve(state: Arc<AgentState>, acp: AcpChannel) -> Result<(), AcpErr.on_receive_request({let state = Arc::clone(&state);- async move |request: ResumeSessionRequest, responder, _connection| {+ async move |request: ResumeSessionRequest, responder, connection| {let state = Arc::clone(&state);// Kept when the state already belongs to this ACP id -// either this process served the session, or a cold// attach replayed the frame log back into it (see// `domain::replay`).- state.bind_acp_session(request.session_id, true);+ state.bind_acp_session(request.session_id.clone(), true);state.connect_mcp(request.mcp_servers).await;- responder.respond(+ let responded = responder.respond(ResumeSessionResponse::new().config_options(state.model_config_options()),- )+ );+ advertise_commands(&state, &connection, request.session_id);+ responded}},agent_client_protocol::on_receive_request!(),@@ -819,6 +824,45 @@ async fn run_ask(}}+/// The slash commands this agent handles itself, as ACP advertises them:+/// bare names, no leading slash. `/ask` only while the host enables+/// development commands, since the prompt handler ignores it otherwise.+fn available_commands(state: &AgentState) -> Vec<AvailableCommand> {+ let name = |command: &str| command.trim_start_matches('/').to_owned();+ let mut commands = vec![AvailableCommand::new(+ name(COMPACT_COMMAND),+ "Drop the earlier conversation from the model's context",+ )];+ if state.enable_dev_commands {+ commands.push(+ AvailableCommand::new(+ name(ASK_COMMAND),+ "Ask the user a question through a form instead of running the model",+ )+ .input(AvailableCommandInput::Unstructured(+ UnstructuredCommandInput::new("<question> | <option> | <option>"),+ )),+ );+ }+ commands+}++/// Tell the client which slash commands this session accepts. Sent after+/// the open/resume response, the way the Claude Code adapter does, so the+/// fold has the session before the update names it.+fn advertise_commands(+ state: &AgentState,+ connection: &ConnectionTo<Client>,+ acp_session_id: SessionId,+) {+ let _ = connection.send_notification(SessionNotification::new(+ acp_session_id,+ SessionUpdate::AvailableCommandsUpdate(AvailableCommandsUpdate::new(available_commands(+ state,+ ))),+ ));+}+/// Split `/ask`'s argument into the question and its options: everything/// before the first `|` is the question, each `|`-separated piece after it/// an option. No `|` means free text.diff --git a/crates/agent_inmem/src/domain/agent/test.rs b/crates/agent_inmem/src/domain/agent/test.rsindex 7862d6c627..13ac828949 100644--- a/crates/agent_inmem/src/domain/agent/test.rs+++ b/crates/agent_inmem/src/domain/agent/test.rs@@ -159,6 +159,45 @@ async fn new_session_advertises_the_engine_supported_models() {);}+#[tokio::test]+async fn new_session_advertises_its_slash_commands() {+ let (notifications, _config_options, ()) = with_agent(+ Arc::new(ScriptedEngine::new(vec![])),+ async |connection, session| {+ // A round trip so the advertisement, sent right after the+ // session/new response, has landed before the client is torn down.+ connection+ .send_request(text_prompt(&session, "/compact"))+ .block_task()+ .await+ .expect("compaction should complete");+ },+ )+ .await;++ let advertised = notifications+ .iter()+ .find_map(|notification| match ¬ification.update {+ SessionUpdate::AvailableCommandsUpdate(update) => Some(update),+ _ => None,+ })+ .expect("session/new is followed by an available_commands_update");+ let names = advertised+ .available_commands+ .iter()+ .map(|command| command.name.as_str())+ .collect::<Vec<_>>();+ assert_eq!(names, vec!["compact", "ask"]);+ assert!(+ advertised.available_commands[0].input.is_none(),+ "/compact takes no argument, so the composer sends it as-is"+ );+ assert!(+ advertised.available_commands[1].input.is_some(),+ "/ask carries a hint for its question"+ );+}+#[tokio::test]async fn a_prompt_streams_updates_and_ends_the_turn() {let engine = Arc::new(ScriptedEngine::new(vec![@@ -196,12 +235,14 @@ async fn a_prompt_streams_updates_and_ends_the_turn() {SessionUpdate::AgentMessageChunk(_) => "message",SessionUpdate::ToolCall(_) => "tool_call",SessionUpdate::ToolCallUpdate(_) => "tool_call_update",+ SessionUpdate::AvailableCommandsUpdate(_) => "commands",_ => "other",}).collect();assert_eq!(kinds,vec![+ "commands","thought","message","tool_call",@@ -363,7 +404,13 @@ async fn engine_cancellation_is_not_rendered_as_an_error_message() {.await;assert_eq!(response.stop_reason, StopReason::Cancelled);- assert!(notifications.is_empty());+ assert!(+ notifications.iter().all(|notification| matches!(+ notification.update,+ SessionUpdate::AvailableCommandsUpdate(_)+ )),+ "only the session-open command advertisement, no error message"+ );}#[tokio::test]