(
trigger: 'init' | 'maintenance',
{ forceSyncExecution }: { forceSyncExecution?: boolean } = {},
)
| 183 | } |
| 184 | |
| 185 | export async function processSetupHooks( |
| 186 | trigger: 'init' | 'maintenance', |
| 187 | { forceSyncExecution }: { forceSyncExecution?: boolean } = {}, |
| 188 | ): Promise<HookResultMessage[]> { |
| 189 | // Same rationale as processSessionStartHooks above. |
| 190 | if (isBareMode()) { |
| 191 | return [] |
| 192 | } |
| 193 | const hookMessages: HookResultMessage[] = [] |
| 194 | const additionalContexts: string[] = [] |
| 195 | |
| 196 | if (shouldAllowManagedHooksOnly()) { |
| 197 | logForDebugging('Skipping plugin hooks - allowManagedHooksOnly is enabled') |
| 198 | } else if (isDeferredHeadlessPluginStartupSurfacesEnabled()) { |
| 199 | logForDebugging( |
| 200 | '[STARTUP] Skipping plugin setup-hook loading during deferred headless startup', |
| 201 | ) |
| 202 | } else { |
| 203 | try { |
| 204 | await loadPluginHooks() |
| 205 | } catch (error) { |
| 206 | const errorMessage = |
| 207 | error instanceof Error ? error.message : String(error) |
| 208 | logForDebugging( |
| 209 | `Warning: Failed to load plugin hooks. Setup hooks from plugins will not execute. Error: ${errorMessage}`, |
| 210 | { level: 'warn' }, |
| 211 | ) |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | for await (const hookResult of executeSetupHooks( |
| 216 | trigger, |
| 217 | undefined, |
| 218 | undefined, |
| 219 | forceSyncExecution, |
| 220 | )) { |
| 221 | if (hookResult.message) { |
| 222 | hookMessages.push(hookResult.message) |
| 223 | } |
| 224 | if ( |
| 225 | hookResult.additionalContexts && |
| 226 | hookResult.additionalContexts.length > 0 |
| 227 | ) { |
| 228 | additionalContexts.push(...hookResult.additionalContexts) |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | if (additionalContexts.length > 0) { |
| 233 | const contextMessage = createAttachmentMessage({ |
| 234 | type: 'hook_additional_context', |
| 235 | content: additionalContexts, |
| 236 | hookName: 'Setup', |
| 237 | toolUseID: 'Setup', |
| 238 | hookEvent: 'Setup', |
| 239 | }) |
| 240 | hookMessages.push(contextMessage) |
| 241 | } |
| 242 |
no test coverage detected