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

Function getHooksConfig

src/utils/hooks.ts:1496–1570  ·  view source on GitHub ↗
(
  appState: AppState | undefined,
  sessionId: string,
  hookEvent: HookEvent,
)

Source from the content-addressed store, hash-verified

1494}
1495
1496function getHooksConfig(
1497 appState: AppState | undefined,
1498 sessionId: string,
1499 hookEvent: HookEvent,
1500): Array<
1501 | HookMatcher
1502 | HookCallbackMatcher
1503 | FunctionHookMatcher
1504 | PluginHookMatcher
1505 | SkillHookMatcher
1506 | SessionDerivedHookMatcher
1507> {
1508 // HookMatcher is a zod-stripped {matcher, hooks} so snapshot matchers can be
1509 // pushed directly without re-wrapping.
1510 const hooks: Array<
1511 | HookMatcher
1512 | HookCallbackMatcher
1513 | FunctionHookMatcher
1514 | PluginHookMatcher
1515 | SkillHookMatcher
1516 | SessionDerivedHookMatcher
1517 > = [...(getHooksConfigFromSnapshot()?.[hookEvent] ?? [])]
1518
1519 // Check if only managed hooks should run (used for both registered and session hooks)
1520 const managedOnly = shouldAllowManagedHooksOnly()
1521
1522 // Process registered hooks (SDK callbacks and plugin native hooks)
1523 const registeredHooks = getRegisteredHooks()?.[hookEvent]
1524 if (registeredHooks) {
1525 for (const matcher of registeredHooks) {
1526 // Skip plugin hooks when restricted to managed hooks only
1527 // Plugin hooks have pluginRoot set, SDK callbacks do not
1528 if (managedOnly && 'pluginRoot' in matcher) {
1529 continue
1530 }
1531 hooks.push(matcher)
1532 }
1533 }
1534
1535 // Merge session hooks for the current session only
1536 // Function hooks (like structured output enforcement) must be scoped to their session
1537 // to prevent hooks from one agent leaking to another (e.g., verification agent to main agent)
1538 // Skip session hooks entirely when allowManagedHooksOnly is set —
1539 // this prevents frontmatter hooks from agents/skills from bypassing the policy.
1540 // strictPluginOnlyCustomization does NOT block here — it gates at the
1541 // REGISTRATION sites (runAgent.ts:526 for agent frontmatter hooks) where
1542 // agentDefinition.source is known. A blanket block here would also kill
1543 // plugin-provided agents' frontmatter hooks, which is too broad.
1544 // Also skip if appState not provided (for backwards compatibility)
1545 if (!managedOnly && appState !== undefined) {
1546 const sessionHooks = getSessionHooks(appState, sessionId, hookEvent).get(
1547 hookEvent,
1548 )
1549 if (sessionHooks) {
1550 // SessionDerivedHookMatcher already includes optional skillRoot
1551 for (const matcher of sessionHooks) {
1552 hooks.push(matcher)
1553 }

Callers 1

getMatchingHooksFunction · 0.85

Calls 6

getRegisteredHooksFunction · 0.85
getSessionHooksFunction · 0.85
getSessionFunctionHooksFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected