@@ -16,20 +16,24 @@ export interface JudgeStatusOptions {
1616 language ?: Language ;
1717 interactive ?: boolean ;
1818 onStream ?: StreamCallback ;
19- onJudgeStage ?: ( entry : {
20- stage : 1 | 2 | 3 ;
21- method : 'structured_output' | 'phase3_tag' | 'ai_judge' ;
22- status : 'done' | 'error' | 'skipped' ;
23- instruction : string ;
24- response : string ;
25- providerUsage ?: ProviderUsageSnapshot ;
26- } ) => void ;
19+ onJudgeStage ?: ( entry : JudgeStageLogEntry ) => void ;
2720 onStructuredPromptResolved ?: ( promptParts : {
2821 systemPrompt : string ;
2922 userInstruction : string ;
3023 } ) => void ;
3124}
3225
26+ export interface JudgeStageLogEntry {
27+ stage : 1 | 2 | 3 ;
28+ method : 'structured_output' | 'phase3_tag' | 'ai_judge' ;
29+ status : 'done' | 'error' | 'skipped' ;
30+ instruction : string ;
31+ response : string ;
32+ providerUsage ?: ProviderUsageSnapshot ;
33+ }
34+
35+ type JudgeResponseEntry = Pick < JudgeStageLogEntry , 'instruction' | 'status' | 'response' | 'providerUsage' > ;
36+
3337export interface TagJudgeRunOptions {
3438 cwd : string ;
3539 provider ?: ProviderType ;
@@ -133,6 +137,28 @@ export async function evaluateCondition(
133137 return detectJudgeIndex ( response . content ) ;
134138}
135139
140+ export function createJudgeStageRecorder ( ) : {
141+ capture ( entry : JudgeResponseEntry ) : void ;
142+ stage ( entry : Pick < JudgeStageLogEntry , 'stage' | 'method' > ) : JudgeStageLogEntry ;
143+ } {
144+ let latest : JudgeResponseEntry = {
145+ status : 'skipped' ,
146+ instruction : '' ,
147+ response : '' ,
148+ } ;
149+ return {
150+ capture ( entry ) : void {
151+ latest = entry ;
152+ } ,
153+ stage ( entry ) : JudgeStageLogEntry {
154+ return {
155+ ...entry ,
156+ ...latest ,
157+ } ;
158+ } ,
159+ } ;
160+ }
161+
136162export async function judgeStatus (
137163 structuredInstruction : string ,
138164 tagInstruction : string ,
@@ -207,32 +233,20 @@ export async function judgeStatus(
207233 const conditions = buildJudgeConditions ( rules , interactiveEnabled ) ;
208234
209235 if ( conditions . length > 0 ) {
210- let stage3Status : 'done' | 'error' | 'skipped' = 'skipped' ;
211- let stage3Instruction = '' ;
212- let stage3Response = '' ;
213- let stage3ProviderUsage : ProviderUsageSnapshot | undefined ;
236+ const stage3 = createJudgeStageRecorder ( ) ;
214237 const normalizedConditions = conditions . map ( ( c , pos ) => ( { index : pos , text : c . text } ) ) ;
215238 const fallbackPosition = await evaluateCondition ( structuredInstruction , normalizedConditions , {
216239 cwd : options . cwd ,
217240 provider : options . provider ,
218241 resolvedProvider : options . resolvedProvider ,
219242 resolvedModel : options . resolvedModel ,
220- onJudgeResponse : ( entry ) => {
221- stage3Status = entry . status ;
222- stage3Instruction = entry . instruction ;
223- stage3Response = entry . response ;
224- stage3ProviderUsage = entry . providerUsage ;
225- } ,
243+ onJudgeResponse : stage3 . capture ,
226244 } ) ;
227245
228- options . onJudgeStage ?.( {
246+ options . onJudgeStage ?.( stage3 . stage ( {
229247 stage : 3 ,
230248 method : 'ai_judge' ,
231- status : stage3Status ,
232- instruction : stage3Instruction ,
233- response : stage3Response ,
234- providerUsage : stage3ProviderUsage ,
235- } ) ;
249+ } ) ) ;
236250
237251 if ( fallbackPosition >= 0 && fallbackPosition < conditions . length ) {
238252 const originalIndex = conditions [ fallbackPosition ] ?. index ;
0 commit comments