code wiki / _hdl_build / nx_extract_heal_gate.nx

nx_extract_heal_gate.nx source

↩ module page · 68 lines · 4044 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" 9import "nx_gate_verdict.nx" 10 11func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw(" 12" as *u8); return ok } 13func gsl(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 14func cls(t: *i64, url: *u8, kb: *i64) -> i64 { return xh_classify(t, url, gsl(url), kb) } 15 16func main() -> i64 { 17 gw("extract-heal SOVEREIGN gate (data-driven patterns: miss -> log -> learn -> heal -> adapt -> no-overgeneralize)\n" as *u8) 18 var pass: i64 = 0 19 var ttl: i64 = 0 20 21 let t: *i64 = xh_new() 22 xh_seed(t) 23 let seed_n: i64 = t[0] 24 let kb: *i64 = sys_mmap(8) as *i64 25 let adv: *u8 = "https://cdn-x7.streamhost.net/deliver/vod/abc123" as *u8 // novel host, no ext, unseeded path 26 27 // H1: the seeded (data-driven) table classifies a known extension 28 cls(t, "https://c/x.m3u8" as *u8, kb) 29 ttl=ttl+1; pass=pass+grow("H1 seed table classifies .m3u8 -> HLS\x00" as *u8, (kb[0] == XT_HLS) as i64) 30 // H2: the adversary URL is a MISS (the failure) 31 let c2: i64 = cls(t, adv, kb) 32 ttl=ttl+1; pass=pass+grow("H2 adversary URL MISS (conf 0, kind NONE)\x00" as *u8, ((kb[0] == XT_NONE)) as i64) 33 // log the failure 34 let logbuf: *u8 = sys_mmap(8192) 35 let loglen: i64 = xh_log(logbuf, 0, 8192, adv, gsl(adv), "no-pattern-match" as *u8) 36 // H3: LEARN from the confirmed-media failure -> HEALED 37 let learned: i64 = xh_learn(t, adv, gsl(adv), XT_DIRECT) 38 let c3: i64 = cls(t, adv, kb) 39 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)) 40 // H4: a DIFFERENT URL from the SAME host is now caught too (generalized) 41 cls(t, "https://cdn-x7.streamhost.net/deliver/live/xyz789" as *u8, kb) 42 ttl=ttl+1; pass=pass+grow("H4 same-host new URL also DIRECT (adapted/generalized)\x00" as *u8, (kb[0] == XT_DIRECT) as i64) 43 // H5: a DIFFERENT host is still a miss (no over-generalization) 44 cls(t, "https://videos.other.net/clip" as *u8, kb) 45 ttl=ttl+1; pass=pass+grow("H5 different host still NONE (no over-generalize)\x00" as *u8, (kb[0] == XT_NONE) as i64) 46 // H6: repeated learn dedups (table doesn't bloat) 47 let before: i64 = t[0] 48 let l2: i64 = xh_learn(t, adv, gsl(adv), XT_DIRECT) 49 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)) 50 // H7: the failure log captured the URL + reason 51 var h7: i64 = 1 52 if xt_has(logbuf, loglen, "streamhost.net" as *u8) == 0 { h7 = 0 } 53 if xt_has(logbuf, loglen, "no-pattern-match" as *u8) == 0 { h7 = 0 } 54 ttl=ttl+1; pass=pass+grow("H7 failure log captured url + reason\x00" as *u8, h7) 55 // H8: exactly one pattern was added by the whole episode 56 ttl=ttl+1; pass=pass+grow("H8 table grew by exactly 1 (seed+1)\x00" as *u8, (t[0] == (seed_n + 1)) as i64) 57 58 gw("pass=" as *u8); gn(pass); gw("/" as *u8); gn(ttl); gw("\n" as *u8) 59 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 60 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 61 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 62 let ctr__dry: *i64 = gv_ctr() 63 ctr__dry[0] = pass 64 ctr__dry[1] = ttl 65 let rc__dry: i64 = gv_verdict("EXTRACT-HEAL-GATE" as *u8, ctr__dry, "self-healing adaptive recognition: learns a pattern from a failure, generalizes, bounded)" as *u8) 66 sys_exit(rc__dry) 67 return rc__dry 68}