code wiki / _hdl_build / nx_link_auto_gate.nx
nx_link_auto_gate.nx source
↩ module page · 120 lines · 7415 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"
12
13const LA_LINK: *u8 = "knowledge/store/lauto-link-"
14const LA_FOOD: *u8 = "knowledge/store/lauto-food-"
15const LA_PRICE: *u8 = "knowledge/store/lauto-price-"
16const LA_SWAP: *u8 = "knowledge/store/lauto-swap-"
17const LA_AREA: *u8 = "TX-Austin"
18const LA_STAGE_FILE: *u8 = "knowledge/staging/lauto/index.html"
19const LA_LIVE_FILE: *u8 = "knowledge/publish/lauto-live/index.html"
20
21func 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 }
22func g_i(v: i64) -> i64 {
23 let bb: *u8 = sys_mmap(28); var m: i64 = v
24 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
25 let t: *u8 = sys_mmap(28); var k: i64 = 0
26 if m == 0 { t[0] = 48 as u8; k = 1 }
27 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
28 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0
29}
30func g_streq(prefix: *u8, canonical: *u8, f: i64, want: *u8) -> i64 {
31 let b: *u8 = sys_mmap(64); lk_field(prefix, canonical, f, b)
32 return fd_streq(b, want)
33}
34func g_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
35
36func main() -> i64 {
37 g_p("=== nx_link_auto_gate (R-LINK-R1: self-populating unifier) ===\n" as *u8)
38
39 // food: the full Dirty-Dozen impact catalog + tier index
40 pd_seed(LA_FOOD) // 8 original Dirty-Dozen impact records
41 cm_seed(LA_FOOD) // +4 dirty + clean15 + food:tier:dirty (12)
42
43 // price: only strawberry + blueberries observed
44 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)
45 pr_set_price(LA_PRICE, "walmart_atx" as *u8, "strawberry" as *u8, 498, "2025-06-20" as *u8, "lb" as *u8, "receipt" as *u8)
46 pr_set_price(LA_PRICE, "walmart_atx" as *u8, "blueberries" as *u8, 700, "2025-06-20" as *u8, "pint" as *u8, "receipt" as *u8)
47
48 // swap: only strawberry is a swap species
49 sw_seed_config(LA_SWAP)
50 sw_add_species(LA_SWAP, "strawberry" as *u8, "Strawberry" as *u8, "fruit" as *u8, "common" as *u8)
51
52 var pass: i64 = 0
53 var tot: i64 = 0
54
55 // T1 auto-register the whole tier
56 let n: i64 = lk_auto_from_tier(LA_LINK, LA_FOOD, LA_PRICE, LA_SWAP, "food:tier:dirty" as *u8, LA_AREA)
57 g_p("auto-registered from catalog tier = " as *u8); g_i(n); g_p("\n" as *u8)
58 tot = tot + 1
59 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) }
60
61 // T2 fully-stocked item: strawberry detects impact + price + swap
62 tot = tot + 1
63 var ok2: i64 = 1
64 if g_streq(LA_LINK, "strawberry" as *u8, 2, "strawberry" as *u8) != 1 { ok2 = 0 }
65 if g_streq(LA_LINK, "strawberry" as *u8, 3, "strawberry" as *u8) != 1 { ok2 = 0 }
66 if g_streq(LA_LINK, "strawberry" as *u8, 4, "strawberry" as *u8) != 1 { ok2 = 0 }
67 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) }
68
69 // T3 honest partial: kale has impact only
70 tot = tot + 1
71 var ok3: i64 = 1
72 if g_streq(LA_LINK, "kale" as *u8, 2, "kale" as *u8) != 1 { ok3 = 0 } // impact present
73 if g_streq(LA_LINK, "kale" as *u8, 3, "-" as *u8) != 1 { ok3 = 0 } // price absent
74 if g_streq(LA_LINK, "kale" as *u8, 4, "-" as *u8) != 1 { ok3 = 0 } // swap absent
75 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) }
76
77 // T4 mixed: blueberries impact + price, no swap
78 tot = tot + 1
79 var ok4: i64 = 1
80 if g_streq(LA_LINK, "blueberries" as *u8, 2, "blueberries" as *u8) != 1 { ok4 = 0 }
81 if g_streq(LA_LINK, "blueberries" as *u8, 3, "blueberries" as *u8) != 1 { ok4 = 0 }
82 if g_streq(LA_LINK, "blueberries" as *u8, 4, "-" as *u8) != 1 { ok4 = 0 }
83 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) }
84
85 // T5 detection is REAL (no fabrication)
86 tot = tot + 1
87 var ok5: i64 = 1
88 if lk_has_swap(LA_SWAP, "blueberries" as *u8) != 0 { ok5 = 0 }
89 if lk_has_price(LA_PRICE, "kale" as *u8, LA_AREA) != 0 { ok5 = 0 }
90 if lk_has_impact(LA_FOOD, "dragonfruit" as *u8) != 0 { ok5 = 0 } // never seeded anywhere
91 if lk_has_impact(LA_FOOD, "strawberry" as *u8) != 1 { ok5 = 0 } // really there
92 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) }
93
94 // T6 browsable index links each item to its unified view
95 let page: *u8 = sys_mmap(65536)
96 let np: i64 = lk_render_index(LA_LINK, LA_FOOD, "food:tier:dirty" as *u8, "Nishi clean market — the whole story" as *u8, page)
97 g_p("index page = " as *u8); g_i(np); g_p(" bytes\n" as *u8)
98 tot = tot + 1
99 var ok6: i64 = 1
100 if as_has_thirdparty_js(page, np) != 0 { ok6 = 0 }
101 if as_contains(page, np, "strawberry.html" as *u8) != 1 { ok6 = 0 } // links to the unified view
102 if as_contains(page, np, "blueberries.html" as *u8) != 1 { ok6 = 0 }
103 if as_contains(page, np, "Clean" as *u8) != 1 { ok6 = 0 } // facet badges
104 if as_contains(page, np, "Swap" as *u8) != 1 { ok6 = 0 }
105 sys_mkdir("knowledge/staging" as *u8, 0x1ed)
106 sys_mkdir("knowledge/staging/lauto" as *u8, 0x1ed)
107 let sfd: i64 = sys_openat_wr(LA_STAGE_FILE, 420); if sfd >= 0 { sys_write(sfd, page, np); sys_close(sfd) }
108 pub_init()
109 sys_mkdir("knowledge/publish/lauto-stage" as *u8, 0x1ed)
110 sys_mkdir("knowledge/publish/lauto-live" as *u8, 0x1ed)
111 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)
112 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)
113 if g_exists(LA_LIVE_FILE) != 1 { ok6 = 0 }
114 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) }
115
116 g_p("nx_link_auto_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot)
117 if pass == tot { g_p(" verdict=GREEN (the unifier populates itself from the catalogs; add an item anywhere -> it shows up)\n" as *u8); return 0 }
118 g_p(" verdict=RED\n" as *u8)
119 return 1
120}