Skip to content
Merged
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
35 changes: 31 additions & 4 deletions crates/zeph-acp/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ impl acp::Agent for ZephAcpAgent {

async fn cancel(&self, args: acp::CancelNotification) -> acp::Result<()> {
tracing::debug!(session_id = %args.session_id, "ACP cancel");
self.sessions.borrow_mut().remove(&args.session_id);
// Keep the session alive — the IDE may send another prompt on the same session_id.
// The current prompt() drain loop will finish naturally when the agent completes its turn.
Ok(())
}

Expand All @@ -246,9 +247,20 @@ impl acp::Agent for ZephAcpAgent {
}
}

/// Returns `true` if `text` looks like a raw tool-use marker that should not be
/// forwarded to the IDE (e.g. `[tool_use: bash (toolu_abc123)]`).
fn is_tool_use_marker(text: &str) -> bool {
let trimmed = text.trim();
trimmed.starts_with("[tool_use:") && trimmed.ends_with(']')
}

fn loopback_event_to_update(event: LoopbackEvent) -> Option<acp::SessionUpdate> {
match event {
LoopbackEvent::Chunk(text) | LoopbackEvent::FullMessage(text) if text.is_empty() => None,
LoopbackEvent::Chunk(text) | LoopbackEvent::FullMessage(text)
if text.is_empty() || is_tool_use_marker(&text) =>
{
None
}
LoopbackEvent::Chunk(text) | LoopbackEvent::FullMessage(text) => Some(
acp::SessionUpdate::AgentMessageChunk(acp::ContentChunk::new(text.into())),
),
Expand Down Expand Up @@ -319,7 +331,7 @@ mod tests {
}

#[tokio::test]
async fn cancel_removes_session() {
async fn cancel_keeps_session() {
let local = tokio::task::LocalSet::new();
local
.run_until(async {
Expand All @@ -334,7 +346,8 @@ mod tests {
.cancel(acp::CancelNotification::new(sid.clone()))
.await
.unwrap();
assert!(!agent.sessions.borrow().contains_key(&sid));
// Cancel keeps the session alive for subsequent prompts.
assert!(agent.sessions.borrow().contains_key(&sid));
})
.await;
}
Expand Down Expand Up @@ -474,4 +487,18 @@ mod tests {
})
.await;
}

#[test]
fn tool_use_marker_filtered() {
let event =
LoopbackEvent::Chunk("[tool_use: bash (toolu_01VzP6Q9b6JQY6ZP5r6qY9Wm)]".into());
assert!(loopback_event_to_update(event).is_none());

let event = LoopbackEvent::FullMessage("[tool_use: read (toolu_abc)]".into());
assert!(loopback_event_to_update(event).is_none());

// Normal text should pass through.
let event = LoopbackEvent::Chunk("hello [tool_use: not a marker".into());
assert!(loopback_event_to_update(event).is_some());
}
}
Loading