@@ -85,6 +85,7 @@ export class Brain {
8585 private isProcessing = false
8686 private currentCancellationToken : CancellationToken | undefined
8787 private lastContextView : string | undefined
88+ private lastReasoning : string | undefined // HACK: Store previous reasoning token for continuity
8889
8990 constructor ( private readonly deps : BrainDeps ) {
9091 this . debugService = DebugService . getInstance ( )
@@ -198,6 +199,7 @@ export class Brain {
198199 // 3. Call Neuri (Stateful) with retry logic
199200 const maxAttempts = 3
200201 let result : string | null = null
202+ let capturedReasoning : string | undefined // HACK: Capture reasoning but don't save until success
201203
202204 for ( let attempt = 1 ; attempt <= maxAttempts ; attempt ++ ) {
203205 try {
@@ -228,6 +230,9 @@ export class Brain {
228230 const content = message ?. content
229231 const reasoning = message ?. reasoning_content || message ?. reasoning
230232
233+ // HACK: Capture reasoning but don't save yet (wait for successful parsing)
234+ capturedReasoning = reasoning
235+
231236 if ( ! content ) throw new Error ( 'No content from LLM' )
232237
233238 this . debugService . traceLLM ( {
@@ -272,6 +277,11 @@ export class Brain {
272277 const parsed = this . parseResponse ( result )
273278 const action = parsed . action
274279
280+ // HACK: Only store reasoning after successful LLM call and valid JSON parsing
281+ if ( capturedReasoning ) {
282+ this . lastReasoning = capturedReasoning
283+ }
284+
275285 if ( action . tool === 'skip' ) {
276286 this . deps . logger . log ( 'INFO' , 'Brain: Skipping turn (observing)' )
277287 return
@@ -315,6 +325,11 @@ export class Brain {
315325 private buildUserMessage ( event : BotEvent , contextView : string ) : string {
316326 const parts : string [ ] = [ ]
317327
328+ // HACK: Inject previous reasoning token into user message for continuity
329+ if ( this . lastReasoning ) {
330+ parts . push ( `[PREVIOUS REASONING] ${ this . lastReasoning } ` )
331+ }
332+
318333 // 1. Event Content
319334 if ( event . type === 'perception' ) {
320335 const signal = event . payload as PerceptionSignal
0 commit comments