code wiki / _hdl_build / nx_garden_gate.nx

nx_garden_gate.nx source

↩ module page · 152 lines · 8157 B

1// nx_garden_gate.nx -- GATE: R-GARDEN. The grow-your-own affordability engine, grounded in the permaculture 2// research corpus. Proves: T1 growable model (veg/aromatics growable, proteins/processed sauces not), T2 3// buy-vs-grow savings (integer cents, no float), T3 research-grounded (crops CITE real perma_*.raw sources -- 4// not bro science), T4 a cooked meal's growable ingredients carry real savings, T5 sovereign grow-plan render 5// with an annual projection, T6 SHIPPED via publisher. license_tier: ORIGINAL 6import "nx_garden.nx" 7import "nx_food_provenance.nx" 8import "nx_food_science.nx" 9import "nx_publisher.nx" 10import "nx_syscalls.nx" 11import "nx_gate_verdict.nx" 12 13const GG_FOOD: *u8 = "knowledge/store/food-" 14const GG_Q: *u8 = "knowledge/publish/garden-queue.tsv" 15const GG_LED: *u8 = "knowledge/publish/garden-ledger.tsv" 16const GG_STG: *u8 = "knowledge/publish/garden-stage" 17const GG_LIVE: *u8 = "knowledge/publish/garden-live" 18const GG_STAGE_FILE: *u8 = "knowledge/staging/garden/plan.html" 19const GG_LIVE_FILE: *u8 = "knowledge/publish/garden-live/grow-plan.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_garden_gate (R-GARDEN: grow-your-own affordability, grounded in the permaculture corpus) ===\n" as *u8) 34 fd_seed(GG_FOOD) 35 let cw: i64 = gd_seed(GG_FOOD) 36 g_p("garden crops authored this run=" as *u8); g_i(cw); g_p("\n" as *u8) 37 38 let world: *i64 = fd_world_open(GG_FOOD) 39 let names: *i64 = world[4] as *i64 40 41 var pass: i64 = 0 42 var tot: i64 = 0 43 44 // T1 growable model 45 tot = tot + 1 46 var ok1: i64 = 1 47 if gd_growable(GG_FOOD, "onion" as *u8) != 1 { ok1 = 0 } 48 if gd_growable(GG_FOOD, "garlic" as *u8) != 1 { ok1 = 0 } 49 if gd_growable(GG_FOOD, "beef" as *u8) != 0 { ok1 = 0 } // you don't grow beef in a garden 50 if gd_growable(GG_FOOD, "soy" as *u8) != 0 { ok1 = 0 } // processed sauce, not a crop 51 if ok1 == 1 { pass = pass + 1; g_p("PASS T1 growable model (veg/aromatics grow, proteins/sauces don't)\n" as *u8) } else { g_p("FAIL T1\n" as *u8) } 52 53 // T2 buy-vs-grow savings 54 let sav_onion: i64 = gd_savings(GG_FOOD, "onion" as *u8) 55 let sav_garlic: i64 = gd_savings(GG_FOOD, "garlic" as *u8) 56 g_p("savings/unit: onion=" as *u8); g_i(sav_onion); g_p("c garlic=" as *u8); g_i(sav_garlic); g_p("c\n" as *u8) 57 tot = tot + 1 58 var ok2: i64 = 1 59 if sav_onion != 85 { ok2 = 0 } // buy 100 - grow 15 60 if sav_garlic != 88 { ok2 = 0 } // buy 100 - grow 12 61 if gd_savings(GG_FOOD, "beef" as *u8) != 0 { ok2 = 0 } 62 if ok2 == 1 { pass = pass + 1; g_p("PASS T2 buy-vs-grow savings exact (onion 85c, garlic 88c per unit, no float)\n" as *u8) } else { g_p("FAIL T2\n" as *u8) } 63 64 // T3 research-grounded: every crop cites a real permaculture source 65 let pq: *i64 = sys_mmap(16) as *i64 66 let lq: *i64 = sys_mmap(16) as *i64 67 var grounded: i64 = 0 68 var ncrop: i64 = 0 69 if ss_get(GG_FOOD, "garden:cropids" as *u8, pq, lq) == 1 { 70 let buf: *u8 = pq[0] as *u8 71 let blen: i64 = lq[0] 72 var i: i64 = 0 73 var ls: i64 = 0 74 while i <= blen { 75 var sep: i64 = 0 76 if i == blen { sep = 1 } else { if buf[i] == (9 as u8) { sep = 1 } } 77 if sep == 1 { 78 let tl: i64 = i - ls 79 if tl > 0 { 80 let id: *u8 = sys_mmap(48) 81 var t: i64 = 0 82 while t < tl { id[t] = buf[ls + t]; t = t + 1 } id[tl] = 0 as u8 83 ncrop = ncrop + 1 84 let cite: *u8 = sys_mmap(64) 85 gd_field_str(GG_FOOD, id, 5, cite) 86 if fd_sci_cited(cite) == 1 { grounded = grounded + 1 } 87 } 88 ls = i + 1 89 } 90 i = i + 1 91 } 92 } 93 g_p("crops grounded in real permaculture sources: " as *u8); g_i(grounded); g_p("/" as *u8); g_i(ncrop); g_p("\n" as *u8) 94 tot = tot + 1 95 if grounded >= 10 { pass = pass + 1; g_p("PASS T3 research-grounded (>=10/15 crops cite a fetched permaculture source)\n" as *u8) } else { g_p("FAIL T3 only " as *u8); g_i(grounded); g_p(" grounded -- resume nx_perma_research_fetch\n" as *u8) } 96 97 // T4 a cooked meal's growable ingredients carry savings 98 let avail: *i64 = sys_mmap(8 * 64) as *i64 99 let avoid: *i64 = sys_mmap(8 * 64) as *i64 100 let prefw: *i64 = sys_mmap(8 * 8) as *i64 101 let n: i64 = world[0] 102 fd_set_all(avail, n, 1); fd_set_all(avoid, n, 0) 103 var z: i64 = 0; while z < FOOD_NAX { prefw[z] = 0; z = z + 1 } 104 let frame: *i64 = sys_mmap(8 * 16) as *i64; let nframe: i64 = fd_load_frame(GG_FOOD, frame) 105 let wts: *i64 = sys_mmap(8 * 8) as *i64; fd_load_weights(GG_FOOD, wts) 106 let build: *i64 = sys_mmap(8 * 16) as *i64; let roles: *i64 = sys_mmap(8 * 16) as *i64 107 let nb: i64 = fd_choose(world, avail, avoid, prefw, frame, nframe, wts, build, roles) 108 let og: *i64 = sys_mmap(16) as *i64 109 let mealsav: i64 = gd_meal_savings(GG_FOOD, world, build, nb, og) 110 g_p("cooked: " as *u8) 111 var si: i64 = 0; while si < nb { if si > 0 { g_p(" | " as *u8) } g_p(names[build[si]] as *u8); si = si + 1 } 112 g_p(" -> grow " as *u8); g_i(og[0]); g_p(" of them, save " as *u8); g_i(mealsav); g_p("c/meal\n" as *u8) 113 tot = tot + 1 114 var ok4: i64 = 1 115 if og[0] < 3 { ok4 = 0 } 116 if mealsav <= 0 { ok4 = 0 } 117 if ok4 == 1 { pass = pass + 1; g_p("PASS T4 meal affordability (>=3 growable ingredients, real per-meal savings)\n" as *u8) } else { g_p("FAIL T4\n" as *u8) } 118 119 // T5 sovereign grow-plan render with an annual projection 120 let page: *u8 = sys_mmap(65536) 121 let np: i64 = gd_render_plan(GG_FOOD, world, build, nb, 3, page) 122 tot = tot + 1 123 var ok5: i64 = 1 124 if as_has_thirdparty_js(page, np) != 0 { ok5 = 0 } 125 if as_contains(page, np, "a year" as *u8) != 1 { ok5 = 0 } 126 if as_contains(page, np, "You save" as *u8) != 1 { ok5 = 0 } 127 if ok5 == 1 { pass = pass + 1; g_p("PASS T5 sovereign grow-plan with annual savings projection (" as *u8); g_i(np); g_p(" bytes, 0 JS)\n" as *u8) } else { g_p("FAIL T5\n" as *u8) } 128 129 // T6 ship 130 sys_mkdir("knowledge/staging" as *u8, 0x1ed) 131 sys_mkdir("knowledge/staging/garden" as *u8, 0x1ed) 132 let sfd: i64 = sys_openat_wr(GG_STAGE_FILE, 420); if sfd >= 0 { sys_write(sfd, page, np); sys_close(sfd) } 133 pub_init() 134 sys_mkdir(GG_STG, 0x1ed) 135 sys_mkdir(GG_LIVE, 0x1ed) 136 pub_submit_to(GG_Q, GG_STAGE_FILE, "grow-plan.html" as *u8, "nishifamily" as *u8, "nishi-garden" as *u8, "internal" as *u8) 137 let pubd: i64 = pub_run_full(GG_Q, GG_LED, GG_STG, GG_LIVE, "publish:garden" as *u8) 138 g_p(" pub_run_full -> published_this_pass=" as *u8); g_i(pubd); g_p("\n" as *u8) 139 tot = tot + 1 140 if g_exists(GG_LIVE_FILE) == 1 { pass = pass + 1; g_p("PASS T6 SHIPPED the grow-your-own plan to liveroot\n" as *u8) } else { g_p("FAIL T6\n" as *u8) } 141 142 g_p("nx_garden_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot) 143 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 144 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 145 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 146 let ctr__dry: *i64 = gv_ctr() 147 ctr__dry[0] = pass 148 ctr__dry[1] = tot 149 let rc__dry: i64 = gv_verdict("GARDEN-GATE" as *u8, ctr__dry, "grow-your-own affordability, grounded in the permaculture corpus, shipped)" as *u8) 150 sys_exit(rc__dry) 151 return rc__dry 152}