claude_cli: tool calls on the event bus, extensions can block, permissions deny/extensions-only (#182)
This commit is contained in:
1 parent
6ebf1c3180
commit
6978aad27a
12 files changed
+297
-12
No files matched your search
@@ -378,6 +378,42 @@ impl Agent {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A tool `claude_cli` ran itself: `ToolCall` (unless the permission bridge sent it before the
|
||||
/// run) and `ToolResult`, in hx' vocabulary. Informational: the tool already ran.
|
||||
async fn claude_tool(
|
||||
&self,
|
||||
id: String,
|
||||
name: &str,
|
||||
input: &serde_json::Value,
|
||||
content: String,
|
||||
is_error: bool,
|
||||
) {
|
||||
let (name, args) = crate::approve::hx_call(name, input);
|
||||
let seen = self
|
||||
.cx
|
||||
.state
|
||||
.claude_seen
|
||||
.lock()
|
||||
.unwrap_or_else(|e| e.into_inner())
|
||||
.remove(&id);
|
||||
if !seen {
|
||||
self.emit(Event::ToolCall {
|
||||
id: id.clone(),
|
||||
name: name.clone(),
|
||||
args: args.clone(),
|
||||
})
|
||||
.await;
|
||||
}
|
||||
self.emit(Event::ToolResult {
|
||||
id,
|
||||
name,
|
||||
args,
|
||||
content,
|
||||
is_error,
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
async fn emit(&self, ev: Event) -> crate::hook::Outcome {
|
||||
self.bus.emit(ev).await
|
||||
}
|
||||
@@ -460,6 +496,10 @@ impl Agent {
|
||||
if let StreamEvent::Done { message, stop, usage } = &ev {
|
||||
done = Some((message.clone(), *stop, usage.clone()));
|
||||
}
|
||||
if let StreamEvent::ToolRun { id, name, input, content, is_error } = ev {
|
||||
self.claude_tool(id, &name, &input, content, is_error).await;
|
||||
continue;
|
||||
}
|
||||
self.emit(Event::Stream(ev)).await;
|
||||
}
|
||||
None => break,
|
||||
|
||||
Reference in new issue
Block a user