code wiki / _hdl_build / nx_vsbest.nx
nx_vsbest.nx source
↩ module page · 115 lines · 5547 B
1// nx_vsbest.nx -- RECORD a vs-best-in-class claim, or refuse it loudly.
2//
3// argv: <domain> <scope> <competitor> <verdict:behind|parity|ahead> <evlog> <evpat> <method>
4//
5// Every admitted claim is appended to knowledge/status/vsbest_claims.log as ONE atomic line, with
6// the level it EARNS and whether its scope covers the domain. A refusal is printed with the leg that
7// failed and NOTHING is written -- a rejected claim must leave no trace that a later reader could
8// mistake for evidence.
9//
10// ★★★★★THIS IS THE ONLY WAY A DOMAIN CAN REACH S-CLASS OR EXCEED. Three other routes existed and all
11// three are now closed: permil_to_level minting rungs from a coverage percentage (capped), a green
12// gate carrying a stored 4/5 through em_derive_level (capped), and simply having nowhere to record a
13// comparison so only the fake paths were reachable. A comparative rung is now EARNED or ABSENT.
14// license_tier: ORIGINAL No hw writes (Rule 26).
15import "nx_vsbest_lib.nx"
16
17const VS_LOG: *u8 = "knowledge/status/vsbest_claims.log"
18const VS_MODE: i64 = 0x1a4
19const VS_LINE_CAP: i64 = 2048
20
21func vs_apps(b: *u8, cap: i64, o: i64, s: *u8) -> i64 {
22 if o < 0 { return 0 - 1 }
23 var n: i64 = 0
24 while s[n] != (0 as u8) { n = n + 1 }
25 if o + n > cap { return 0 - 1 }
26 var p: i64 = o
27 var i: i64 = 0
28 while i < n { b[p] = s[i]; p = p + 1; i = i + 1 }
29 return p
30}
31
32func vs_appn(b: *u8, cap: i64, o: i64, v: i64) -> i64 {
33 if o < 0 { return 0 - 1 }
34 let t: *u8 = sys_mmap(32)
35 var m: i64 = v
36 var neg: i64 = 0
37 if m < 0 { neg = 1; m = 0 - m }
38 var k: i64 = 0
39 if m == 0 { t[0] = 48 as u8; k = 1 }
40 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
41 if o + neg + k > cap { return 0 - 1 }
42 var p: i64 = o
43 if neg == 1 { b[p] = 45 as u8; p = p + 1 }
44 var i: i64 = 0
45 while i < k { b[p] = t[k - 1 - i]; p = p + 1; i = i + 1 }
46 return p
47}
48
49func main(argc: i64, argv: *i64) -> i64 {
50 if argc < 8 {
51 _p("usage: nx_vsbest <domain> <scope> <competitor> <behind|parity|ahead> <evlog> <evpat> <method>\n" as *u8)
52 _p(" scope must equal <domain> to lift it to a comparative rung; a narrower scope is\n" as *u8)
53 _p(" ADMITTED and recorded but earns only PRODUCTION -- a narrow win is not a domain win.\n" as *u8)
54 sys_exit(1)
55 return 1
56 }
57 let domain: *u8 = argv[1] as *u8
58 let scope: *u8 = argv[2] as *u8
59 let competitor: *u8 = argv[3] as *u8
60 let verdict: *u8 = argv[4] as *u8
61 let evlog: *u8 = argv[5] as *u8
62 let evpat: *u8 = argv[6] as *u8
63 let method: *u8 = argv[7] as *u8
64
65 _p("=== NX-VSBEST: admit or refuse a vs-best-in-class claim ===\n" as *u8)
66 let out: *i64 = sys_mmap(64) as *i64
67 let rc: i64 = vb_admit_scoped(competitor, method, evlog, evpat, verdict, scope, domain, out)
68
69 if rc != VB_OK { if rc != VB_SCOPE_NARROWER {
70 _p(" domain=" as *u8); _p(domain); _p(" competitor=" as *u8); _p(competitor); _p("\n " as *u8)
71 _p(vb_refusal_label(rc)); _p("\n" as *u8)
72 _p("NX-VSBEST verdict=RED (claim REFUSED; nothing written -- a rejected claim leaves no trace)\n" as *u8)
73 sys_exit(2)
74 return 2
75 } }
76
77 let fd: i64 = sys_openat_append(VS_LOG, VS_MODE)
78 if fd < 0 {
79 _p("NX-VSBEST verdict=RED reason=log-unwritable\n" as *u8)
80 sys_exit(3)
81 return 3
82 }
83 let lb: *u8 = sys_mmap(VS_LINE_CAP)
84 var o: i64 = vs_apps(lb, VS_LINE_CAP, 0, "VSBEST epoch=" as *u8)
85 o = vs_appn(lb, VS_LINE_CAP, o, sys_now_realtime_sec())
86 o = vs_apps(lb, VS_LINE_CAP, o, " domain=" as *u8); o = vs_apps(lb, VS_LINE_CAP, o, domain)
87 o = vs_apps(lb, VS_LINE_CAP, o, " scope=" as *u8); o = vs_apps(lb, VS_LINE_CAP, o, scope)
88 o = vs_apps(lb, VS_LINE_CAP, o, " competitor=" as *u8); o = vs_apps(lb, VS_LINE_CAP, o, competitor)
89 o = vs_apps(lb, VS_LINE_CAP, o, " verdict=" as *u8); o = vs_apps(lb, VS_LINE_CAP, o, vb_verdict_label(out[0]))
90 o = vs_apps(lb, VS_LINE_CAP, o, " earns=" as *u8); o = vs_apps(lb, VS_LINE_CAP, o, mat_label(out[1]))
91 o = vs_apps(lb, VS_LINE_CAP, o, " domain_lifting=" as *u8); o = vs_appn(lb, VS_LINE_CAP, o, out[3])
92 o = vs_apps(lb, VS_LINE_CAP, o, " evbytes=" as *u8); o = vs_appn(lb, VS_LINE_CAP, o, out[2])
93 o = vs_apps(lb, VS_LINE_CAP, o, " evlog=" as *u8); o = vs_apps(lb, VS_LINE_CAP, o, evlog)
94 o = vs_apps(lb, VS_LINE_CAP, o, " evpat=" as *u8); o = vs_apps(lb, VS_LINE_CAP, o, evpat)
95 o = vs_apps(lb, VS_LINE_CAP, o, " method=" as *u8); o = vs_apps(lb, VS_LINE_CAP, o, method)
96 o = vs_apps(lb, VS_LINE_CAP, o, "\n" as *u8)
97 if o < 0 { sys_close(fd); _p("NX-VSBEST verdict=RED reason=line-too-long\n" as *u8); sys_exit(4); return 4 }
98 sys_write(fd, lb, o)
99 sys_close(fd)
100
101 _p(" domain=" as *u8); _p(domain); _p(" scope=" as *u8); _p(scope)
102 _p("\n competitor=" as *u8); _p(competitor)
103 _p("\n verdict=" as *u8); _p(vb_verdict_label(out[0]))
104 _p(" earns=" as *u8); _p(mat_label(out[1]))
105 _p(" evidence=" as *u8); _fn(1, out[2]); _p(" bytes readable, pattern present\n" as *u8)
106 if out[3] == 1 {
107 _p(" DOMAIN-LIFTING: scope IS the domain, so this claim earns the comparative rung.\n" as *u8)
108 } else {
109 _p(" NOT domain-lifting: scope is NARROWER than the domain. Recorded as real evidence,\n" as *u8)
110 _p(" but it earns PRODUCTION -- a narrow win is not a domain win.\n" as *u8)
111 }
112 _p("NX-VSBEST verdict=GREEN (claim admitted and recorded)\n" as *u8)
113 sys_exit(0)
114 return 0
115}