feat: Hooks (#9093)

This commit is contained in:
Alex Hancock
2026-05-11 12:02:44 -04:00
committed by GitHub
parent f5eda3527c
commit 40d4b118bb
12 changed files with 1258 additions and 18 deletions
+32 -8
View File
@@ -500,6 +500,28 @@ impl CliSession {
/// Start an interactive session, optionally with an initial message
pub async fn interactive(&mut self, prompt: Option<String>) -> Result<()> {
self.agent
.emit_hook(goose::hooks::HookEvent::SessionStart, &self.session_id)
.await;
let result = self.run_interactive(prompt).await;
self.agent
.emit_hook(goose::hooks::HookEvent::SessionEnd, &self.session_id)
.await;
if result.is_ok() {
println!(
"\n {} {}",
console::style("").red(),
console::style(format!("session closed · {}", &self.session_id)).dim()
);
}
result
}
async fn run_interactive(&mut self, prompt: Option<String>) -> Result<()> {
if let Some(prompt) = prompt {
let msg = Message::user().with_text(&prompt);
self.process_message(msg, CancellationToken::default(), true)
@@ -536,12 +558,6 @@ impl CliSession {
.await?;
}
println!(
"\n {} {}",
console::style("").red(),
console::style(format!("session closed · {}", &self.session_id)).dim()
);
Ok(())
}
@@ -1044,9 +1060,17 @@ impl CliSession {
/// Process a single message and exit
pub async fn headless(&mut self, prompt: String) -> Result<()> {
self.agent
.emit_hook(goose::hooks::HookEvent::SessionStart, &self.session_id)
.await;
let message = Message::user().with_text(&prompt);
self.process_message(message, CancellationToken::default(), false)
.await?;
let result = self
.process_message(message, CancellationToken::default(), false)
.await;
self.agent
.emit_hook(goose::hooks::HookEvent::SessionEnd, &self.session_id)
.await;
result?;
Ok(())
}