code wiki / _hdl_build / nx_extract_heal_gate.nx

nx_extract_heal_gate.nx source

↩ module page · 60 lines · 3661 B

1import "nx_gate_gn.nx" 2import "nx_gate_base.nx" 3// nx_extract_heal_gate.nx -- proves the SELF-HEAL / ADAPT loop: an adversary URL the seed patterns MISS is 4// logged, then LEARNED (a host pattern derived from it) so it + future URLs from that source classify -- while 5// a different host stays a miss (no over-generalization), and repeated learns dedup. license_tier: ORIGINAL expect_exit: 0 6import "nx_syscalls.nx" 7import "nx_media_signal.nx" 8import "nx_extract_heal.nx" 9 10func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw(" 11" as *u8); return ok } 12func gsl(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 13func cls(t: *i64, url: *u8, kb: *i64) -> i64 { return xh_classify(t, url, gsl(url), kb) } 14 15func main() -> i64 { 16 gw("extract-heal SOVEREIGN gate (data-driven patterns: miss -> log -> learn -> heal -> adapt -> no-overgeneralize)\n" as *u8) 17 var pass: i64 = 0 18 var ttl: i64 = 0 19 20 let t: *i64 = xh_new() 21 xh_seed(t) 22 let seed_n: i64 = t[0] 23 let kb: *i64 = sys_mmap(8) as *i64 24 let adv: *u8 = "https://cdn-x7.streamhost.net/deliver/vod/abc123" as *u8 // novel host, no ext, unseeded path 25 26 // H1: the seeded (data-driven) table classifies a known extension 27 cls(t, "https://c/x.m3u8" as *u8, kb) 28 ttl=ttl+1; pass=pass+grow("H1 seed table classifies .m3u8 -> HLS\x00" as *u8, (kb[0] == XT_HLS) as i64) 29 // H2: the adversary URL is a MISS (the failure) 30 let c2: i64 = cls(t, adv, kb) 31 ttl=ttl+1; pass=pass+grow("H2 adversary URL MISS (conf 0, kind NONE)\x00" as *u8, ((kb[0] == XT_NONE)) as i64) 32 // log the failure 33 let logbuf: *u8 = sys_mmap(8192) 34 let loglen: i64 = xh_log(logbuf, 0, 8192, adv, gsl(adv), "no-pattern-match" as *u8) 35 // H3: LEARN from the confirmed-media failure -> HEALED 36 let learned: i64 = xh_learn(t, adv, gsl(adv), XT_DIRECT) 37 let c3: i64 = cls(t, adv, kb) 38 ttl=ttl+1; pass=pass+grow("H3 learn -> adversary now classifies DIRECT (healed)\x00" as *u8, ((learned == 1)) as i64 * ((kb[0] == XT_DIRECT) as i64)) 39 // H4: a DIFFERENT URL from the SAME host is now caught too (generalized) 40 cls(t, "https://cdn-x7.streamhost.net/deliver/live/xyz789" as *u8, kb) 41 ttl=ttl+1; pass=pass+grow("H4 same-host new URL also DIRECT (adapted/generalized)\x00" as *u8, (kb[0] == XT_DIRECT) as i64) 42 // H5: a DIFFERENT host is still a miss (no over-generalization) 43 cls(t, "https://videos.other.net/clip" as *u8, kb) 44 ttl=ttl+1; pass=pass+grow("H5 different host still NONE (no over-generalize)\x00" as *u8, (kb[0] == XT_NONE) as i64) 45 // H6: repeated learn dedups (table doesn't bloat) 46 let before: i64 = t[0] 47 let l2: i64 = xh_learn(t, adv, gsl(adv), XT_DIRECT) 48 ttl=ttl+1; pass=pass+grow("H6 repeat-learn dedups (no growth, returns 0)\x00" as *u8, ((l2 == 0)) as i64 * ((t[0] == before) as i64)) 49 // H7: the failure log captured the URL + reason 50 var h7: i64 = 1 51 if xt_has(logbuf, loglen, "streamhost.net" as *u8) == 0 { h7 = 0 } 52 if xt_has(logbuf, loglen, "no-pattern-match" as *u8) == 0 { h7 = 0 } 53 ttl=ttl+1; pass=pass+grow("H7 failure log captured url + reason\x00" as *u8, h7) 54 // H8: exactly one pattern was added by the whole episode 55 ttl=ttl+1; pass=pass+grow("H8 table grew by exactly 1 (seed+1)\x00" as *u8, (t[0] == (seed_n + 1)) as i64) 56 57 gw("pass=" as *u8); gn(pass); gw("/" as *u8); gn(ttl); gw("\n" as *u8) 58 if pass == ttl { gw("verdict=GREEN (self-healing adaptive recognition: learns a pattern from a failure, generalizes, bounded)\n" as *u8); sys_exit(0); return 0 } 59 gw("verdict=RED\n" as *u8); sys_exit(1); return 1 60}