@@ -375,8 +375,10 @@ program
375375 inkUnmountFn ?.( ) ;
376376 } ;
377377
378- // Create a UILoopFn that translates Wire messages → WireUIEvent for Shell
379- const createShellUILoopFn = ( pe : ( event : WireUIEvent ) => void ) : UILoopFn => {
378+ // Create a UILoopFn that translates Wire messages → WireUIEvent for Shell.
379+ // Uses the outer `pushEvent` variable (not a parameter) so that event
380+ // routing stays correct across Shell lifecycle changes.
381+ const createShellUILoopFn = ( ) : UILoopFn => {
380382 return async ( wire ) => {
381383 const uiSide = wire . uiSide ( true ) ;
382384 while ( true ) {
@@ -387,6 +389,8 @@ program
387389 if ( err instanceof QueueShutDown ) break ;
388390 throw err ;
389391 }
392+ const pe = pushEvent ;
393+ if ( ! pe ) continue ;
390394 const t = msg . __wireType ?? "" ;
391395 if ( t === "TurnBegin" ) {
392396 const raw = msg . user_input ;
@@ -490,7 +494,7 @@ program
490494 currentCancelController = cancelController ;
491495 const wireFile = app . session . wireFile ? new WireFile ( app . session . wireFile ) : undefined ;
492496 try {
493- await runSoul ( app . soul , input , createShellUILoopFn ( pushEvent ! ) , cancelController , {
497+ await runSoul ( app . soul , input , createShellUILoopFn ( ) , cancelController , {
494498 wireFile,
495499 runtime : app . soul . runtime ,
496500 } ) ;
@@ -588,7 +592,7 @@ program
588592 const cancelController = new AbortController ( ) ;
589593 currentCancelController = cancelController ;
590594 const wireFile = app . session . wireFile ? new WireFile ( app . session . wireFile ) : undefined ;
591- runSoul ( app . soul , currentPrompt , createShellUILoopFn ( pushEvent ! ) , cancelController , {
595+ runSoul ( app . soul , currentPrompt , createShellUILoopFn ( ) , cancelController , {
592596 wireFile,
593597 runtime : app . soul . runtime ,
594598 } ) . catch ( ( err ) => {
0 commit comments