code wiki / _hdl_build / nx_link_gate.nx
nx_link_gate.nx source
↩ module page · 139 lines · 9546 B
1// nx_link_gate.nx -- GATE: the grand unifier (R-LINK). One canonical item (strawberry) resolves to ALL four
2// facets, each from its OWN sovereign store: T1 link registered/resolvable. T2 lineage (bio-). T3 clean/impact
3// (food-). T4 best local price (price-). T5 swap availability (swap-) + HONEST partial (an item with only
4// lineage shows the rest as "not recorded", never fabricated). T6 one unified sovereign view with all facets,
5// shipped. license_tier: ORIGINAL
6import "nx_link.nx"
7import "nx_publisher.nx"
8import "nx_seg_store.nx"
9import "nx_syscalls.nx"
10import "nx_gate_verdict.nx"
11
12const LK_LINK: *u8 = "knowledge/store/link-"
13const LK_BIO: *u8 = "knowledge/store/lnk-bio-"
14const LK_FOOD: *u8 = "knowledge/store/lnk-food-"
15const LK_PRICE: *u8 = "knowledge/store/lnk-price-"
16const LK_SWAP: *u8 = "knowledge/store/lnk-swap-"
17const LK_AREA: *u8 = "TX-Austin"
18const LK_STAGE_FILE: *u8 = "knowledge/staging/link/strawberry.html"
19const LK_LIVE_FILE: *u8 = "knowledge/publish/link-live/strawberry.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_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
31
32func main() -> i64 {
33 g_p("=== nx_link_gate (R-LINK: one item, all its facets, one view) ===\n" as *u8)
34
35 // bio- : a strawberry lineage (founder -> F2, superior)
36 ln_seed_config(LK_BIO)
37 ln_add(LK_BIO, "straw_gp" as *u8, "Albion (founder)" as *u8, "plant" as *u8, "Albion" as *u8, 1, "-" as *u8, "-" as *u8, "saved" as *u8, "self" as *u8, "perma_a8_regenerative_ag" as *u8)
38 ln_add(LK_BIO, "straw_h" as *u8, "Albion (F2)" as *u8, "plant" as *u8, "Albion" as *u8, 2, "straw_gp" as *u8, "-" as *u8, "saved" as *u8, "self" as *u8, "perma_a8_regenerative_ag" as *u8)
39 ln_set_gene(LK_BIO, "straw_h" as *u8, 92, 88, 90, 85, 90, "Nishi field trial" as *u8, "perma_a8_regenerative_ag" as *u8)
40 ln_add(LK_BIO, "saff_org" as *u8, "Saffron heritage" as *u8, "plant" as *u8, "Saffron Crocus" as *u8, 1, "-" as *u8, "-" as *u8, "bought" as *u8, "spice farm" as *u8, "perma_a8_regenerative_ag" as *u8)
41
42 // food- : strawberry impact (conv vs nishi)
43 im_seed(LK_FOOD)
44
45 // price- : strawberry at two Austin stores
46 pr_add_store(LK_PRICE, "walmart_atx" as *u8, "Walmart Supercenter" as *u8, "Walmart" as *u8, "TX-Austin" as *u8, "TX" as *u8, "receipt" as *u8)
47 pr_add_store(LK_PRICE, "wf_atx" as *u8, "Whole Foods Market" as *u8, "Whole Foods" as *u8, "TX-Austin" as *u8, "TX" as *u8, "receipt" as *u8)
48 pr_set_price(LK_PRICE, "walmart_atx" as *u8, "strawberry" as *u8, 498, "2025-06-20" as *u8, "lb" as *u8, "receipt" as *u8)
49 pr_set_price(LK_PRICE, "wf_atx" as *u8, "strawberry" as *u8, 650, "2025-06-20" as *u8, "lb" as *u8, "receipt" as *u8)
50
51 // swap- : a neighbour gives strawberry runners
52 sw_seed_config(LK_SWAP)
53 sw_add_species(LK_SWAP, "strawberry" as *u8, "Strawberry" as *u8, "fruit" as *u8, "common" as *u8)
54 sw_add_gardener(LK_SWAP, "alice" as *u8, "Alice" as *u8, "TX-Austin" as *u8)
55 sw_post_offer(LK_SWAP, "a_straw" as *u8, "alice" as *u8, "strawberry" as *u8, "runner" as *u8, 6, "TX-Austin" as *u8, "-" as *u8)
56
57 // the LINKS
58 lk_register(LK_LINK, "strawberry" as *u8, "Strawberry" as *u8, "straw_h" as *u8, "strawberry" as *u8, "strawberry" as *u8, "strawberry" as *u8)
59 lk_register(LK_LINK, "saffron" as *u8, "Saffron" as *u8, "saff_org" as *u8, "-" as *u8, "-" as *u8, "-" as *u8)
60
61 var pass: i64 = 0
62 var tot: i64 = 0
63
64 // T1 link resolvable
65 let bid: *u8 = sys_mmap(48); lk_field(LK_LINK, "strawberry" as *u8, 1, bid)
66 let iid: *u8 = sys_mmap(48); lk_field(LK_LINK, "strawberry" as *u8, 2, iid)
67 g_p("link strawberry: bio=" as *u8); g_p(bid); g_p(" impact=" as *u8); g_p(iid); g_p("\n" as *u8)
68 tot = tot + 1
69 if fd_streq(bid, "straw_h" as *u8) == 1 { if fd_streq(iid, "strawberry" as *u8) == 1 { pass = pass + 1; g_p("PASS T1 link registered + resolvable (bio_id + impact_item)\n" as *u8) } else { g_p("FAIL T1 impact\n" as *u8) } } else { g_p("FAIL T1 bio\n" as *u8) }
70
71 // T2 lineage facet
72 let q: i64 = ln_quality_score(LK_BIO, "straw_h" as *u8)
73 g_p("lineage quality=" as *u8); g_i(q); g_p(" superior=" as *u8); g_i(ln_is_superior(LK_BIO, "straw_h" as *u8)); g_p("\n" as *u8)
74 tot = tot + 1
75 if q == 89 { if ln_is_superior(LK_BIO, "straw_h" as *u8) == 1 { pass = pass + 1; g_p("PASS T2 lineage facet resolves from bio- (quality 89, superior)\n" as *u8) } else { g_p("FAIL T2 superior\n" as *u8) } } else { g_p("FAIL T2 q=" as *u8); g_i(q); g_p("\n" as *u8) }
76
77 // T3 impact facet
78 let clean: i64 = im_clean(LK_FOOD, "strawberry" as *u8, "nishi" as *u8)
79 let save: i64 = im_savings(LK_FOOD, "strawberry" as *u8, "nishi" as *u8, "conv" as *u8)
80 g_p("clean=" as *u8); g_i(clean); g_p(" save=" as *u8); g_i(save); g_p("c\n" as *u8)
81 tot = tot + 1
82 if clean == 95 { if save == 150 { pass = pass + 1; g_p("PASS T3 impact facet resolves from food- (95/100 clean, save $1.50)\n" as *u8) } else { g_p("FAIL T3 save\n" as *u8) } } else { g_p("FAIL T3 clean\n" as *u8) }
83
84 // T4 price facet
85 let sid: *u8 = sys_mmap(48)
86 let cheap: i64 = pr_cheapest(LK_PRICE, LK_AREA, "strawberry" as *u8, sid)
87 g_p("cheapest=" as *u8); g_i(cheap); g_p(" at " as *u8); g_p(sid); g_p("\n" as *u8)
88 tot = tot + 1
89 if cheap == 498 { if fd_streq(sid, "walmart_atx" as *u8) == 1 { pass = pass + 1; g_p("PASS T4 price facet resolves from price- (cheapest $4.98 at Walmart)\n" as *u8) } else { g_p("FAIL T4 sid\n" as *u8) } } else { g_p("FAIL T4 cheap=" as *u8); g_i(cheap); g_p("\n" as *u8) }
90
91 // T5 swap facet + honest partial
92 let oids: *i64 = sys_mmap(8 * 64) as *i64
93 let noff: i64 = sw_find_offers(LK_SWAP, "strawberry" as *u8, LK_AREA, oids)
94 let saffpage: *u8 = sys_mmap(65536)
95 let snp: i64 = lk_render_item(LK_LINK, LK_BIO, LK_FOOD, LK_PRICE, LK_SWAP, "saffron" as *u8, LK_AREA, saffpage)
96 g_p("strawberry offers=" as *u8); g_i(noff); g_p(" | saffron(partial) page=" as *u8); g_i(snp); g_p(" bytes\n" as *u8)
97 tot = tot + 1
98 var ok5: i64 = 1
99 if noff != 1 { ok5 = 0 }
100 if as_contains(saffpage, snp, "Saffron Crocus" as *u8) != 1 { ok5 = 0 } // lineage present
101 if as_contains(saffpage, snp, "No impact data" as *u8) != 1 { ok5 = 0 } // absent facet handled honestly
102 if as_contains(saffpage, snp, "No price data" as *u8) != 1 { ok5 = 0 }
103 if as_contains(saffpage, snp, "Not in the swap network" as *u8) != 1 { ok5 = 0 }
104 if ok5 == 1 { pass = pass + 1; g_p("PASS T5 swap facet resolves (1 offer) + partial item shows present facet, others 'not recorded' (honest)\n" as *u8) } else { g_p("FAIL T5\n" as *u8) }
105
106 // T6 the unified view: all four facets in one sovereign page
107 let page: *u8 = sys_mmap(65536)
108 let np: i64 = lk_render_item(LK_LINK, LK_BIO, LK_FOOD, LK_PRICE, LK_SWAP, "strawberry" as *u8, LK_AREA, page)
109 g_p("unified strawberry view = " as *u8); g_i(np); g_p(" bytes\n" as *u8)
110 tot = tot + 1
111 var ok6: i64 = 1
112 if as_has_thirdparty_js(page, np) != 0 { ok6 = 0 }
113 if as_contains(page, np, "Albion" as *u8) != 1 { ok6 = 0 } // lineage
114 if as_contains(page, np, "superior strain" as *u8) != 1 { ok6 = 0 }
115 if as_contains(page, np, "95/100 clean" as *u8) != 1 { ok6 = 0 } // impact
116 if as_contains(page, np, "$4.98" as *u8) != 1 { ok6 = 0 } // price
117 if as_contains(page, np, "1 neighbour" as *u8) != 1 { ok6 = 0 } // swap
118 sys_mkdir("knowledge/staging" as *u8, 0x1ed)
119 sys_mkdir("knowledge/staging/link" as *u8, 0x1ed)
120 let sfd: i64 = sys_openat_wr(LK_STAGE_FILE, 420); if sfd >= 0 { sys_write(sfd, page, np); sys_close(sfd) }
121 pub_init()
122 sys_mkdir("knowledge/publish/link-stage" as *u8, 0x1ed)
123 sys_mkdir("knowledge/publish/link-live" as *u8, 0x1ed)
124 pub_submit_to("knowledge/publish/link-queue.tsv" as *u8, LK_STAGE_FILE, "strawberry.html" as *u8, "nishifoodfamily" as *u8, "nishi-link" as *u8, "internal" as *u8)
125 pub_run_full("knowledge/publish/link-queue.tsv" as *u8, "knowledge/publish/link-ledger.tsv" as *u8, "knowledge/publish/link-stage" as *u8, "knowledge/publish/link-live" as *u8, "publish:link" as *u8)
126 if g_exists(LK_LIVE_FILE) != 1 { ok6 = 0 }
127 if ok6 == 1 { pass = pass + 1; g_p("PASS T6 ONE unified view: lineage + clean + price + swap for a strawberry, sovereign, shipped\n" as *u8) } else { g_p("FAIL T6\n" as *u8) }
128
129 g_p("nx_link_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot)
130 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
131 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
132 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
133 let ctr__dry: *i64 = gv_ctr()
134 ctr__dry[0] = pass
135 ctr__dry[1] = tot
136 let rc__dry: i64 = gv_verdict("LINK-GATE" as *u8, ctr__dry, "one strawberry: its lineage, cleanliness, best price, and swap availability, together)" as *u8)
137 sys_exit(rc__dry)
138 return rc__dry
139}