11import { MultiBar , SingleBar , Presets } from 'cli-progress' ;
22import chalk from 'chalk' ;
3- import { RootPromptDefinition } from '../shared-interfaces.js' ;
3+ import { AssessmentResult , RootPromptDefinition } from '../shared-interfaces.js' ;
44import { ProgressLogger , ProgressType , progressTypeToIcon } from './progress-logger.js' ;
55import { redX } from '../reporting/format.js' ;
66
@@ -13,6 +13,8 @@ export class DynamicProgressLogger implements ProgressLogger {
1313 private pendingBars = new Map < RootPromptDefinition , SingleBar > ( ) ;
1414 private spinnerFrames = [ '⠋' , '⠙' , '⠹' , '⠸' , '⠼' , '⠴' , '⠦' , '⠧' , '⠇' , '⠏' ] ;
1515 private currentSpinnerFrame = 0 ;
16+ private completedEvals = 0 ;
17+ private totalScore = 0 ;
1618 private spinnerInterval : ReturnType < typeof setInterval > | undefined ;
1719 private errors : {
1820 prompt : RootPromptDefinition ;
@@ -46,10 +48,17 @@ export class DynamicProgressLogger implements ProgressLogger {
4648 ) ;
4749
4850 // Bar that tracks how many prompts are completed in total.
49- this . totalBar = this . wrapper . create ( total , 0 , undefined , {
50- format : '{bar} {spinner} {value}/{total} prompts completed' ,
51- barsize : PREFIX_WIDTH ,
52- } ) ;
51+ this . totalBar = this . wrapper . create (
52+ total ,
53+ 0 ,
54+ {
55+ additionalInfo : '' ,
56+ } ,
57+ {
58+ format : '{bar} {spinner} {value}/{total} prompts completed{additionalInfo}' ,
59+ barsize : PREFIX_WIDTH ,
60+ } ,
61+ ) ;
5362
5463 // Interval to update the spinner.
5564 this . spinnerInterval = setInterval ( ( ) => {
@@ -74,6 +83,7 @@ export class DynamicProgressLogger implements ProgressLogger {
7483 this . wrapper ?. stop ( ) ;
7584 this . pendingBars . clear ( ) ;
7685 this . wrapper = this . totalBar = this . spinnerInterval = undefined ;
86+ this . completedEvals = this . totalScore = 0 ;
7787
7888 for ( const error of this . errors ) {
7989 let message = `${ redX ( ) } [${ error . prompt . name } ] ${ error . message } ` ;
@@ -91,17 +101,6 @@ export class DynamicProgressLogger implements ProgressLogger {
91101
92102 let bar = this . pendingBars . get ( prompt ) ;
93103
94- // Drop the bar from the screen if it's complete.
95- if ( type === 'done' ) {
96- this . pendingBars . delete ( prompt ) ;
97-
98- if ( bar ) {
99- this . totalBar . increment ( ) ;
100- this . wrapper . remove ( bar ) ;
101- }
102- return ;
103- }
104-
105104 // Capture errors for static printing once the dynamic progress is hidden.
106105 if ( type === 'error' ) {
107106 this . errors . push ( { prompt, message, details} ) ;
@@ -117,14 +116,36 @@ export class DynamicProgressLogger implements ProgressLogger {
117116 if ( bar ) {
118117 bar . update ( 0 , payload ) ;
119118 } else {
120- const bar = this . wrapper . create ( 1 , 0 , payload ) ;
119+ bar = this . wrapper . create ( 1 , 0 , payload ) ;
121120 this . pendingBars . set ( prompt , bar ) ;
122121 }
123122 }
124123
124+ evalFinished ( prompt : RootPromptDefinition , results : AssessmentResult [ ] ) : void {
125+ const bar = this . pendingBars . get ( prompt ) ;
126+ this . pendingBars . delete ( prompt ) ;
127+
128+ for ( const result of results ) {
129+ this . completedEvals ++ ;
130+ this . totalScore += ( result . score . totalPoints / result . score . maxOverallPoints ) * 100 ;
131+ }
132+
133+ if ( this . completedEvals > 0 ) {
134+ this . totalBar ?. increment ( 1 , {
135+ additionalInfo : `, ${ Math . round ( this . totalScore / this . completedEvals ) } % score on average` ,
136+ } ) ;
137+ } else {
138+ this . totalBar ?. increment ( ) ;
139+ }
140+
141+ // Drop the bar from the screen if it's complete.
142+ if ( bar ) {
143+ this . wrapper ?. remove ( bar ) ;
144+ }
145+ }
146+
125147 private getColorFunction ( type : ProgressType ) : ( value : string ) => string {
126148 switch ( type ) {
127- case 'done' :
128149 case 'success' :
129150 case 'serve-testing' :
130151 case 'build' :
0 commit comments