@@ -226,6 +226,7 @@ type ModifyingHookPolicy<K extends PluginHookName, TResult> = {
226226 terminalLabel ?: string ;
227227 onTerminal ?: ( params : { hookName : K ; pluginId : string ; result : TResult } ) => void ;
228228 includeRegistration ?: ( registration : PluginHookRegistration < K > ) => boolean ;
229+ assertHandlerBoundaryActive ?: ( ) => void ;
229230} ;
230231
231232type PluginTargetedInboundClaimOutcome =
@@ -728,6 +729,8 @@ export function createHookRunner(
728729 let result : TResult | undefined ;
729730
730731 for ( const hook of selectedHooks ) {
732+ policy . assertHandlerBoundaryActive ?.( ) ;
733+ let shouldStop = false ;
731734 try {
732735 const handler = hook . handler as ( event : unknown , ctx : unknown ) => Promise < TResult > ;
733736 const handlerEvent = policy . isolateEventPerHandler
@@ -752,7 +755,7 @@ export function createHookRunner(
752755 `[hooks] ${ hookName } ${ terminalLabel } decided by ${ hook . pluginId } (priority=${ priority } ); skipping remaining handlers` ,
753756 ) ;
754757 policy . onTerminal ?.( { hookName, pluginId : hook . pluginId , result } ) ;
755- break ;
758+ shouldStop = true ;
756759 }
757760 }
758761 } catch ( err ) {
@@ -761,6 +764,10 @@ export function createHookRunner(
761764 }
762765 handleHookError ( { hookName, pluginId : hook . pluginId , error : err } ) ;
763766 }
767+ policy . assertHandlerBoundaryActive ?.( ) ;
768+ if ( shouldStop ) {
769+ break ;
770+ }
764771 }
765772
766773 return result ;
@@ -989,7 +996,6 @@ export function createHookRunner(
989996 assertActive,
990997 } ) ;
991998 try {
992- assertActive ( ) ;
993999 const result = await runModifyingHook <
9941000 "before_prompt_build" ,
9951001 PluginHookBeforePromptBuildResult
@@ -1000,9 +1006,9 @@ export function createHookRunner(
10001006 {
10011007 mergeResults : mergeBeforePromptBuild ,
10021008 includeRegistration : ( registration ) => registration . requiresToolAuthority === true ,
1009+ assertHandlerBoundaryActive : assertActive ,
10031010 } ,
10041011 ) ;
1005- assertActive ( ) ;
10061012 if ( ! result ) {
10071013 return undefined ;
10081014 }
0 commit comments