1- export interface ToolResultTracker {
1+ export interface ToolTracker {
22 seenToolResultIds : Set < string >
33 toolResultCount : number
44}
55
6- export function createToolResultTracker ( ) : ToolResultTracker {
6+ export function createToolTracker ( ) : ToolTracker {
77 return {
88 seenToolResultIds : new Set ( ) ,
99 toolResultCount : 0
1010 }
1111}
1212
13- function countNewToolResults ( messages : any [ ] , tracker : ToolResultTracker ) : number {
13+ function countToolResults ( messages : any [ ] , tracker : ToolTracker ) : number {
1414 let newCount = 0
1515
1616 for ( const m of messages ) {
@@ -41,21 +41,21 @@ function countNewToolResults(messages: any[], tracker: ToolResultTracker): numbe
4141 * Counts new tool results and injects nudge instruction every 5th tool result.
4242 * Returns true if injection happened.
4343 */
44- export function maybeInjectToolResultNudge (
44+ export function injectNudge (
4545 messages : any [ ] ,
46- tracker : ToolResultTracker ,
46+ tracker : ToolTracker ,
4747 nudgeText : string
4848) : boolean {
4949 const prevCount = tracker . toolResultCount
50- const newCount = countNewToolResults ( messages , tracker )
50+ const newCount = countToolResults ( messages , tracker )
5151
5252 if ( newCount > 0 ) {
5353 // Check if we crossed a multiple of 5
5454 const prevBucket = Math . floor ( prevCount / 5 )
5555 const newBucket = Math . floor ( tracker . toolResultCount / 5 )
5656 if ( newBucket > prevBucket ) {
5757 // Inject at the END of messages so it's in immediate context
58- return injectNudgeAtEnd ( messages , nudgeText )
58+ return appendNudge ( messages , nudgeText )
5959 }
6060 }
6161 return false
@@ -82,10 +82,10 @@ export function isIgnoredUserMessage(msg: any): boolean {
8282}
8383
8484/**
85- * Injects a nudge message at the END of the messages array as a new user message.
85+ * Appends a nudge message at the END of the messages array as a new user message.
8686 * This ensures it's in the model's immediate context, not buried in old messages.
8787 */
88- export function injectNudgeAtEnd ( messages : any [ ] , nudgeText : string ) : boolean {
88+ function appendNudge ( messages : any [ ] , nudgeText : string ) : boolean {
8989 messages . push ( {
9090 role : 'user' ,
9191 content : nudgeText ,
@@ -94,7 +94,7 @@ export function injectNudgeAtEnd(messages: any[], nudgeText: string): boolean {
9494 return true
9595}
9696
97- export function injectSynthInstruction ( messages : any [ ] , instruction : string ) : boolean {
97+ export function injectSynth ( messages : any [ ] , instruction : string ) : boolean {
9898 // Find the last user message that is not ignored
9999 for ( let i = messages . length - 1 ; i >= 0 ; i -- ) {
100100 const msg = messages [ i ]
0 commit comments