1
1
import { MultiBar , SingleBar , Presets } from 'cli-progress' ;
2
2
import chalk from 'chalk' ;
3
- import { RootPromptDefinition } from '../shared-interfaces.js' ;
3
+ import { AssessmentResult , RootPromptDefinition } from '../shared-interfaces.js' ;
4
4
import { ProgressLogger , ProgressType , progressTypeToIcon } from './progress-logger.js' ;
5
5
import { redX } from '../reporting/format.js' ;
6
6
@@ -13,6 +13,8 @@ export class DynamicProgressLogger implements ProgressLogger {
13
13
private pendingBars = new Map < RootPromptDefinition , SingleBar > ( ) ;
14
14
private spinnerFrames = [ '⠋' , '⠙' , '⠹' , '⠸' , '⠼' , '⠴' , '⠦' , '⠧' , '⠇' , '⠏' ] ;
15
15
private currentSpinnerFrame = 0 ;
16
+ private completedEvals = 0 ;
17
+ private totalScore = 0 ;
16
18
private spinnerInterval : ReturnType < typeof setInterval > | undefined ;
17
19
private errors : {
18
20
prompt : RootPromptDefinition ;
@@ -46,10 +48,17 @@ export class DynamicProgressLogger implements ProgressLogger {
46
48
) ;
47
49
48
50
// 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
+ ) ;
53
62
54
63
// Interval to update the spinner.
55
64
this . spinnerInterval = setInterval ( ( ) => {
@@ -74,6 +83,7 @@ export class DynamicProgressLogger implements ProgressLogger {
74
83
this . wrapper ?. stop ( ) ;
75
84
this . pendingBars . clear ( ) ;
76
85
this . wrapper = this . totalBar = this . spinnerInterval = undefined ;
86
+ this . completedEvals = this . totalScore = 0 ;
77
87
78
88
for ( const error of this . errors ) {
79
89
let message = `${ redX ( ) } [${ error . prompt . name } ] ${ error . message } ` ;
@@ -91,17 +101,6 @@ export class DynamicProgressLogger implements ProgressLogger {
91
101
92
102
let bar = this . pendingBars . get ( prompt ) ;
93
103
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
-
105
104
// Capture errors for static printing once the dynamic progress is hidden.
106
105
if ( type === 'error' ) {
107
106
this . errors . push ( { prompt, message, details} ) ;
@@ -117,14 +116,36 @@ export class DynamicProgressLogger implements ProgressLogger {
117
116
if ( bar ) {
118
117
bar . update ( 0 , payload ) ;
119
118
} else {
120
- const bar = this . wrapper . create ( 1 , 0 , payload ) ;
119
+ bar = this . wrapper . create ( 1 , 0 , payload ) ;
121
120
this . pendingBars . set ( prompt , bar ) ;
122
121
}
123
122
}
124
123
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
+
125
147
private getColorFunction ( type : ProgressType ) : ( value : string ) => string {
126
148
switch ( type ) {
127
- case 'done' :
128
149
case 'success' :
129
150
case 'serve-testing' :
130
151
case 'build' :
0 commit comments