code wiki / _hdl_build / nx_paper_panel_cli.nx
nx_paper_panel_cli.nx source
↩ module page · 86 lines · 4365 B
1// nx_paper_panel_cli.nx -- callable MCP/API surface for manuscript-grade admissibility (AS-2).
2//
3// nx_paper_panel <grader_id> <author_id> <leak_csv> <holdout_clean> <grade_a> <grade_b> [tiebreak]
4// leak_csv = same_model,inheritance,same_family (1=yes 0=no)
5// holdout_clean = 1 if the manuscript was NOT part of what the grader was tuned on
6// e.g. self-graded, perfect score: nx_paper_panel 7 7 1,1,1 1 1000 1000
7// -> {"verdict":"INADMISSIBLE","grade":0} (a score cannot launder its grader)
8//
9// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
10import "nx_paper_panel.nx"
11import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc)
12import "nx_syscalls.nx"
13
14func ppc_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
15func ppc_q() -> i64 { let b: *u8 = sys_mmap(1); b[0] = 34 as u8; sys_write(1, b, 1); return 0 }
16func ppc_key(name: *u8) -> i64 { ppc_q(); ppc_puts(name); ppc_q(); ppc_puts(":" as *u8); return 0 }
17// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer
18// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the
19// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls).
20// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign.
21func ppc_num(v: i64) -> i64 { nxi_out(v); return 0 }
22func ppc_atoi(a: *u8) -> i64 {
23 var v: i64 = 0; var i: i64 = 0
24 while a[i] != (0 as u8) {
25 let ch: i64 = a[i] as i64
26 if ch >= 48 { if ch <= 57 { v = v * 10 + (ch - 48) } }
27 i = i + 1
28 }
29 return v
30}
31func ppc_csv3(s: *u8, out: *i64) -> i64 {
32 var cnt: i64 = 0; var cur: i64 = 0; var i: i64 = 0
33 out[0] = 0; out[1] = 0; out[2] = 0
34 while s[i] != (0 as u8) {
35 let c: i64 = s[i] as i64
36 if c >= 48 { if c <= 57 { cur = cur * 10 + (c - 48) } }
37 if c == 44 { if cnt < 3 { out[cnt] = cur; cnt = cnt + 1 } cur = 0 }
38 i = i + 1
39 }
40 if cnt < 3 { out[cnt] = cur; cnt = cnt + 1 }
41 return cnt
42}
43func ppc_name(v: i64) -> i64 {
44 if v == PP_INADMISSIBLE { ppc_puts("INADMISSIBLE" as *u8); return 0 }
45 if v == PP_PROVISIONAL { ppc_puts("PROVISIONAL" as *u8); return 0 }
46 ppc_puts("ADMITTED" as *u8)
47 return 0
48}
49func main(argc: i64, argv: *i64) -> i64 {
50 if argc < 7 {
51 ppc_puts("{" as *u8); ppc_key("error" as *u8); ppc_q()
52 ppc_puts("usage: nx_paper_panel <grader_id> <author_id> <same_model,inheritance,same_family> <holdout_clean> <grade_a> <grade_b> [tiebreak]" as *u8)
53 ppc_q(); ppc_puts("}\n" as *u8); sys_exit(2); return 2
54 }
55 let gid: i64 = ppc_atoi(argv[1] as *u8)
56 let aid: i64 = ppc_atoi(argv[2] as *u8)
57 let leak: *i64 = sys_mmap(3 * 8) as *i64
58 ppc_csv3(argv[3] as *u8, leak)
59 let hold: i64 = ppc_atoi(argv[4] as *u8)
60 let ga: i64 = ppc_atoi(argv[5] as *u8)
61 let gb: i64 = ppc_atoi(argv[6] as *u8)
62 var tb: i64 = ga
63 if argc >= 8 { tb = ppc_atoi(argv[7] as *u8) }
64
65 let indep: i64 = pp_grader_independent(gid, aid, leak[0], leak[1], leak[2])
66 let adm: i64 = pp_admissible(indep, hold)
67 let out: *i64 = sys_mmap(2 * 8) as *i64
68 let v: i64 = pp_verdict(adm, ga, gb, tb, out)
69
70 ppc_puts("{" as *u8)
71 ppc_key("tool" as *u8); ppc_q(); ppc_puts("nx_paper_panel" as *u8); ppc_q(); ppc_puts("," as *u8)
72 ppc_key("self_graded" as *u8); ppc_num(pp_self_graded(gid, aid)); ppc_puts("," as *u8)
73 ppc_key("grader_independent" as *u8); ppc_num(indep); ppc_puts("," as *u8)
74 ppc_key("holdout_clean" as *u8); ppc_num(hold); ppc_puts("," as *u8)
75 ppc_key("admissible" as *u8); ppc_num(adm); ppc_puts("," as *u8)
76 ppc_key("grade_a" as *u8); ppc_num(ga); ppc_puts("," as *u8)
77 ppc_key("grade_b" as *u8); ppc_num(gb); ppc_puts("," as *u8)
78 ppc_key("verdict" as *u8); ppc_num(v); ppc_puts("," as *u8)
79 ppc_key("verdict_name" as *u8); ppc_q(); ppc_name(v); ppc_q(); ppc_puts("," as *u8)
80 ppc_key("grade" as *u8); ppc_num(out[0]); ppc_puts("," as *u8)
81 ppc_key("note" as *u8); ppc_q()
82 ppc_puts("composes nx_referee ref_no_self_grade + nx_referee_v2 R6 leakage and R7 holdout + nx_peer_review dual-grade; an INADMISSIBLE grade is forced to 0 because a score cannot launder its grader" as *u8)
83 ppc_q(); ppc_puts("}\n" as *u8)
84 sys_exit(0)
85 return 0
86}