Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 54 additions & 3 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) {
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
Expand Down Expand Up @@ -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<Client>,
session_id: SessionId,
text: impl AsRef<str>,
) -> 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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
28 changes: 17 additions & 11 deletions crates/cli/tests/acp_logout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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}"
Expand Down
Loading