MCPcopy
hub / github.com/docker/docker-agent / dispatchHook

Method dispatchHook

pkg/runtime/hooks.go:93–129  ·  view source on GitHub ↗

dispatchHook is the common dispatch path shared by every hook callsite: resolve the pre-built executor, dispatch, and emit any [Result.SystemMessage] as a Warning event. Errors are logged at warn level and surfaced as nil results so callers can use a single nil check to mean "nothing useful came bac

(
	ctx context.Context,
	a *agent.Agent,
	event hooks.EventType,
	input *hooks.Input,
	events EventSink,
)

Source from the content-addressed store, hash-verified

91// silently logged, since those events are themselves the user-facing
92// notification mechanism.
93func (r *LocalRuntime) dispatchHook(
94 ctx context.Context,
95 a *agent.Agent,
96 event hooks.EventType,
97 input *hooks.Input,
98 events EventSink,
99) *hooks.Result {
100 exec := r.hooksExec(a)
101 if exec == nil || !exec.Has(event) {
102 return nil
103 }
104
105 // Auto-fill AgentName for events whose Input builder omits it (tool
106 // events via toolexec.NewHooksInput), mirroring Cwd auto-fill in
107 // Executor.Dispatch. Caller-set values win.
108 if input != nil && input.AgentName == "" {
109 input.AgentName = a.Name()
110 }
111
112 started := time.Now()
113 if events != nil {
114 events.Emit(HookStarted(event, input.SessionID, a.Name()))
115 }
116 result, err := exec.Dispatch(ctx, event, input)
117 if events != nil {
118 events.Emit(HookFinished(event, input.SessionID, result, err, time.Since(started), a.Name()))
119 }
120 if err != nil {
121 slog.WarnContext(ctx, "Hook execution failed", "event", event, "agent", a.Name(), "error", err)
122 return nil
123 }
124
125 if events != nil && result.SystemMessage != "" {
126 events.Emit(Warning(result.SystemMessage, a.Name()))
127 }
128 return result
129}
130
131// executeSessionStartHooks fires session_start once at the top of
132// RunStream and returns its AdditionalContext as transient system

Callers 15

executeTurnStartHooksMethod · 0.95
executeTurnEndHooksMethod · 0.95
executeStopHooksMethod · 0.95
notifyMethod · 0.95

Calls 9

hooksExecMethod · 0.95
HookStartedFunction · 0.85
HookFinishedFunction · 0.85
WarningFunction · 0.85
NowMethod · 0.80
NameMethod · 0.65
EmitMethod · 0.65
DispatchMethod · 0.65
HasMethod · 0.45

Tested by

no test coverage detected