File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed
services/minecraft/src/cognitive Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -161,4 +161,17 @@ inv;
161161
162162 expect ( enqueueSpy ) . not . toHaveBeenCalled ( )
163163 } )
164+
165+ it ( 'refreshes reflex context before debug perception injection' , async ( ) => {
166+ const deps : any = createDeps ( 'await skip()' )
167+ deps . reflexManager . refreshFromBotState = vi . fn ( )
168+ const brain : any = new Brain ( deps )
169+ brain . runtimeMineflayer = { } as any
170+ brain . enqueueEvent = vi . fn ( async ( ) => undefined )
171+
172+ await brain . injectDebugEvent ( createPerceptionEvent ( ) )
173+
174+ expect ( deps . reflexManager . refreshFromBotState ) . toHaveBeenCalledTimes ( 1 )
175+ expect ( brain . enqueueEvent ) . toHaveBeenCalledTimes ( 1 )
176+ } )
164177} )
Original file line number Diff line number Diff line change @@ -326,6 +326,19 @@ export class Brain {
326326 if ( ! this . runtimeMineflayer ) {
327327 throw new Error ( 'Brain runtime is not initialized yet' )
328328 }
329+
330+ // Debug-injected perception events bypass the normal Reflex signal path.
331+ // Refresh context from live bot state first so conscious prompts don't use
332+ // stale/default environment placeholders.
333+ if ( event . type === 'perception' ) {
334+ try {
335+ this . deps . reflexManager . refreshFromBotState ( )
336+ }
337+ catch ( err ) {
338+ this . deps . logger . withError ( err as Error ) . warn ( 'Brain: Failed to refresh reflex context for debug event' )
339+ }
340+ }
341+
329342 await this . enqueueEvent ( this . runtimeMineflayer , event )
330343 }
331344
Original file line number Diff line number Diff line change @@ -111,6 +111,14 @@ export class ReflexManager {
111111 this . emitReflexState ( )
112112 }
113113
114+ public refreshFromBotState ( ) : void {
115+ if ( ! this . bot )
116+ return
117+
118+ this . runtime . tick ( this . bot , 0 , this . deps . perception )
119+ this . emitReflexState ( )
120+ }
121+
114122 private onSignal ( event : TracedEvent < PerceptionSignal > ) : void {
115123 const bot = this . bot
116124 if ( ! bot )
You can’t perform that action at this time.
0 commit comments