emitHookDrivenShutdown fans out the standard Error / notification(level=error) / on_error stanzas when a hook (post_tool_use or before_llm_call) signals run termination.
( ctx context.Context, a *agent.Agent, sess *session.Session, message string, events EventSink, )
| 154 | // notification(level=error) / on_error stanzas when a hook |
| 155 | // (post_tool_use or before_llm_call) signals run termination. |
| 156 | func (r *LocalRuntime) emitHookDrivenShutdown( |
| 157 | ctx context.Context, |
| 158 | a *agent.Agent, |
| 159 | sess *session.Session, |
| 160 | message string, |
| 161 | events EventSink, |
| 162 | ) { |
| 163 | if message == "" { |
| 164 | // aggregate() always populates Result.Message on a deny |
| 165 | // verdict; the fallback covers any future hook that returns |
| 166 | // block without a reason. |
| 167 | message = "Agent terminated by a hook." |
| 168 | } |
| 169 | events.Emit(ErrorWithCodeForSession(sess.ID, ErrorCodeHookBlocked, message)) |
| 170 | r.notifyError(ctx, a, sess.ID, message) |
| 171 | } |
| 172 | |
| 173 | // finalizeEventChannel performs cleanup at the end of a RunStream goroutine: |
| 174 | // emits the StreamStopped event, fires hooks, records telemetry, restores the |
no test coverage detected