@@ -27,6 +27,7 @@ type MockOpenAiRequestSnapshot = {
2727 body : Record < string , unknown > ;
2828 prompt : string ;
2929 allInputText : string ;
30+ instructions ?: string ;
3031 toolOutput : string ;
3132 model : string ;
3233 imageInputCount : number ;
@@ -181,6 +182,23 @@ function extractAllInputTexts(input: ResponsesInputItem[]) {
181182 return texts . join ( "\n" ) ;
182183}
183184
185+ function extractInstructionsText ( body : Record < string , unknown > ) {
186+ return typeof body . instructions === "string" ? body . instructions . trim ( ) : "" ;
187+ }
188+
189+ function extractAllRequestTexts ( input : ResponsesInputItem [ ] , body : Record < string , unknown > ) {
190+ const texts : string [ ] = [ ] ;
191+ const instructions = extractInstructionsText ( body ) ;
192+ if ( instructions ) {
193+ texts . push ( instructions ) ;
194+ }
195+ const inputText = extractAllInputTexts ( input ) ;
196+ if ( inputText ) {
197+ texts . push ( inputText ) ;
198+ }
199+ return texts . join ( "\n" ) ;
200+ }
201+
184202function countImageInputs ( input : ResponsesInputItem [ ] ) {
185203 let count = 0 ;
186204 for ( const item of input ) {
@@ -320,6 +338,33 @@ function extractOrbitCode(text: string) {
320338 return / \b O R B I T - \d + \b / i. exec ( text ) ?. [ 0 ] ?. toUpperCase ( ) ?? null ;
321339}
322340
341+ function decodeXmlEntities ( text : string ) {
342+ return text
343+ . replaceAll ( "<" , "<" )
344+ . replaceAll ( ">" , ">" )
345+ . replaceAll ( "&" , "&" )
346+ . replaceAll ( """ , '"' )
347+ . replaceAll ( "'" , "'" ) ;
348+ }
349+
350+ function extractActiveMemorySummary ( text : string ) {
351+ const match = / < a c t i v e _ m e m o r y _ p l u g i n > \s * ( [ \s \S ] * ?) \s * < \/ a c t i v e _ m e m o r y _ p l u g i n > / i. exec ( text ) ;
352+ return match ?. [ 1 ] ? decodeXmlEntities ( match [ 1 ] ) . trim ( ) : null ;
353+ }
354+
355+ function isActiveMemorySubagentPrompt ( text : string ) {
356+ return text . includes ( "You are a memory search agent." ) ;
357+ }
358+
359+ function extractSnackPreference ( text : string ) {
360+ const normalized = text . replace ( / \s + / g, " " ) . trim ( ) ;
361+ const match =
362+ / ( l e m o n p e p p e r w i n g s (?: \s + w i t h \s + b l u e c h e e s e ) ? | b l u e c h e e s e (?: \s + w i t h \s + l e m o n p e p p e r w i n g s ) ? ) / i. exec (
363+ normalized ,
364+ ) ;
365+ return match ?. [ 0 ] ?. trim ( ) ?? null ;
366+ }
367+
323368function extractLastCapture ( text : string , pattern : RegExp ) {
324369 let lastMatch : RegExpExecArray | null = null ;
325370 const flags = pattern . flags . includes ( "g" ) ? pattern . flags : `${ pattern . flags } g` ;
@@ -355,7 +400,7 @@ function buildAssistantText(input: ResponsesInputItem[], body: Record<string, un
355400 const toolOutput = extractToolOutput ( input ) ;
356401 const toolJson = parseToolOutputJson ( toolOutput ) ;
357402 const userTexts = extractAllUserTexts ( input ) ;
358- const allInputText = extractAllInputTexts ( input ) ;
403+ const allInputText = extractAllRequestTexts ( input , body ) ;
359404 const rememberedFact = extractRememberedFact ( userTexts ) ;
360405 const model = typeof body . model === "string" ? body . model : "" ;
361406 const memorySnippet =
@@ -369,6 +414,8 @@ function buildAssistantText(input: ResponsesInputItem[], body: Record<string, un
369414 const exactReplyDirective = extractExactReplyDirective ( allInputText ) ;
370415 const exactMarkerDirective = extractExactMarkerDirective ( allInputText ) ;
371416 const imageInputCount = countImageInputs ( input ) ;
417+ const activeMemorySummary = extractActiveMemorySummary ( allInputText ) ;
418+ const snackPreference = extractSnackPreference ( activeMemorySummary ?? memorySnippet ) ;
372419
373420 if ( / w h a t w a s t h e q a c a n a r y c o d e / i. test ( prompt ) && rememberedFact ) {
374421 return `Protocol note: the QA canary code was ${ rememberedFact } .` ;
@@ -400,6 +447,12 @@ function buildAssistantText(input: ResponsesInputItem[], body: Record<string, un
400447 if ( / m e m o r y t o o l s c h e c k / i. test ( prompt ) && orbitCode ) {
401448 return `Protocol note: I checked memory and the project codename is ${ orbitCode } .` ;
402449 }
450+ if ( / s i l e n t s n a c k r e c a l l c h e c k / i. test ( prompt ) && snackPreference ) {
451+ return `Protocol note: you usually want ${ snackPreference } for QA movie night.` ;
452+ }
453+ if ( / s i l e n t s n a c k r e c a l l c h e c k / i. test ( prompt ) ) {
454+ return "Protocol note: I do not have enough context to say what you usually want for QA movie night." ;
455+ }
403456 if ( / t o o l c o n t i n u i t y c h e c k / i. test ( prompt ) && toolOutput ) {
404457 return `Protocol note: model switch handoff confirmed on ${ model || "the requested model" } . QA mission from QA_KICKOFF_TASK.md still applies: understand this OpenClaw repo from source + docs before acting.` ;
405458 }
@@ -531,7 +584,7 @@ async function buildResponsesPayload(body: Record<string, unknown>) {
531584 const prompt = extractLastUserText ( input ) ;
532585 const toolOutput = extractToolOutput ( input ) ;
533586 const toolJson = parseToolOutputJson ( toolOutput ) ;
534- const allInputText = extractAllInputTexts ( input ) ;
587+ const allInputText = extractAllRequestTexts ( input , body ) ;
535588 const isGroupChat = allInputText . includes ( '"is_group_chat": true' ) ;
536589 const isBaselineUnmentionedChannelChatter = / \b n o b o t p i n g h e r e \b / i. test ( prompt ) ;
537590 if ( isHeartbeatPrompt ( prompt ) ) {
@@ -591,6 +644,48 @@ async function buildResponsesPayload(body: Record<string, unknown>) {
591644 } ) ;
592645 }
593646 }
647+ if (
648+ isActiveMemorySubagentPrompt ( allInputText ) &&
649+ / s i l e n t s n a c k r e c a l l c h e c k / i. test ( allInputText )
650+ ) {
651+ if ( ! toolOutput ) {
652+ return buildToolCallEventsWithArgs ( "memory_search" , {
653+ query : "QA movie night snack lemon pepper wings blue cheese" ,
654+ maxResults : 3 ,
655+ } ) ;
656+ }
657+ const results = Array . isArray ( toolJson ?. results )
658+ ? ( toolJson . results as Array < Record < string , unknown > > )
659+ : [ ] ;
660+ const first = results [ 0 ] ;
661+ if (
662+ typeof first ?. path === "string" &&
663+ ( typeof first . startLine === "number" || typeof first . endLine === "number" )
664+ ) {
665+ const from =
666+ typeof first . startLine === "number"
667+ ? Math . max ( 1 , first . startLine )
668+ : typeof first . endLine === "number"
669+ ? Math . max ( 1 , first . endLine )
670+ : 1 ;
671+ return buildToolCallEventsWithArgs ( "memory_get" , {
672+ path : first . path ,
673+ from,
674+ lines : 4 ,
675+ } ) ;
676+ }
677+ const memorySnippet =
678+ typeof toolJson ?. text === "string"
679+ ? toolJson . text
680+ : Array . isArray ( toolJson ?. results )
681+ ? JSON . stringify ( toolJson . results )
682+ : toolOutput ;
683+ const snackPreference = extractSnackPreference ( memorySnippet ) ;
684+ if ( snackPreference ) {
685+ return buildAssistantEvents ( `User usually wants ${ snackPreference } for QA movie night.` ) ;
686+ }
687+ return buildAssistantEvents ( "NONE" ) ;
688+ }
594689 if ( / s e s s i o n m e m o r y r a n k i n g c h e c k / i. test ( prompt ) ) {
595690 if ( ! toolOutput ) {
596691 return buildToolCallEventsWithArgs ( "memory_search" , {
@@ -798,7 +893,8 @@ export async function startQaMockOpenAiServer(params?: { host?: string; port?: n
798893 raw,
799894 body,
800895 prompt : extractLastUserText ( input ) ,
801- allInputText : extractAllInputTexts ( input ) ,
896+ allInputText : extractAllRequestTexts ( input , body ) ,
897+ instructions : extractInstructionsText ( body ) || undefined ,
802898 toolOutput : extractToolOutput ( input ) ,
803899 model : typeof body . model === "string" ? body . model : "" ,
804900 imageInputCount : countImageInputs ( input ) ,
0 commit comments