@@ -29,78 +29,76 @@ const DIMENSIONS = [
2929
3030let currentJudge : LayoutJudge | undefined
3131
32- export const layoutQualityKind : EvaluationKind <
33- LayoutQualityOutput ,
34- undefined
35- > = {
36- id : 'layout-quality' ,
37- description :
38- 'Evaluates FormSpec layout quality using LLM-as-judge against a civic tech best practices rubric' ,
39-
40- async score ( output : LayoutQualityOutput ) : Promise < CaseMetrics > {
41- if ( ! currentJudge ) {
42- throw new Error (
43- 'layoutQualityKind: judge not set. Call setLayoutJudge() before scoring.' ,
44- )
45- }
46-
47- const response = await currentJudge . judge ( output . spec , output . formSpec )
48-
49- const metrics : Record < string , number > = { }
50- let total = 0
51- let count = 0
52-
53- for ( const dim of DIMENSIONS ) {
54- const entry = response . scores [ dim ]
55- if ( entry ) {
56- const normalized = ( entry . score - 1 ) / 4 // 1-5 → 0-1
57- metrics [ dim ] = normalized
58- total += normalized
59- count ++
32+ export const layoutQualityKind : EvaluationKind < LayoutQualityOutput , undefined > =
33+ {
34+ id : 'layout-quality' ,
35+ description :
36+ 'Evaluates FormSpec layout quality using LLM-as-judge against a civic tech best practices rubric' ,
37+
38+ async score ( output : LayoutQualityOutput ) : Promise < CaseMetrics > {
39+ if ( ! currentJudge ) {
40+ throw new Error (
41+ 'layoutQualityKind: judge not set. Call setLayoutJudge() before scoring.' ,
42+ )
6043 }
61- }
62-
63- metrics . overall = count > 0 ? total / count : 0
64-
65- return {
66- fixture : '' ,
67- metrics,
68- details : {
69- rawScores : response . scores ,
70- pageCount : output . formSpec . pages . length ,
71- fieldCount : output . spec . groups . reduce (
72- ( sum , g ) => sum + g . requirements . length ,
73- 0 ,
74- ) ,
75- groupCount : output . spec . groups . length ,
76- } ,
77- }
78- } ,
79-
80- summarize ( cases : CaseMetrics [ ] ) : SummaryMetrics {
81- if ( cases . length === 0 ) return { metrics : { } }
82-
83- const metricKeys = new Set < string > ( )
84- for ( const c of cases ) {
85- for ( const key of Object . keys ( c . metrics ) ) metricKeys . add ( key )
86- }
87-
88- const metrics : Record < string , number > = { }
89- for ( const key of metricKeys ) {
90- let sum = 0
44+
45+ const response = await currentJudge . judge ( output . spec , output . formSpec )
46+
47+ const metrics : Record < string , number > = { }
48+ let total = 0
9149 let count = 0
92- for ( const c of cases ) {
93- if ( key in c . metrics ) {
94- sum += c . metrics [ key ]
50+
51+ for ( const dim of DIMENSIONS ) {
52+ const entry = response . scores [ dim ]
53+ if ( entry ) {
54+ const normalized = ( entry . score - 1 ) / 4 // 1-5 → 0-1
55+ metrics [ dim ] = normalized
56+ total += normalized
9557 count ++
9658 }
9759 }
98- metrics [ key ] = count > 0 ? sum / count : 0
99- }
10060
101- return { metrics }
102- } ,
103- }
61+ metrics . overall = count > 0 ? total / count : 0
62+
63+ return {
64+ fixture : '' ,
65+ metrics,
66+ details : {
67+ rawScores : response . scores ,
68+ pageCount : output . formSpec . pages . length ,
69+ fieldCount : output . spec . groups . reduce (
70+ ( sum , g ) => sum + g . requirements . length ,
71+ 0 ,
72+ ) ,
73+ groupCount : output . spec . groups . length ,
74+ } ,
75+ }
76+ } ,
77+
78+ summarize ( cases : CaseMetrics [ ] ) : SummaryMetrics {
79+ if ( cases . length === 0 ) return { metrics : { } }
80+
81+ const metricKeys = new Set < string > ( )
82+ for ( const c of cases ) {
83+ for ( const key of Object . keys ( c . metrics ) ) metricKeys . add ( key )
84+ }
85+
86+ const metrics : Record < string , number > = { }
87+ for ( const key of metricKeys ) {
88+ let sum = 0
89+ let count = 0
90+ for ( const c of cases ) {
91+ if ( key in c . metrics ) {
92+ sum += c . metrics [ key ]
93+ count ++
94+ }
95+ }
96+ metrics [ key ] = count > 0 ? sum / count : 0
97+ }
98+
99+ return { metrics }
100+ } ,
101+ }
104102
105103export function setLayoutJudge ( judge : LayoutJudge ) : void {
106104 currentJudge = judge
0 commit comments