* Get hooks from allowed sources. * If allowManagedHooksOnly is set in policySettings, only managed hooks are returned. * If disableAllHooks is set in policySettings, no hooks are returned. * If disableAllHooks is set in non-managed settings, only managed hooks are returned * (non-managed settin
()
| 16 | * Otherwise, returns merged hooks from all sources (backwards compatible). |
| 17 | */ |
| 18 | function getHooksFromAllowedSources(): HooksSettings { |
| 19 | const policySettings = settingsModule.getSettingsForSource('policySettings') |
| 20 | |
| 21 | // If managed settings disables all hooks, return empty |
| 22 | if (policySettings?.disableAllHooks === true) { |
| 23 | return {} |
| 24 | } |
| 25 | |
| 26 | // If allowManagedHooksOnly is set in managed settings, only use managed hooks |
| 27 | if (policySettings?.allowManagedHooksOnly === true) { |
| 28 | return policySettings.hooks ?? {} |
| 29 | } |
| 30 | |
| 31 | // strictPluginOnlyCustomization: block user/project/local settings hooks. |
| 32 | // Plugin hooks (registered channel, hooks.ts:1391) are NOT affected — |
| 33 | // they're assembled separately and the managedOnly skip there is keyed |
| 34 | // on shouldAllowManagedHooksOnly(), not on this policy. Agent frontmatter |
| 35 | // hooks are gated at REGISTRATION (runAgent.ts:~535) by agent source — |
| 36 | // plugin/built-in/policySettings agents register normally, user-sourced |
| 37 | // agents skip registration under ["hooks"]. A blanket execution-time |
| 38 | // block here would over-kill plugin agents' hooks. |
| 39 | if (isRestrictedToPluginOnly('hooks')) { |
| 40 | return policySettings?.hooks ?? {} |
| 41 | } |
| 42 | |
| 43 | const mergedSettings = settingsModule.getSettings_DEPRECATED() |
| 44 | |
| 45 | // If disableAllHooks is set in non-managed settings, only managed hooks still run |
| 46 | // (non-managed settings cannot override managed hooks) |
| 47 | if (mergedSettings.disableAllHooks === true) { |
| 48 | return policySettings?.hooks ?? {} |
| 49 | } |
| 50 | |
| 51 | // Otherwise, use all hooks (merged from all sources) - backwards compatible |
| 52 | return mergedSettings.hooks ?? {} |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Check if only managed hooks should run. |
no test coverage detected