MCPcopy Create free account
hub / github.com/Noumena-Network/code / groupHooksByEventAndMatcher

Function groupHooksByEventAndMatcher

src/utils/hooks/hooksConfigManager.ts:271–366  ·  view source on GitHub ↗
(
  appState: AppState,
  toolNames: string[],
)

Source from the content-addressed store, hash-verified

269
270// Group hooks by event and matcher
271export function groupHooksByEventAndMatcher(
272 appState: AppState,
273 toolNames: string[],
274): Record<HookEvent, Record<string, IndividualHookConfig[]>> {
275 const grouped: Record<HookEvent, Record<string, IndividualHookConfig[]>> = {
276 PreToolUse: {},
277 PostToolUse: {},
278 PostToolUseFailure: {},
279 PermissionDenied: {},
280 Notification: {},
281 UserPromptSubmit: {},
282 SessionStart: {},
283 SessionEnd: {},
284 Stop: {},
285 StopFailure: {},
286 SubagentStart: {},
287 SubagentStop: {},
288 PreCompact: {},
289 PostCompact: {},
290 PermissionRequest: {},
291 Setup: {},
292 TeammateIdle: {},
293 TaskCreated: {},
294 TaskCompleted: {},
295 Elicitation: {},
296 ElicitationResult: {},
297 ConfigChange: {},
298 WorktreeCreate: {},
299 WorktreeRemove: {},
300 InstructionsLoaded: {},
301 CwdChanged: {},
302 FileChanged: {},
303 }
304
305 const metadata = getHookEventMetadata(toolNames)
306
307 // Include hooks from settings files
308 getAllHooks(appState).forEach(hook => {
309 const eventGroup = grouped[hook.event]
310 if (eventGroup) {
311 // For events without matchers, use empty string as key
312 const matcherKey =
313 metadata[hook.event].matcherMetadata !== undefined
314 ? hook.matcher || ''
315 : ''
316 if (!eventGroup[matcherKey]) {
317 eventGroup[matcherKey] = []
318 }
319 eventGroup[matcherKey].push(hook)
320 }
321 })
322
323 // Include registered hooks (e.g., plugin hooks)
324 const registeredHooks = getRegisteredHooks()
325 if (registeredHooks) {
326 for (const [event, matchers] of Object.entries(registeredHooks)) {
327 const hookEvent = event as HookEvent
328 const eventGroup = grouped[hookEvent]

Callers 1

HooksConfigMenuFunction · 0.85

Calls 4

getAllHooksFunction · 0.85
getRegisteredHooksFunction · 0.85
isInternalBuildFunction · 0.85
entriesMethod · 0.80

Tested by

no test coverage detected