the claude code sourcemaps leaked march 31
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 64 lines 2.1 kB view raw
1import { HOOK_EVENTS } from 'src/entrypoints/agentSdkTypes.js' 2import type { AppState } from 'src/state/AppState.js' 3import { logForDebugging } from '../debug.js' 4import type { HooksSettings } from '../settings/types.js' 5import { addSessionHook, removeSessionHook } from './sessionHooks.js' 6 7/** 8 * Registers hooks from a skill's frontmatter as session hooks. 9 * 10 * Hooks are registered as session-scoped hooks that persist for the duration 11 * of the session. If a hook has `once: true`, it will be automatically removed 12 * after its first successful execution. 13 * 14 * @param setAppState - Function to update the app state 15 * @param sessionId - The current session ID 16 * @param hooks - The hooks settings from the skill's frontmatter 17 * @param skillName - The name of the skill (for logging) 18 * @param skillRoot - The base directory of the skill (for CLAUDE_PLUGIN_ROOT env var) 19 */ 20export function registerSkillHooks( 21 setAppState: (updater: (prev: AppState) => AppState) => void, 22 sessionId: string, 23 hooks: HooksSettings, 24 skillName: string, 25 skillRoot?: string, 26): void { 27 let registeredCount = 0 28 29 for (const eventName of HOOK_EVENTS) { 30 const matchers = hooks[eventName] 31 if (!matchers) continue 32 33 for (const matcher of matchers) { 34 for (const hook of matcher.hooks) { 35 // For once: true hooks, use onHookSuccess callback to remove after execution 36 const onHookSuccess = hook.once 37 ? () => { 38 logForDebugging( 39 `Removing one-shot hook for event ${eventName} in skill '${skillName}'`, 40 ) 41 removeSessionHook(setAppState, sessionId, eventName, hook) 42 } 43 : undefined 44 45 addSessionHook( 46 setAppState, 47 sessionId, 48 eventName, 49 matcher.matcher || '', 50 hook, 51 onHookSuccess, 52 skillRoot, 53 ) 54 registeredCount++ 55 } 56 } 57 } 58 59 if (registeredCount > 0) { 60 logForDebugging( 61 `Registered ${registeredCount} hooks from skill '${skillName}'`, 62 ) 63 } 64}