@@ -181,14 +181,43 @@ function validateInput(input) {
181181 // Check for tool execution
182182 if ( message . type === "say" && message . say === "api_req_started" && message . text ) {
183183 console . log ( "API request started:" , message . text . substring ( 0 , 200 ) )
184+
185+ // More robust detection of apply_diff tool
184186 try {
185- const requestData = JSON . parse ( message . text )
186- if ( requestData . request && requestData . request . includes ( "apply_diff" ) ) {
187+ const text = message . text
188+ if (
189+ text . includes ( "apply_diff" ) ||
190+ text . includes ( '"tool":"apply_diff"' ) ||
191+ text . includes ( "applyDiff" ) ||
192+ text . includes ( "appliedDiff" )
193+ ) {
187194 applyDiffExecuted = true
188195 console . log ( "apply_diff tool executed!" )
196+ } else {
197+ // Also try to parse as JSON if it doesn't match string patterns
198+ let requestData : { request ?: string } | null = null
199+ try {
200+ requestData = JSON . parse ( text )
201+ } catch {
202+ // Try extracting JSON from the text
203+ const jsonMatch = text . match ( / \{ [ \s \S ] * \} / )
204+ if ( jsonMatch ) {
205+ requestData = JSON . parse ( jsonMatch [ 0 ] )
206+ }
207+ }
208+
209+ if (
210+ requestData &&
211+ requestData . request &&
212+ ( requestData . request . includes ( "apply_diff" ) || requestData . request . includes ( "appliedDiff" ) )
213+ ) {
214+ applyDiffExecuted = true
215+ console . log ( "apply_diff tool executed (parsed from JSON)!" )
216+ }
189217 }
190218 } catch ( e ) {
191219 console . log ( "Failed to parse api_req_started message:" , e )
220+ console . log ( "Raw text:" , message . text . substring ( 0 , 500 ) )
192221 }
193222 }
194223 }
@@ -294,14 +323,43 @@ ${testFile.content}\nAssume the file exists and you can modify it directly.`,
294323 // Check for tool execution
295324 if ( message . type === "say" && message . say === "api_req_started" && message . text ) {
296325 console . log ( "API request started:" , message . text . substring ( 0 , 200 ) )
326+
327+ // More robust detection of apply_diff tool
297328 try {
298- const requestData = JSON . parse ( message . text )
299- if ( requestData . request && requestData . request . includes ( "apply_diff" ) ) {
329+ const text = message . text
330+ if (
331+ text . includes ( "apply_diff" ) ||
332+ text . includes ( '"tool":"apply_diff"' ) ||
333+ text . includes ( "applyDiff" ) ||
334+ text . includes ( "appliedDiff" )
335+ ) {
300336 applyDiffExecuted = true
301337 console . log ( "apply_diff tool executed!" )
338+ } else {
339+ // Also try to parse as JSON if it doesn't match string patterns
340+ let requestData : { request ?: string } | null = null
341+ try {
342+ requestData = JSON . parse ( text )
343+ } catch {
344+ // Try extracting JSON from the text
345+ const jsonMatch = text . match ( / \{ [ \s \S ] * \} / )
346+ if ( jsonMatch ) {
347+ requestData = JSON . parse ( jsonMatch [ 0 ] )
348+ }
349+ }
350+
351+ if (
352+ requestData &&
353+ requestData . request &&
354+ ( requestData . request . includes ( "apply_diff" ) || requestData . request . includes ( "appliedDiff" ) )
355+ ) {
356+ applyDiffExecuted = true
357+ console . log ( "apply_diff tool executed (parsed from JSON)!" )
358+ }
302359 }
303360 } catch ( e ) {
304361 console . log ( "Failed to parse api_req_started message:" , e )
362+ console . log ( "Raw text:" , message . text . substring ( 0 , 500 ) )
305363 }
306364 }
307365 }
@@ -413,14 +471,43 @@ function keepThis() {
413471 // Check for tool execution
414472 if ( message . type === "say" && message . say === "api_req_started" && message . text ) {
415473 console . log ( "API request started:" , message . text . substring ( 0 , 200 ) )
474+
475+ // More robust detection of apply_diff tool
416476 try {
417- const requestData = JSON . parse ( message . text )
418- if ( requestData . request && requestData . request . includes ( "apply_diff" ) ) {
477+ const text = message . text
478+ if (
479+ text . includes ( "apply_diff" ) ||
480+ text . includes ( '"tool":"apply_diff"' ) ||
481+ text . includes ( "applyDiff" ) ||
482+ text . includes ( "appliedDiff" )
483+ ) {
419484 applyDiffExecuted = true
420485 console . log ( "apply_diff tool executed!" )
486+ } else {
487+ // Also try to parse as JSON if it doesn't match string patterns
488+ let requestData : { request ?: string } | null = null
489+ try {
490+ requestData = JSON . parse ( text )
491+ } catch {
492+ // Try extracting JSON from the text
493+ const jsonMatch = text . match ( / \{ [ \s \S ] * \} / )
494+ if ( jsonMatch ) {
495+ requestData = JSON . parse ( jsonMatch [ 0 ] )
496+ }
497+ }
498+
499+ if (
500+ requestData &&
501+ requestData . request &&
502+ ( requestData . request . includes ( "apply_diff" ) || requestData . request . includes ( "appliedDiff" ) )
503+ ) {
504+ applyDiffExecuted = true
505+ console . log ( "apply_diff tool executed (parsed from JSON)!" )
506+ }
421507 }
422508 } catch ( e ) {
423509 console . log ( "Failed to parse api_req_started message:" , e )
510+ console . log ( "Raw text:" , message . text . substring ( 0 , 500 ) )
424511 }
425512 }
426513 }
@@ -521,14 +608,43 @@ ${testFile.content}\nAssume the file exists and you can modify it directly.`,
521608 // Check for tool execution attempt
522609 if ( message . type === "say" && message . say === "api_req_started" && message . text ) {
523610 console . log ( "API request started:" , message . text . substring ( 0 , 200 ) )
611+
612+ // More robust detection of apply_diff tool
524613 try {
525- const requestData = JSON . parse ( message . text )
526- if ( requestData . request && requestData . request . includes ( "apply_diff" ) ) {
614+ const text = message . text
615+ if (
616+ text . includes ( "apply_diff" ) ||
617+ text . includes ( '"tool":"apply_diff"' ) ||
618+ text . includes ( "applyDiff" ) ||
619+ text . includes ( "appliedDiff" )
620+ ) {
527621 applyDiffAttempted = true
528622 console . log ( "apply_diff tool attempted!" )
623+ } else {
624+ // Also try to parse as JSON if it doesn't match string patterns
625+ let requestData : { request ?: string } | null = null
626+ try {
627+ requestData = JSON . parse ( text )
628+ } catch {
629+ // Try extracting JSON from the text
630+ const jsonMatch = text . match ( / \{ [ \s \S ] * \} / )
631+ if ( jsonMatch ) {
632+ requestData = JSON . parse ( jsonMatch [ 0 ] )
633+ }
634+ }
635+
636+ if (
637+ requestData &&
638+ requestData . request &&
639+ ( requestData . request . includes ( "apply_diff" ) || requestData . request . includes ( "appliedDiff" ) )
640+ ) {
641+ applyDiffAttempted = true
642+ console . log ( "apply_diff tool attempted (parsed from JSON)!" )
643+ }
529644 }
530645 } catch ( e ) {
531646 console . log ( "Failed to parse api_req_started message:" , e )
647+ console . log ( "Raw text:" , message . text . substring ( 0 , 500 ) )
532648 }
533649 }
534650 }
@@ -651,15 +767,45 @@ function checkInput(input) {
651767 // Check for tool execution
652768 if ( message . type === "say" && message . say === "api_req_started" && message . text ) {
653769 console . log ( "API request started:" , message . text . substring ( 0 , 200 ) )
770+
771+ // More robust detection of apply_diff tool
654772 try {
655- const requestData = JSON . parse ( message . text )
656- if ( requestData . request && requestData . request . includes ( "apply_diff" ) ) {
773+ const text = message . text
774+ if (
775+ text . includes ( "apply_diff" ) ||
776+ text . includes ( '"tool":"apply_diff"' ) ||
777+ text . includes ( "applyDiff" ) ||
778+ text . includes ( "appliedDiff" )
779+ ) {
657780 applyDiffExecuted = true
658781 applyDiffCount ++
659782 console . log ( `apply_diff tool executed! (count: ${ applyDiffCount } )` )
783+ } else {
784+ // Also try to parse as JSON if it doesn't match string patterns
785+ let requestData : { request ?: string } | null = null
786+ try {
787+ requestData = JSON . parse ( text )
788+ } catch {
789+ // Try extracting JSON from the text
790+ const jsonMatch = text . match ( / \{ [ \s \S ] * \} / )
791+ if ( jsonMatch ) {
792+ requestData = JSON . parse ( jsonMatch [ 0 ] )
793+ }
794+ }
795+
796+ if (
797+ requestData &&
798+ requestData . request &&
799+ ( requestData . request . includes ( "apply_diff" ) || requestData . request . includes ( "appliedDiff" ) )
800+ ) {
801+ applyDiffExecuted = true
802+ applyDiffCount ++
803+ console . log ( `apply_diff tool executed (parsed from JSON)! (count: ${ applyDiffCount } )` )
804+ }
660805 }
661806 } catch ( e ) {
662807 console . log ( "Failed to parse api_req_started message:" , e )
808+ console . log ( "Raw text:" , message . text . substring ( 0 , 500 ) )
663809 }
664810 }
665811 }
0 commit comments