code wiki / _hdl_build / nx_referee_serve.nx
nx_referee_serve.nx source
↩ module page · 40 lines · 3411 B
1// nx_referee_serve.nx -- SERVE-WRAPPER making the REFEREE role's capability MCP-callable (operator 2026-07-10: "each role
2// owns its raci capabilities and gets them to be mcp apis"). Library-role pattern (5th): nx_referee is a PURE-LOGIC lib
3// (ref_score/ref_verdict/fairness gates, no main). Referee's NEW owned activity = ADJUDICATE (cheat-proof scoring of a
4// head-to-head; it previously owned NO activity -- only Consulted -- a real RACI defect). Self-test exercises the three
5// pillars: (1) GROUND-TRUTH scoring vs an oracle (never self-assessed), (2) the SEPARATION gate -- a scorer who IS a
6// competitor invalidates the head-to-head, (3) DECISIVENESS -- a winner ONLY when the margin clears the noise threshold,
7// else an honest TIE (no overclaim). Clean exit 0 + JSON so nishi_crew dispatches `referee adjudicate`. Import ONLY
8// nx_referee.nx (brings nx_syscalls; 2nd direct import = double-import trap). REF_TIE=0 REF_A_WINS=1 REF_B_WINS=2.
9// license_tier: ORIGINAL expect_exit: 0
10import "nx_referee.nx"
11
12func rsv_w2(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){ if s[n]==(39 as u8) { let q: *u8=sys_mmap(1); q[0]=34 as u8; sys_write(1,q,1) } else { sys_write(1,(s as i64+n) as *u8,1) } n=n+1 } return 0 }
13func rsv_bit(b: i64) -> i64 { let d: *u8=sys_mmap(1); d[0]=(48+b) as u8; sys_write(1,d,1); return 0 }
14
15func main() -> i64 {
16 // hidden oracle + two competitors' outputs. The referee compares OUTPUT vs ORACLE -- never asks how well they did.
17 let oracle: *i64 = sys_mmap(5*8) as *i64; oracle[0]=1; oracle[1]=2; oracle[2]=3; oracle[3]=4; oracle[4]=5
18 let outA: *i64 = sys_mmap(5*8) as *i64; outA[0]=1; outA[1]=2; outA[2]=3; outA[3]=4; outA[4]=5
19 let outB: *i64 = sys_mmap(5*8) as *i64; outB[0]=1; outB[1]=2; outB[2]=0; outB[3]=0; outB[4]=0
20 let sa: i64 = ref_score(outA, oracle, 5)
21 let sb: i64 = ref_score(outB, oracle, 5)
22 var scoring_ok: i64=0; if sa==5 { if sb==2 { scoring_ok=1 } }
23 // SEPARATION: an independent scorer (id 9) validates; a scorer who IS competitor A (id 1) invalidates.
24 let fair: i64 = ref_test_valid(ref_no_self_grade(9, 1, 2), ref_hidden(0), 1, 1)
25 let selfgrade: i64 = ref_test_valid(ref_no_self_grade(1, 1, 2), ref_hidden(0), 1, 1)
26 var separation_ok: i64=0; if fair==1 { if selfgrade==0 { separation_ok=1 } }
27 // DECISIVENESS: margin 3 >= threshold 2 -> A WINS (1); margin 1 < threshold 2 -> honest TIE (0), never overclaimed.
28 let vd: i64 = ref_verdict(sa, sb, 2)
29 let vt: i64 = ref_verdict(4, 5, 2)
30 var verdict_ok: i64=0; if vd==1 { if vt==0 { verdict_ok=1 } }
31 var ok: i64=0; if scoring_ok==1 { if separation_ok==1 { if verdict_ok==1 { ok=1 } } }
32 rsv_w2("{'v':1,'api':'nishi-crew-referee/v1','role':'referee','activity':'adjudicate','capability':'cheat-proof head-to-head adjudication -- ground-truth oracle scoring (never self-assessed), SEPARATION gate (a competitor cannot be the scorer), decisive-or-honest-TIE verdicts (no overclaim under noise)','selftest':{'oracle_scoring_correct':" as *u8); rsv_bit(scoring_ok)
33 rsv_w2(",'self_grading_invalidated':" as *u8); rsv_bit(separation_ok)
34 rsv_w2(",'tie_when_margin_under_noise':" as *u8); rsv_bit(verdict_ok)
35 rsv_w2("},'verdict':'" as *u8)
36 if ok==1 { rsv_w2("GREEN (fair-judge pillars proven)'}" as *u8) } else { rsv_w2("RED'}" as *u8) }
37 rsv_w2("\n" as *u8)
38 if ok==1 { sys_exit(0); return 0 }
39 sys_exit(1); return 1
40}