code wiki / _hdl_build / nx_eval_factor_register.nx
nx_eval_factor_register.nx source
↩ module page · 101 lines · 6033 B
1// nx_eval_factor_register.nx -- GOVERNED registration of EVAL rung 3 (factor attribution) + the
2// O-lane flag writer. ENGINEER verdict mechanical: (a) factor KAT byte-exact vs expected (8 factors,
3// permil math, ignored/unmatched accounting); (b) flag writer appends exactly one well-formed EVAL
4// line per call (run twice -> two identical lines). license_tier: ORIGINAL
5import "nx_cap_register.nx"
6import "nx_pm_review_log.nx"
7import "nx_syscalls.nx"
8
9func efr_run3(path: *u8, a1: *u8, a2: *u8, a3: *u8, outpath: *u8) -> i64 {
10 let pid: i64 = sys_fork()
11 if pid == 0 {
12 let ofd: i64 = sys_openat_wr(outpath, 0x1a4)
13 if ofd >= 0 { sys_dup3(ofd, 1, 0) }
14 let argv: *i64 = sys_mmap(48) as *i64
15 argv[0] = path as i64
16 argv[1] = a1 as i64
17 argv[2] = a2 as i64
18 argv[3] = a3 as i64
19 argv[4] = 0
20 let envp: *i64 = sys_mmap(16) as *i64
21 envp[0] = "PATH=/usr/bin:/bin" as *u8 as i64
22 envp[1] = 0
23 sys_execve(path, argv, envp)
24 sys_exit(127)
25 }
26 let st: *i64 = sys_mmap(16) as *i64
27 sys_wait4(pid, st, 0)
28 let sig: i64 = st[0] & 0x7f
29 if sig != 0 { return 128 + sig }
30 return (st[0] >> 8) & 0xff
31}
32
33func efr_files_eq(pa: *u8, pb: *u8) -> i64 {
34 let la: *i64 = sys_mmap(8) as *i64
35 let ba: *u8 = sys_read_file(pa, la)
36 let lb: *i64 = sys_mmap(8) as *i64
37 let bb: *u8 = sys_read_file(pb, lb)
38 if (ba as i64) == 0 { return 0 }
39 if (bb as i64) == 0 { return 0 }
40 if la[0] != lb[0] { return 0 }
41 if la[0] < 10 { return 0 }
42 var i: i64 = 0
43 while i < la[0] { if ba[i] != bb[i] { return 0 } i = i + 1 }
44 return 1
45}
46
47func efr_file_is(path: *u8, want: *u8) -> i64 {
48 let lp: *i64 = sys_mmap(8) as *i64
49 let buf: *u8 = sys_read_file(path, lp)
50 if (buf as i64) == 0 { return 0 }
51 var wl: i64 = 0
52 while want[wl] != (0 as u8) { wl = wl + 1 }
53 if lp[0] != wl { return 0 }
54 var i: i64 = 0
55 while i < wl { if buf[i] != want[i] { return 0 } i = i + 1 }
56 return 1
57}
58
59func main() -> i64 {
60 // (a) factor attribution KAT
61 let rc1: i64 = efr_run3("/tmp/_eval_factor_authored.sov.elf" as *u8, "knowledge/status/eval_kat_triangle_in.log" as *u8, "knowledge/status/eval_kat_genrec.log" as *u8, "/tmp/efr_factor_kat.log" as *u8, "/tmp/efr_factor_out.txt" as *u8)
62 let eq1: i64 = efr_files_eq("/tmp/efr_factor_out.txt" as *u8, "knowledge/status/eval_kat_factor_expected.txt" as *u8)
63 cr_w(1, "ENGINEER: factor KAT exit=" as *u8); cr_wn(1, rc1)
64 cr_w(1, " byte-exact=" as *u8); cr_wn(1, eq1); cr_w(1, " (need 0 and 1)\n" as *u8)
65
66 // (b) flag writer: fresh log, two appends -> exactly two identical lines
67 let wfd: i64 = sys_openat_wr("/tmp/efr_flag_kat.log" as *u8, 0x1a4)
68 sys_close(wfd)
69 let rcf1: i64 = efr_run3("/tmp/_eval_flag_authored.sov.elf" as *u8, "kat-img" as *u8, "1000" as *u8, "/tmp/efr_flag_kat.log" as *u8, "/tmp/efr_flag_out.txt" as *u8)
70 let rcf2: i64 = efr_run3("/tmp/_eval_flag_authored.sov.elf" as *u8, "kat-img" as *u8, "1000" as *u8, "/tmp/efr_flag_kat.log" as *u8, "/tmp/efr_flag_out.txt" as *u8)
71 let eqf: i64 = efr_file_is("/tmp/efr_flag_kat.log" as *u8, "EVAL img=kat-img lane=O score=1000\nEVAL img=kat-img lane=O score=1000\n" as *u8)
72 cr_w(1, "ENGINEER: flag exits=" as *u8); cr_wn(1, rcf1); cr_wn(1, rcf2)
73 cr_w(1, " two-line-exact=" as *u8); cr_wn(1, eqf); cr_w(1, " (need 00 and 1)\n" as *u8)
74
75 var exit_ok: i64 = 0
76 if rc1 == 0 { if eq1 == 1 { if rcf1 == 0 { if rcf2 == 0 { if eqf == 1 { exit_ok = 1 } } } } }
77 let eng: i64 = ig_engineer(1, 1, 1, exit_ok)
78 let cat: i64 = sys_openat_rd("knowledge/CAPABILITY_CATALOG.md" as *u8)
79 var documented: i64 = 0
80 if cat >= 0 { documented = ig_documented(1, 1); sys_close(cat) }
81 let council: i64 = ig_council(eng, 1, 1, 2)
82 let decision: i64 = ig_decision(eng, council, documented)
83
84 let pm: i64 = pm_open("/tmp/nishi_pm_review.log" as *u8)
85 if decision == IG_INGEST {
86 pm_deliverable(pm, "eldermig/eval" as *u8, "nx_eval_factor+flag" as *u8, "EVAL rung 3 CLOSED: factor attribution (TRIANGLE x GENREC -> per-factor good/bad permil, generic key=value factors: seed/loras/phrasepos/tokens/cfg; clean signal = TRI-GOOD/TRI-BAD only) KAT byte-exact; O-lane flag writer appends operator EVAL lines (double-append proven). Precision loop closes: operator flags -> triangulation -> factor permil -> what to fix for dress/outfit sales" as *u8)
87 }
88 pm_gap(pm, "eldermig/eval" as *u8, "NEXT-RUNG" as *u8, "GENREC writer at gen time + numeric bucketing" as *u8, "gen-img must emit GENREC lines per render (migrate from idempotency/image_metadata); numeric factors (tokens, cfg) need bucket fields from the writer side; V-lane VLM wiring + M-lane forensics still open; Researcher RoPE grounding before bucket design" as *u8)
89 sys_close(pm)
90 cr_w(1, "GOVERNED decision=" as *u8); cr_wn(1, decision); cr_w(1, " (1=INGEST); PM log updated\n" as *u8)
91
92 if decision != IG_INGEST { sys_exit(1) }
93 if cr_can_register(2, 2, 6, decision) != 1 { cr_w(1, "REFUSED\n" as *u8); sys_exit(1) }
94 let fd: i64 = sys_openat_append("/tmp/nishi_cap_registry.log" as *u8, 0x1a4)
95 cr_write_entry(fd, 226, 2, "GEN EVAL-FACTOR rung3 -- Builder-authored (ma_emit_eval_factor) factor attribution: TRIANGLE verdicts x GENREC input vectors (generic key=value: seed/loras/phrasepos/tokens/cfg/...) -> FACTOR good/bad/permil lines + ignored/unmatched accounting -> append-only knowledge/status/eval_factor.log; KAT 8-factor byte-exact; context-rot/phrase-position now MEASURED; clean signal law (only TRI-GOOD/TRI-BAD attribute)" as *u8, 2)
96 cr_write_entry(fd, 227, 2, "GEN EVAL-FLAG -- Builder-authored (ma_emit_eval_flag) O-lane operator flag writer: argv img-id + score-permil -> appends EVAL lane=O line to the lanes log (append-only, double-append proven exact); the operator's feedback becomes triangulation data with one command" as *u8, 2)
97 sys_close(fd)
98 cr_w(1, "CAPREG idx=226,227 REGISTERED\n" as *u8)
99 sys_exit(0)
100 return 0
101}