From d665d7cc1017cab72377932b268e559a24b25a59 Mon Sep 17 00:00:00 2001 From: Seto Elkahfi <1797197+setoelkahfi@users.noreply.github.com> Date: Thu, 29 Oct 2026 17:30:52 +0100 Subject: [PATCH] feat: show /login, /logout and /whoami as system notices These three answered as plain assistant messages. They now go out as a completed think tool call, the lightbulb row Zed draws for system status. A browser /login reply has several lines and a URL, so the new send_system_notice puts the first line in the card title and the rest in its content. The URL stays visible and clickable. The whoami test reads the tool card instead of message chunks. The TUI already renders these as system messages and is unchanged. Co-Authored-By: Claude Sonnet 5.5 --- crates/cli/src/main.rs | 57 ++++++++++++++++++++++++++++++++-- crates/cli/tests/acp_logout.rs | 28 ++++++++++------- 2 files changed, 71 insertions(+), 14 deletions(-) diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index a8378c9..888be3e 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -433,6 +433,19 @@ fn tool_arguments_content(arguments_json: &str) -> ToolCallContent { fenced_code_block(language, &chat::pretty_tool_arguments(arguments_json)).into() } +/// Splits a notice into its title (the first non-empty line) and the body +/// (everything after it), if there is any. +fn split_notice(text: &str) -> (String, Option) { + let text = text.trim(); + match text.split_once('\n') { + Some((title, rest)) if !rest.trim().is_empty() => { + (title.trim().to_string(), Some(rest.trim().to_string())) + } + Some((title, _)) => (title.trim().to_string(), None), + None => (text.to_string(), None), + } +} + /// Wraps a tool's output as the display content of its ACP tool-call card /// (issue #78). Capped via [`chat::cap_output_preview`] — display only, the /// model still gets the full output — and fenced so plain-text output (or a @@ -1661,6 +1674,28 @@ impl SiGitAgent { )) } + /// A system notice that may run to several lines: the first line is the + /// card's title and the rest is its body, so a sign-in URL stays visible + /// and clickable. A single line is the same as `send_system_status`. + fn send_system_notice( + &self, + cx: &ConnectionTo, + session_id: SessionId, + text: impl AsRef, + ) -> agent_client_protocol::Result<()> { + let (title, body) = split_notice(text.as_ref()); + let mut call = ToolCall::new(format!("system-status-{}", uuid::Uuid::new_v4()), title) + .kind(ToolKind::Think) + .status(ToolCallStatus::Completed); + if let Some(body) = body { + call = call.content(vec![body.into()]); + } + cx.send_notification(SessionNotification::new( + session_id, + SessionUpdate::ToolCall(call), + )) + } + /// Run one inference turn (`fut`) while concurrently forwarding any streamed /// tokens to the editor. The sink receiver is drained as the future runs, so /// chunks reach the client live rather than all at once when it resolves. @@ -5992,15 +6027,15 @@ async fn exec_slash_acp( .unwrap_or_else(|message| message), }; mcp::refresh_session_auth().await; - agent.send_assistant_message(cx, session_id, message).ok(); + agent.send_system_notice(cx, session_id, message).ok(); } SlashCommand::Logout => { let message = agent.sign_out(cx).await; - agent.send_assistant_message(cx, session_id, message).ok(); + agent.send_system_notice(cx, session_id, message).ok(); } SlashCommand::Whoami => { let message = account::status_line().await; - agent.send_assistant_message(cx, session_id, message).ok(); + agent.send_system_notice(cx, session_id, message).ok(); } SlashCommand::Reload => { agent.handle_reload(cx, session_id).await; @@ -6997,6 +7032,22 @@ async fn main() -> anyhow::Result<()> { #[cfg(test)] mod tests { + #[test] + fn notices_split_into_title_and_body() { + assert_eq!(super::split_notice("Signed in"), ("Signed in".into(), None)); + assert_eq!( + super::split_notice("Signed in\n"), + ("Signed in".into(), None) + ); + assert_eq!( + super::split_notice("Open this page:\nhttps://x.test/a\nthen return"), + ( + "Open this page:".into(), + Some("https://x.test/a\nthen return".into()) + ) + ); + } + use super::*; /// Compares path components so the tests pass on both Unix (forward slashes) diff --git a/crates/cli/tests/acp_logout.rs b/crates/cli/tests/acp_logout.rs index e51da65..5a9185d 100644 --- a/crates/cli/tests/acp_logout.rs +++ b/crates/cli/tests/acp_logout.rs @@ -124,28 +124,34 @@ impl AgentUnderTest { } } - /// Send `text` as a prompt and return the agent message text it streamed - /// before the turn ended. - fn prompt_text(&mut self, session_id: &str, text: &str) -> String { + /// Send `text` as a prompt and return the system notice it produced: the + /// completed `think` tool card's title, then its content text if any. + fn prompt_notice(&mut self, session_id: &str, text: &str) -> String { let id = self.request( "session/prompt", json!({"sessionId": session_id, "prompt": [{"type": "text", "text": text}]}), ); let deadline = Instant::now() + TIMEOUT; - let mut reply = String::new(); + let mut notice = String::new(); loop { let remaining = deadline.saturating_duration_since(Instant::now()); let Ok(message) = self.incoming.recv_timeout(remaining) else { panic!("timed out waiting for the response to prompt {id}"); }; - if message["method"] == "session/update" - && message["params"]["update"]["sessionUpdate"] == "agent_message_chunk" - && let Some(chunk) = message["params"]["update"]["content"]["text"].as_str() - { - reply.push_str(chunk); + let update = &message["params"]["update"]; + if message["method"] == "session/update" && update["sessionUpdate"] == "tool_call" { + assert_eq!(update["kind"], "think", "{update}"); + assert_eq!(update["status"], "completed", "{update}"); + notice.push_str(update["title"].as_str().unwrap_or_default()); + for item in update["content"].as_array().into_iter().flatten() { + if let Some(body) = item["content"]["text"].as_str() { + notice.push('\n'); + notice.push_str(body); + } + } } if message["id"] == id && message.get("method").is_none() { - return reply; + return notice; } } } @@ -231,7 +237,7 @@ fn whoami_checks_the_session_against_the_user_endpoint() { .expect("session id") .to_string(); - let reply = agent.prompt_text(&session_id, "/whoami"); + let reply = agent.prompt_notice(&session_id, "/whoami"); assert!( reply.contains("Signed in to siGit Code Cloud as dev@example.com"), "{reply}"