code wiki / _hdl_build / nx_lineage_gate.nx

nx_lineage_gate.nx source

↩ module page · 161 lines · 11511 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" 10import "nx_gate_verdict.nx" 11 12const LG_STORE: *u8 = "knowledge/store/bio-" 13const LG_STAGE_FILE: *u8 = "knowledge/staging/bio/tomato_passport.html" 14const LG_LIVE_FILE: *u8 = "knowledge/publish/bio-live/tomato_passport.html" 15 16func 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 } 17func g_i(v: i64) -> i64 { 18 let bb: *u8 = sys_mmap(28); var m: i64 = v 19 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 20 let t: *u8 = sys_mmap(28); var k: i64 = 0 21 if m == 0 { t[0] = 48 as u8; k = 1 } 22 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 23 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0 24} 25func g_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 } 26 27func main() -> i64 { 28 g_p("=== nx_lineage_gate (seed-to-feed traceability R0) ===\n" as *u8) 29 ln_seed_config(LG_STORE) 30 31 // --- PLANT lineage: a 3-generation heirloom tomato, the youngest swapped from a neighbor --- 32 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) 33 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) 34 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) 35 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) 36 37 // genetics (recorded markers): tomc superior, tombad inferior 38 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) 39 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) 40 41 // lifecycle seed->feed for tomc (8 ordered stages) 42 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) 43 ln_add_stage(LG_STORE, "tomc" as *u8, ST_SOWN, "2025-03-15" as *u8, "Greenhouse" as *u8, "you" as *u8, "-" as *u8) 44 ln_add_stage(LG_STORE, "tomc" as *u8, ST_SPROUT, "2025-03-25" as *u8, "Greenhouse" as *u8, "you" as *u8, "-" as *u8) 45 ln_add_stage(LG_STORE, "tomc" as *u8, ST_GROW, "2025-05-01" as *u8, "Bed 3" as *u8, "you" as *u8, "-" as *u8) 46 ln_add_stage(LG_STORE, "tomc" as *u8, ST_HARVEST, "2025-08-10" as *u8, "Bed 3" as *u8, "you" as *u8, "-" as *u8) 47 ln_add_stage(LG_STORE, "tomc" as *u8, ST_PROCESS, "2025-08-11" as *u8, "Kitchen" as *u8, "you" as *u8, "washed" as *u8) 48 ln_add_stage(LG_STORE, "tomc" as *u8, ST_DISTRIBUTE, "2025-08-11" as *u8, "Table" as *u8, "you" as *u8, "-" as *u8) 49 ln_add_stage(LG_STORE, "tomc" as *u8, ST_EAT, "2025-08-12" as *u8, "Table" as *u8, "family" as *u8, "dinner" as *u8) 50 51 // --- ANIMAL lineage: a heritage breed hen, parent -> offspring --- 52 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) 53 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) 54 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) 55 56 var pass: i64 = 0 57 var tot: i64 = 0 58 59 // T1 GENEALOGY: lineage walk 60 let anc: *u8 = sys_mmap(512) 61 let gens: i64 = ln_ancestry(LG_STORE, "tomc" as *u8, anc) 62 g_p("ancestry: " as *u8); g_p(anc); g_p(" (gens=" as *u8); g_i(gens); g_p(")\n" as *u8) 63 let pa: *u8 = sys_mmap(64); ln_field_str(LG_STORE, "tomc" as *u8, 4, pa) 64 tot = tot + 1 65 var ok1: i64 = 1 66 if fd_streq(anc, "tomc <- tomp <- tomgp" as *u8) != 1 { ok1 = 0 } 67 if gens != 2 { ok1 = 0 } 68 if fd_streq(pa, "tomp" as *u8) != 1 { ok1 = 0 } 69 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) } 70 71 // T2 SEED SWAPPING provenance 72 let org: *u8 = sys_mmap(32); ln_field_str(LG_STORE, "tomc" as *u8, 6, org) 73 let src: *u8 = sys_mmap(96); ln_field_str(LG_STORE, "tomc" as *u8, 7, src) 74 let org0: *u8 = sys_mmap(32); ln_field_str(LG_STORE, "tomgp" as *u8, 6, org0) 75 tot = tot + 1 76 var ok2: i64 = 1 77 if fd_streq(org, "swapped" as *u8) != 1 { ok2 = 0 } 78 if fd_streq(src, "Neighbor Maria" as *u8) != 1 { ok2 = 0 } 79 if fd_streq(org0, "saved" as *u8) != 1 { ok2 = 0 } 80 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) } 81 82 // T3 LIFECYCLE seed->feed, ADDITIVE 83 let nstg: i64 = ln_stagen(LG_STORE, "tomc" as *u8) 84 let first: i64 = ln_stage_code(LG_STORE, "tomc" as *u8, 0) 85 let last: i64 = ln_stage_code(LG_STORE, "tomc" as *u8, 7) 86 // additive proof: re-add SEED with a bogus date -> no-op; original date preserved, count unchanged 87 ln_add_stage(LG_STORE, "tomc" as *u8, ST_SEED, "9999-99-99" as *u8, "x" as *u8, "x" as *u8, "x" as *u8) 88 let nstg2: i64 = ln_stagen(LG_STORE, "tomc" as *u8) 89 let d0: *u8 = sys_mmap(32); ln_stage_field(LG_STORE, "tomc" as *u8, 0, 1, d0) 90 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) 91 tot = tot + 1 92 var ok3: i64 = 1 93 if nstg != 8 { ok3 = 0 } 94 if first != ST_SEED { ok3 = 0 } 95 if last != ST_EAT { ok3 = 0 } 96 if nstg2 != 8 { ok3 = 0 } // re-add was a no-op 97 if fd_streq(d0, "2025-03-01" as *u8) != 1 { ok3 = 0 } // history immutable 98 if ln_reached_plate(LG_STORE, "tomc" as *u8) != 1 { ok3 = 0 } 99 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) } 100 101 // T4 GENETIC superiority/inferiority + you-are-what-you-eat 102 let qc: i64 = ln_quality_score(LG_STORE, "tomc" as *u8) 103 let qb: i64 = ln_quality_score(LG_STORE, "tombad" as *u8) 104 let pq_c: i64 = ln_plate_quality(LG_STORE, "tomc" as *u8) 105 let pq_b: i64 = ln_plate_quality(LG_STORE, "tombad" as *u8) 106 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) 107 tot = tot + 1 108 var ok4: i64 = 1 109 if ln_is_superior(LG_STORE, "tomc" as *u8) != 1 { ok4 = 0 } // superior strain 110 if ln_is_superior(LG_STORE, "tombad" as *u8) != 0 { ok4 = 0 } // inferior strain 111 if qc <= qb { ok4 = 0 } 112 if pq_c != qc { ok4 = 0 } // you-are-what-you-eat: plate carries the quality 113 if pq_b != (0 - 1) { ok4 = 0 } // tombad never eaten -> no plate provenance (honest -1) 114 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) } 115 116 // T5 ANIMALS too 117 let hanc: *u8 = sys_mmap(256); let hgens: i64 = ln_ancestry(LG_STORE, "henc" as *u8, hanc) 118 let hkind: *u8 = sys_mmap(32); ln_field_str(LG_STORE, "henc" as *u8, 1, hkind) 119 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) 120 tot = tot + 1 121 var ok5: i64 = 1 122 if fd_streq(hkind, "animal" as *u8) != 1 { ok5 = 0 } 123 if fd_streq(hanc, "henc <- henp" as *u8) != 1 { ok5 = 0 } 124 if hgens != 1 { ok5 = 0 } 125 if ln_is_superior(LG_STORE, "henc" as *u8) != 1 { ok5 = 0 } 126 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) } 127 128 // T6 PASSPORT renders + ships 129 let page: *u8 = sys_mmap(65536) 130 let np: i64 = ln_render_passport(LG_STORE, "tomc" as *u8, page) 131 g_p("passport = " as *u8); g_i(np); g_p(" bytes\n" as *u8) 132 tot = tot + 1 133 var ok6: i64 = 1 134 if as_has_thirdparty_js(page, np) != 0 { ok6 = 0 } 135 if as_contains(page, np, "tomc &lt;- tomp &lt;- tomgp" as *u8) != 1 { ok6 = 0 } // ancestry HTML-escaped (rule 12) 136 if as_contains(page, np, "Superior strain" as *u8) != 1 { ok6 = 0 } 137 if as_contains(page, np, "you are what you eat" as *u8) != 1 { ok6 = 0 } 138 if as_contains(page, np, "Seed" as *u8) != 1 { ok6 = 0 } 139 if as_contains(page, np, "does not perform DNA sequencing" as *u8) != 1 { ok6 = 0 } // honest disclaimer present 140 sys_mkdir("knowledge/staging" as *u8, 0x1ed) 141 sys_mkdir("knowledge/staging/bio" as *u8, 0x1ed) 142 let sfd: i64 = sys_openat_wr(LG_STAGE_FILE, 420); if sfd >= 0 { sys_write(sfd, page, np); sys_close(sfd) } 143 pub_init() 144 sys_mkdir("knowledge/publish/bio-stage" as *u8, 0x1ed) 145 sys_mkdir("knowledge/publish/bio-live" as *u8, 0x1ed) 146 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) 147 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) 148 if g_exists(LG_LIVE_FILE) != 1 { ok6 = 0 } 149 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) } 150 151 g_p("nx_lineage_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot) 152 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 153 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 154 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 155 let ctr__dry: *i64 = gv_ctr() 156 ctr__dry[0] = pass 157 ctr__dry[1] = tot 158 let rc__dry: i64 = gv_verdict("LINEAGE-GATE" as *u8, ctr__dry, "seed to feed: genealogy + lifecycle + genetic quality, plants AND animals, sovereign)" as *u8) 159 sys_exit(rc__dry) 160 return rc__dry 161}