code wiki / _hdl_build / nx_link_auto_gate.nx

nx_link_auto_gate.nx source

↩ module page · 127 lines · 7813 B

1// nx_link_auto_gate.nx -- GATE: self-populating unifier (R-LINK-R1). T1 auto-register every item in the Dirty- 2// Dozen catalog tier (12). T2 a fully-stocked item (strawberry) auto-detects impact+price+swap. T3 honest 3// partial (kale: impact only -> price/swap "-"). T4 mixed (blueberries: impact+price, no swap). T5 detection is 4// REAL (absent facets really absent; an unseeded item detects nothing -> no fabrication). T6 a browsable index 5// links every item to its unified view, sovereign, shipped. license_tier: ORIGINAL 6import "nx_link_auto.nx" 7import "nx_produce.nx" 8import "nx_clean_market.nx" 9import "nx_publisher.nx" 10import "nx_seg_store.nx" 11import "nx_syscalls.nx" 12import "nx_gate_verdict.nx" 13 14const LA_LINK: *u8 = "knowledge/store/lauto-link-" 15const LA_FOOD: *u8 = "knowledge/store/lauto-food-" 16const LA_PRICE: *u8 = "knowledge/store/lauto-price-" 17const LA_SWAP: *u8 = "knowledge/store/lauto-swap-" 18const LA_AREA: *u8 = "TX-Austin" 19const LA_STAGE_FILE: *u8 = "knowledge/staging/lauto/index.html" 20const LA_LIVE_FILE: *u8 = "knowledge/publish/lauto-live/index.html" 21 22func g_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 23func g_i(v: i64) -> i64 { 24 let bb: *u8 = sys_mmap(28); var m: i64 = v 25 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 26 let t: *u8 = sys_mmap(28); var k: i64 = 0 27 if m == 0 { t[0] = 48 as u8; k = 1 } 28 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 29 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0 30} 31func g_streq(prefix: *u8, canonical: *u8, f: i64, want: *u8) -> i64 { 32 let b: *u8 = sys_mmap(64); lk_field(prefix, canonical, f, b) 33 return fd_streq(b, want) 34} 35func g_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 } 36 37func main() -> i64 { 38 g_p("=== nx_link_auto_gate (R-LINK-R1: self-populating unifier) ===\n" as *u8) 39 40 // food: the full Dirty-Dozen impact catalog + tier index 41 pd_seed(LA_FOOD) // 8 original Dirty-Dozen impact records 42 cm_seed(LA_FOOD) // +4 dirty + clean15 + food:tier:dirty (12) 43 44 // price: only strawberry + blueberries observed 45 pr_add_store(LA_PRICE, "walmart_atx" as *u8, "Walmart" as *u8, "Walmart" as *u8, "TX-Austin" as *u8, "TX" as *u8, "receipt" as *u8) 46 pr_set_price(LA_PRICE, "walmart_atx" as *u8, "strawberry" as *u8, 498, "2025-06-20" as *u8, "lb" as *u8, "receipt" as *u8) 47 pr_set_price(LA_PRICE, "walmart_atx" as *u8, "blueberries" as *u8, 700, "2025-06-20" as *u8, "pint" as *u8, "receipt" as *u8) 48 49 // swap: only strawberry is a swap species 50 sw_seed_config(LA_SWAP) 51 sw_add_species(LA_SWAP, "strawberry" as *u8, "Strawberry" as *u8, "fruit" as *u8, "common" as *u8) 52 53 var pass: i64 = 0 54 var tot: i64 = 0 55 56 // T1 auto-register the whole tier 57 let n: i64 = lk_auto_from_tier(LA_LINK, LA_FOOD, LA_PRICE, LA_SWAP, "food:tier:dirty" as *u8, LA_AREA) 58 g_p("auto-registered from catalog tier = " as *u8); g_i(n); g_p("\n" as *u8) 59 tot = tot + 1 60 if n == 12 { pass = pass + 1; g_p("PASS T1 auto-registered all 12 Dirty-Dozen items from the catalog (no hand-registration)\n" as *u8) } else { g_p("FAIL T1 n=" as *u8); g_i(n); g_p("\n" as *u8) } 61 62 // T2 fully-stocked item: strawberry detects impact + price + swap 63 tot = tot + 1 64 var ok2: i64 = 1 65 if g_streq(LA_LINK, "strawberry" as *u8, 2, "strawberry" as *u8) != 1 { ok2 = 0 } 66 if g_streq(LA_LINK, "strawberry" as *u8, 3, "strawberry" as *u8) != 1 { ok2 = 0 } 67 if g_streq(LA_LINK, "strawberry" as *u8, 4, "strawberry" as *u8) != 1 { ok2 = 0 } 68 if ok2 == 1 { pass = pass + 1; g_p("PASS T2 strawberry auto-detected impact+price+swap (all three facets)\n" as *u8) } else { g_p("FAIL T2\n" as *u8) } 69 70 // T3 honest partial: kale has impact only 71 tot = tot + 1 72 var ok3: i64 = 1 73 if g_streq(LA_LINK, "kale" as *u8, 2, "kale" as *u8) != 1 { ok3 = 0 } // impact present 74 if g_streq(LA_LINK, "kale" as *u8, 3, "-" as *u8) != 1 { ok3 = 0 } // price absent 75 if g_streq(LA_LINK, "kale" as *u8, 4, "-" as *u8) != 1 { ok3 = 0 } // swap absent 76 if ok3 == 1 { pass = pass + 1; g_p("PASS T3 honest partial: kale = impact only, price/swap '-' (auto, not fabricated)\n" as *u8) } else { g_p("FAIL T3\n" as *u8) } 77 78 // T4 mixed: blueberries impact + price, no swap 79 tot = tot + 1 80 var ok4: i64 = 1 81 if g_streq(LA_LINK, "blueberries" as *u8, 2, "blueberries" as *u8) != 1 { ok4 = 0 } 82 if g_streq(LA_LINK, "blueberries" as *u8, 3, "blueberries" as *u8) != 1 { ok4 = 0 } 83 if g_streq(LA_LINK, "blueberries" as *u8, 4, "-" as *u8) != 1 { ok4 = 0 } 84 if ok4 == 1 { pass = pass + 1; g_p("PASS T4 mixed: blueberries = impact+price detected, swap '-'\n" as *u8) } else { g_p("FAIL T4\n" as *u8) } 85 86 // T5 detection is REAL (no fabrication) 87 tot = tot + 1 88 var ok5: i64 = 1 89 if lk_has_swap(LA_SWAP, "blueberries" as *u8) != 0 { ok5 = 0 } 90 if lk_has_price(LA_PRICE, "kale" as *u8, LA_AREA) != 0 { ok5 = 0 } 91 if lk_has_impact(LA_FOOD, "dragonfruit" as *u8) != 0 { ok5 = 0 } // never seeded anywhere 92 if lk_has_impact(LA_FOOD, "strawberry" as *u8) != 1 { ok5 = 0 } // really there 93 if ok5 == 1 { pass = pass + 1; g_p("PASS T5 detection is real: absent facets absent, unseeded item detects nothing, present facet present\n" as *u8) } else { g_p("FAIL T5\n" as *u8) } 94 95 // T6 browsable index links each item to its unified view 96 let page: *u8 = sys_mmap(65536) 97 let np: i64 = lk_render_index(LA_LINK, LA_FOOD, "food:tier:dirty" as *u8, "Nishi clean market &mdash; the whole story" as *u8, page) 98 g_p("index page = " as *u8); g_i(np); g_p(" bytes\n" as *u8) 99 tot = tot + 1 100 var ok6: i64 = 1 101 if as_has_thirdparty_js(page, np) != 0 { ok6 = 0 } 102 if as_contains(page, np, "strawberry.html" as *u8) != 1 { ok6 = 0 } // links to the unified view 103 if as_contains(page, np, "blueberries.html" as *u8) != 1 { ok6 = 0 } 104 if as_contains(page, np, "Clean" as *u8) != 1 { ok6 = 0 } // facet badges 105 if as_contains(page, np, "Swap" as *u8) != 1 { ok6 = 0 } 106 sys_mkdir("knowledge/staging" as *u8, 0x1ed) 107 sys_mkdir("knowledge/staging/lauto" as *u8, 0x1ed) 108 let sfd: i64 = sys_openat_wr(LA_STAGE_FILE, 420); if sfd >= 0 { sys_write(sfd, page, np); sys_close(sfd) } 109 pub_init() 110 sys_mkdir("knowledge/publish/lauto-stage" as *u8, 0x1ed) 111 sys_mkdir("knowledge/publish/lauto-live" as *u8, 0x1ed) 112 pub_submit_to("knowledge/publish/lauto-queue.tsv" as *u8, LA_STAGE_FILE, "index.html" as *u8, "nishifoodfamily" as *u8, "nishi-lauto" as *u8, "internal" as *u8) 113 pub_run_full("knowledge/publish/lauto-queue.tsv" as *u8, "knowledge/publish/lauto-ledger.tsv" as *u8, "knowledge/publish/lauto-stage" as *u8, "knowledge/publish/lauto-live" as *u8, "publish:lauto" as *u8) 114 if g_exists(LA_LIVE_FILE) != 1 { ok6 = 0 } 115 if ok6 == 1 { pass = pass + 1; g_p("PASS T6 browsable index: every catalog item links to its unified story, facet badges, sovereign, shipped\n" as *u8) } else { g_p("FAIL T6\n" as *u8) } 116 117 g_p("nx_link_auto_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot) 118 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 119 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 120 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 121 let ctr__dry: *i64 = gv_ctr() 122 ctr__dry[0] = pass 123 ctr__dry[1] = tot 124 let rc__dry: i64 = gv_verdict("LINK-AUTO-GATE" as *u8, ctr__dry, "the unifier populates itself from the catalogs; add an item anywhere -> it shows up)" as *u8) 125 sys_exit(rc__dry) 126 return rc__dry 127}