@@ -25,21 +25,10 @@ const outputFile = getArg('--output')
2525const preset = getArg ( '--preset' )
2626const instructions = getArg ( '--instructions' )
2727
28- // List of models to try in order.
29- // The first model in the list is the primary model, and the rest are fallbacks.
30-
31- // UPDATED: Aligned with latest model recommendations (Q3 2025+)
32- // 1. gemini-2.5-flash: Next-gen standard workhorse.
33- // 2. gemini-2.5-flash-lite: Next-gen ultra-low-cost model.
34- // 3. gemini-2.0-flash: Previous generation flash model.
35- // 4. gemini-2.0-flash-lite: Previous generation ultra-low-cost model.
36- // 5. gemini-2.5-pro: Expensive, high-intelligence fallback.
37-
3828const defaultFallbacks = [
29+ 'gemini-3.1-flash-lite-preview' ,
3930 'gemini-2.5-flash' ,
4031 'gemini-2.5-flash-lite' ,
41- 'gemini-2.0-flash' ,
42- 'gemini-2.0-flash-lite' ,
4332 'gemini-2.5-pro' ,
4433]
4534
@@ -242,6 +231,7 @@ export interface ReviewContext {
242231 testFiles ?: string | undefined
243232 failedChecks : FailedCheck [ ]
244233 slopAnalysis ?: string
234+ thoughtSignature ?: string
245235}
246236
247237async function main ( ) {
@@ -320,27 +310,45 @@ async function main() {
320310 }
321311}
322312
313+ type ExtendedGenerateContentRequest = GenerateContentRequest & { thought_signature ?: string } ;
314+
323315export async function generateContentWithFallback ( {
324316 genAI,
325317 prompt,
326318 config,
319+ thoughtSignature,
327320} : {
328321 genAI : GoogleGenerativeAI
329322 prompt : string
330323 config ?: Omit < GenerateContentRequest , 'contents' >
331- } ) {
324+ thoughtSignature ?: string
325+ } ) : Promise < { text : string ; thoughtSignature ?: string } > {
332326 let lastError : Error | null = null
333327
334328 for ( const modelName of MODEL_FALLBACKS ) {
335- console . log ( `Attempting to use model: ${ modelName } ...` )
336329 try {
337330 const model = genAI . getGenerativeModel ( { model : modelName } )
338- const result = await model . generateContent ( {
331+ const request : ExtendedGenerateContentRequest = {
339332 contents : [ { role : 'user' , parts : [ { text : prompt } ] } ] ,
340333 ...config ,
341- } )
334+ ...( thoughtSignature && { thought_signature : thoughtSignature } )
335+ }
336+
337+ const result = await model . generateContent ( request )
342338 console . log ( `Successfully generated content using ${ modelName } .` )
343- return result . response . text ( )
339+
340+ const text = result . response . text ( )
341+
342+ // Capture thought signature from the response if present
343+ const capturedSignature = (
344+ result . response . candidates ?. [ 0 ] as NonNullable <
345+ typeof result . response . candidates
346+ > [ number ] & {
347+ thought_signature ?: string
348+ }
349+ ) ?. thought_signature
350+
351+ return { text, thoughtSignature : capturedSignature }
344352 } catch ( error : unknown ) {
345353 if ( error instanceof Error ) {
346354 lastError = error
@@ -418,7 +426,7 @@ ${contextContent}
418426--- Task ---
419427${ task }
420428`
421- const text = await generateContentWithFallback ( { genAI, prompt } )
429+ const { text } = await generateContentWithFallback ( { genAI, prompt } )
422430 await writeOutput ( text , outputFile )
423431}
424432
@@ -552,6 +560,7 @@ function getReviewContextFromEnv(): ReviewContext {
552560 testFiles : process . env . TEST_FILES ,
553561 failedChecks,
554562 slopAnalysis : process . env . SLOP_ANALYSIS || 'Not available.' ,
563+ thoughtSignature : process . env . GEMINI_THOUGHT_SIGNATURE ,
555564 }
556565}
557566
@@ -731,9 +740,10 @@ async function runReviewPreset(
731740 contextContent ,
732741 instructions
733742 )
734- const text = await generateContentWithFallback ( {
743+ const { text, thoughtSignature } = await generateContentWithFallback ( {
735744 genAI,
736745 prompt,
746+ thoughtSignature : context . thoughtSignature ,
737747 config : {
738748 generationConfig : {
739749 maxOutputTokens : 4096 ,
@@ -830,8 +840,10 @@ async function runReviewPreset(
830840 verdict ?: string
831841 labels ?: string [ ]
832842 prContext ?: unknown
843+ thoughtSignature ?: string
833844 }
834845 reviewData . prContext = prContext
846+ reviewData . thoughtSignature ??= thoughtSignature
835847 // It's valid JSON, but we should still check if the content is meaningful.
836848 if (
837849 ! reviewData . reviewComment ||
0 commit comments