code wiki / _hdl_build / nx_lineage_gate.nx

nx_lineage_gate.nx source

↩ module page · 154 lines · 11115 B

1// nx_lineage_gate.nx -- GATE: seed-to-feed traceability R0. T1 GENEALOGY (multi-generation lineage walk). T2 2// SEED SWAPPING provenance (origin + source recorded). T3 LIFECYCLE seed->feed is ADDITIVE (8 ordered stages, 3// re-adding a stage is a no-op and never overwrites history). T4 GENETIC superiority/inferiority scored from 4// recorded markers + "you are what you eat" (plate quality requires real chain-of-custody to the EAT stage). 5// T5 works for ANIMALS too (not just plants). T6 the sovereign seed-to-feed PASSPORT renders + ships. license_tier: ORIGINAL 6import "nx_lineage.nx" 7import "nx_publisher.nx" 8import "nx_seg_store.nx" 9import "nx_syscalls.nx" 10 11const LG_STORE: *u8 = "knowledge/store/bio-" 12const LG_STAGE_FILE: *u8 = "knowledge/staging/bio/tomato_passport.html" 13const LG_LIVE_FILE: *u8 = "knowledge/publish/bio-live/tomato_passport.html" 14 15func 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 } 16func g_i(v: i64) -> i64 { 17 let bb: *u8 = sys_mmap(28); var m: i64 = v 18 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 19 let t: *u8 = sys_mmap(28); var k: i64 = 0 20 if m == 0 { t[0] = 48 as u8; k = 1 } 21 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 22 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0 23} 24func g_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 } 25 26func main() -> i64 { 27 g_p("=== nx_lineage_gate (seed-to-feed traceability R0) ===\n" as *u8) 28 ln_seed_config(LG_STORE) 29 30 // --- PLANT lineage: a 3-generation heirloom tomato, the youngest swapped from a neighbor --- 31 ln_add(LG_STORE, "tomgp" as *u8, "Brandywine (founder)" as *u8, "plant" as *u8, "Brandywine" as *u8, 1, "-" as *u8, "-" as *u8, "saved" as *u8, "self" as *u8, "perma_a8_regenerative_ag" as *u8) 32 ln_add(LG_STORE, "tomp" as *u8, "Brandywine (F2)" as *u8, "plant" as *u8, "Brandywine" as *u8, 2, "tomgp" as *u8, "-" as *u8, "saved" as *u8, "self" as *u8, "perma_a8_regenerative_ag" as *u8) 33 ln_add(LG_STORE, "tomc" as *u8, "Brandywine (F3)" as *u8, "plant" as *u8, "Brandywine" as *u8, 3, "tomp" as *u8, "-" as *u8, "swapped" as *u8, "Neighbor Maria" as *u8, "perma_a8_regenerative_ag" as *u8) 34 ln_add(LG_STORE, "tombad" as *u8, "Weak volunteer" as *u8, "plant" as *u8, "Unknown" as *u8, 1, "-" as *u8, "-" as *u8, "saved" as *u8, "self" as *u8, "perma_a8_regenerative_ag" as *u8) 35 36 // genetics (recorded markers): tomc superior, tombad inferior 37 ln_set_gene(LG_STORE, "tomc" as *u8, 95, 90, 88, 85, 92, "Nishi field trial 2025" as *u8, "perma_a8_regenerative_ag" as *u8) 38 ln_set_gene(LG_STORE, "tombad" as *u8, 40, 30, 35, 50, 38, "Nishi field trial 2025" as *u8, "perma_a8_regenerative_ag" as *u8) 39 40 // lifecycle seed->feed for tomc (8 ordered stages) 41 ln_add_stage(LG_STORE, "tomc" as *u8, ST_SEED, "2025-03-01" as *u8, "Seed vault" as *u8, "Maria" as *u8, "swap received" as *u8) 42 ln_add_stage(LG_STORE, "tomc" as *u8, ST_SOWN, "2025-03-15" as *u8, "Greenhouse" as *u8, "you" as *u8, "-" as *u8) 43 ln_add_stage(LG_STORE, "tomc" as *u8, ST_SPROUT, "2025-03-25" as *u8, "Greenhouse" as *u8, "you" as *u8, "-" as *u8) 44 ln_add_stage(LG_STORE, "tomc" as *u8, ST_GROW, "2025-05-01" as *u8, "Bed 3" as *u8, "you" as *u8, "-" as *u8) 45 ln_add_stage(LG_STORE, "tomc" as *u8, ST_HARVEST, "2025-08-10" as *u8, "Bed 3" as *u8, "you" as *u8, "-" as *u8) 46 ln_add_stage(LG_STORE, "tomc" as *u8, ST_PROCESS, "2025-08-11" as *u8, "Kitchen" as *u8, "you" as *u8, "washed" as *u8) 47 ln_add_stage(LG_STORE, "tomc" as *u8, ST_DISTRIBUTE, "2025-08-11" as *u8, "Table" as *u8, "you" as *u8, "-" as *u8) 48 ln_add_stage(LG_STORE, "tomc" as *u8, ST_EAT, "2025-08-12" as *u8, "Table" as *u8, "family" as *u8, "dinner" as *u8) 49 50 // --- ANIMAL lineage: a heritage breed hen, parent -> offspring --- 51 ln_add(LG_STORE, "henp" as *u8, "Plymouth Rock (dam)" as *u8, "animal" as *u8, "Barred Plymouth Rock" as *u8, 1, "-" as *u8, "-" as *u8, "bought" as *u8, "Heritage hatchery" as *u8, "perma_a8_regenerative_ag" as *u8) 52 ln_add(LG_STORE, "henc" as *u8, "Plymouth Rock (chick)" as *u8, "animal" as *u8, "Barred Plymouth Rock" as *u8, 2, "henp" as *u8, "-" as *u8, "saved" as *u8, "self" as *u8, "perma_a8_regenerative_ag" as *u8) 53 ln_set_gene(LG_STORE, "henc" as *u8, 88, 85, 90, 80, 88, "Nishi flock record 2025" as *u8, "perma_a8_regenerative_ag" as *u8) 54 55 var pass: i64 = 0 56 var tot: i64 = 0 57 58 // T1 GENEALOGY: lineage walk 59 let anc: *u8 = sys_mmap(512) 60 let gens: i64 = ln_ancestry(LG_STORE, "tomc" as *u8, anc) 61 g_p("ancestry: " as *u8); g_p(anc); g_p(" (gens=" as *u8); g_i(gens); g_p(")\n" as *u8) 62 let pa: *u8 = sys_mmap(64); ln_field_str(LG_STORE, "tomc" as *u8, 4, pa) 63 tot = tot + 1 64 var ok1: i64 = 1 65 if fd_streq(anc, "tomc <- tomp <- tomgp" as *u8) != 1 { ok1 = 0 } 66 if gens != 2 { ok1 = 0 } 67 if fd_streq(pa, "tomp" as *u8) != 1 { ok1 = 0 } 68 if ok1 == 1 { pass = pass + 1; g_p("PASS T1 genealogy: 3-generation lineage walked (tomc <- tomp <- tomgp)\n" as *u8) } else { g_p("FAIL T1\n" as *u8) } 69 70 // T2 SEED SWAPPING provenance 71 let org: *u8 = sys_mmap(32); ln_field_str(LG_STORE, "tomc" as *u8, 6, org) 72 let src: *u8 = sys_mmap(96); ln_field_str(LG_STORE, "tomc" as *u8, 7, src) 73 let org0: *u8 = sys_mmap(32); ln_field_str(LG_STORE, "tomgp" as *u8, 6, org0) 74 tot = tot + 1 75 var ok2: i64 = 1 76 if fd_streq(org, "swapped" as *u8) != 1 { ok2 = 0 } 77 if fd_streq(src, "Neighbor Maria" as *u8) != 1 { ok2 = 0 } 78 if fd_streq(org0, "saved" as *u8) != 1 { ok2 = 0 } 79 if ok2 == 1 { pass = pass + 1; g_p("PASS T2 seed swapping recorded: tomc origin=swapped from 'Neighbor Maria'; founder=saved\n" as *u8) } else { g_p("FAIL T2\n" as *u8) } 80 81 // T3 LIFECYCLE seed->feed, ADDITIVE 82 let nstg: i64 = ln_stagen(LG_STORE, "tomc" as *u8) 83 let first: i64 = ln_stage_code(LG_STORE, "tomc" as *u8, 0) 84 let last: i64 = ln_stage_code(LG_STORE, "tomc" as *u8, 7) 85 // additive proof: re-add SEED with a bogus date -> no-op; original date preserved, count unchanged 86 ln_add_stage(LG_STORE, "tomc" as *u8, ST_SEED, "9999-99-99" as *u8, "x" as *u8, "x" as *u8, "x" as *u8) 87 let nstg2: i64 = ln_stagen(LG_STORE, "tomc" as *u8) 88 let d0: *u8 = sys_mmap(32); ln_stage_field(LG_STORE, "tomc" as *u8, 0, 1, d0) 89 g_p("stages=" as *u8); g_i(nstg); g_p(" first=" as *u8); g_i(first); g_p(" last=" as *u8); g_i(last); g_p(" seed-date=" as *u8); g_p(d0); g_p("\n" as *u8) 90 tot = tot + 1 91 var ok3: i64 = 1 92 if nstg != 8 { ok3 = 0 } 93 if first != ST_SEED { ok3 = 0 } 94 if last != ST_EAT { ok3 = 0 } 95 if nstg2 != 8 { ok3 = 0 } // re-add was a no-op 96 if fd_streq(d0, "2025-03-01" as *u8) != 1 { ok3 = 0 } // history immutable 97 if ln_reached_plate(LG_STORE, "tomc" as *u8) != 1 { ok3 = 0 } 98 if ok3 == 1 { pass = pass + 1; g_p("PASS T3 lifecycle seed->feed: 8 ordered stages, additive (re-add no-op, history immutable)\n" as *u8) } else { g_p("FAIL T3\n" as *u8) } 99 100 // T4 GENETIC superiority/inferiority + you-are-what-you-eat 101 let qc: i64 = ln_quality_score(LG_STORE, "tomc" as *u8) 102 let qb: i64 = ln_quality_score(LG_STORE, "tombad" as *u8) 103 let pq_c: i64 = ln_plate_quality(LG_STORE, "tomc" as *u8) 104 let pq_b: i64 = ln_plate_quality(LG_STORE, "tombad" as *u8) 105 g_p("quality: tomc=" as *u8); g_i(qc); g_p(" (superior=" as *u8); g_i(ln_is_superior(LG_STORE, "tomc" as *u8)); g_p(") tombad=" as *u8); g_i(qb); g_p(" plate(tomc)=" as *u8); g_i(pq_c); g_p(" plate(tombad)=" as *u8); g_i(pq_b); g_p("\n" as *u8) 106 tot = tot + 1 107 var ok4: i64 = 1 108 if ln_is_superior(LG_STORE, "tomc" as *u8) != 1 { ok4 = 0 } // superior strain 109 if ln_is_superior(LG_STORE, "tombad" as *u8) != 0 { ok4 = 0 } // inferior strain 110 if qc <= qb { ok4 = 0 } 111 if pq_c != qc { ok4 = 0 } // you-are-what-you-eat: plate carries the quality 112 if pq_b != (0 - 1) { ok4 = 0 } // tombad never eaten -> no plate provenance (honest -1) 113 if ok4 == 1 { pass = pass + 1; g_p("PASS T4 genetic superiority scored (tomc superior, tombad inferior) + plate quality requires real chain-of-custody\n" as *u8) } else { g_p("FAIL T4\n" as *u8) } 114 115 // T5 ANIMALS too 116 let hanc: *u8 = sys_mmap(256); let hgens: i64 = ln_ancestry(LG_STORE, "henc" as *u8, hanc) 117 let hkind: *u8 = sys_mmap(32); ln_field_str(LG_STORE, "henc" as *u8, 1, hkind) 118 g_p("animal: " as *u8); g_p(hanc); g_p(" kind=" as *u8); g_p(hkind); g_p(" superior=" as *u8); g_i(ln_is_superior(LG_STORE, "henc" as *u8)); g_p("\n" as *u8) 119 tot = tot + 1 120 var ok5: i64 = 1 121 if fd_streq(hkind, "animal" as *u8) != 1 { ok5 = 0 } 122 if fd_streq(hanc, "henc <- henp" as *u8) != 1 { ok5 = 0 } 123 if hgens != 1 { ok5 = 0 } 124 if ln_is_superior(LG_STORE, "henc" as *u8) != 1 { ok5 = 0 } 125 if ok5 == 1 { pass = pass + 1; g_p("PASS T5 animals too: heritage hen lineage + genetics (same substrate as plants)\n" as *u8) } else { g_p("FAIL T5\n" as *u8) } 126 127 // T6 PASSPORT renders + ships 128 let page: *u8 = sys_mmap(65536) 129 let np: i64 = ln_render_passport(LG_STORE, "tomc" as *u8, page) 130 g_p("passport = " as *u8); g_i(np); g_p(" bytes\n" as *u8) 131 tot = tot + 1 132 var ok6: i64 = 1 133 if as_has_thirdparty_js(page, np) != 0 { ok6 = 0 } 134 if as_contains(page, np, "tomc &lt;- tomp &lt;- tomgp" as *u8) != 1 { ok6 = 0 } // ancestry HTML-escaped (rule 12) 135 if as_contains(page, np, "Superior strain" as *u8) != 1 { ok6 = 0 } 136 if as_contains(page, np, "you are what you eat" as *u8) != 1 { ok6 = 0 } 137 if as_contains(page, np, "Seed" as *u8) != 1 { ok6 = 0 } 138 if as_contains(page, np, "does not perform DNA sequencing" as *u8) != 1 { ok6 = 0 } // honest disclaimer present 139 sys_mkdir("knowledge/staging" as *u8, 0x1ed) 140 sys_mkdir("knowledge/staging/bio" as *u8, 0x1ed) 141 let sfd: i64 = sys_openat_wr(LG_STAGE_FILE, 420); if sfd >= 0 { sys_write(sfd, page, np); sys_close(sfd) } 142 pub_init() 143 sys_mkdir("knowledge/publish/bio-stage" as *u8, 0x1ed) 144 sys_mkdir("knowledge/publish/bio-live" as *u8, 0x1ed) 145 pub_submit_to("knowledge/publish/bio-queue.tsv" as *u8, LG_STAGE_FILE, "tomato_passport.html" as *u8, "nishifoodfamily" as *u8, "nishi-bio" as *u8, "internal" as *u8) 146 pub_run_full("knowledge/publish/bio-queue.tsv" as *u8, "knowledge/publish/bio-ledger.tsv" as *u8, "knowledge/publish/bio-stage" as *u8, "knowledge/publish/bio-live" as *u8, "publish:bio" as *u8) 147 if g_exists(LG_LIVE_FILE) != 1 { ok6 = 0 } 148 if ok6 == 1 { pass = pass + 1; g_p("PASS T6 sovereign seed-to-feed passport rendered + shipped (genealogy + trace + quality)\n" as *u8) } else { g_p("FAIL T6\n" as *u8) } 149 150 g_p("nx_lineage_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot) 151 if pass == tot { g_p(" verdict=GREEN (seed to feed: genealogy + lifecycle + genetic quality, plants AND animals, sovereign)\n" as *u8); return 0 } 152 g_p(" verdict=RED\n" as *u8) 153 return 1 154}