feat(hooks): pass working_dir to the Stop hook context (#10296)
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -459,19 +459,26 @@ impl Agent {
|
||||
fn stop_hook_context(
|
||||
session_id: &str,
|
||||
last_assistant_message: &str,
|
||||
working_dir: &str,
|
||||
) -> crate::hooks::HookContext {
|
||||
crate::hooks::HookContext::new(crate::hooks::HookEvent::Stop, session_id)
|
||||
.with_last_assistant_message(last_assistant_message.to_string())
|
||||
.with_working_dir(working_dir.to_string())
|
||||
}
|
||||
|
||||
async fn emit_stop_hook(&self, session_id: &str, last_assistant_message: &str) {
|
||||
async fn emit_stop_hook(
|
||||
&self,
|
||||
session_id: &str,
|
||||
last_assistant_message: &str,
|
||||
working_dir: &str,
|
||||
) {
|
||||
if !self.hook_manager.has_hooks(crate::hooks::HookEvent::Stop) {
|
||||
return;
|
||||
}
|
||||
self.hook_manager
|
||||
.emit(
|
||||
crate::hooks::HookEvent::Stop,
|
||||
Self::stop_hook_context(session_id, last_assistant_message),
|
||||
Self::stop_hook_context(session_id, last_assistant_message, working_dir),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
@@ -480,11 +487,12 @@ impl Agent {
|
||||
&self,
|
||||
session_id: &str,
|
||||
last_assistant_message: &str,
|
||||
working_dir: &str,
|
||||
) -> crate::hooks::HookDecision {
|
||||
self.hook_manager
|
||||
.emit_blocking(
|
||||
crate::hooks::HookEvent::Stop,
|
||||
Self::stop_hook_context(session_id, last_assistant_message),
|
||||
Self::stop_hook_context(session_id, last_assistant_message, working_dir),
|
||||
)
|
||||
.await
|
||||
}
|
||||
@@ -1979,7 +1987,7 @@ impl Agent {
|
||||
conversation.push(message);
|
||||
|
||||
match self
|
||||
.emit_stop_hook_blocking(&session_config.id, &last_assistant_text)
|
||||
.emit_stop_hook_blocking(&session_config.id, &last_assistant_text, &session.working_dir.to_string_lossy())
|
||||
.await
|
||||
{
|
||||
crate::hooks::HookDecision::Allow => {
|
||||
@@ -2885,7 +2893,7 @@ impl Agent {
|
||||
|
||||
if exit_chat {
|
||||
match self
|
||||
.emit_stop_hook_blocking(&session_config.id, &last_assistant_text)
|
||||
.emit_stop_hook_blocking(&session_config.id, &last_assistant_text, &session.working_dir.to_string_lossy())
|
||||
.await
|
||||
{
|
||||
crate::hooks::HookDecision::Allow => {
|
||||
@@ -2918,7 +2926,7 @@ impl Agent {
|
||||
}
|
||||
|
||||
if !stop_hook_handled_for_exit {
|
||||
self.emit_stop_hook(&session_config.id, &last_assistant_text).await;
|
||||
self.emit_stop_hook(&session_config.id, &last_assistant_text, &session.working_dir.to_string_lossy()).await;
|
||||
}
|
||||
}.instrument(reply_stream_span));
|
||||
Ok(inner)
|
||||
|
||||
Reference in New Issue
Block a user