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

Function processSetupHooks

src/utils/sessionStart.ts:185–244  ·  view source on GitHub ↗
(
  trigger: 'init' | 'maintenance',
  { forceSyncExecution }: { forceSyncExecution?: boolean } = {},
)

Source from the content-addressed store, hash-verified

183}
184
185export 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

Callers 2

runFunction · 0.85
runHeadlessFunction · 0.85

Calls 7

isBareModeFunction · 0.85
loadPluginHooksFunction · 0.85
executeSetupHooksFunction · 0.85
logForDebuggingFunction · 0.70
createAttachmentMessageFunction · 0.70

Tested by

no test coverage detected