code wiki / _hdl_build / nx_activities_gate.nx

nx_activities_gate.nx source

↩ module page · 137 lines · 8125 B

1// nx_activities_gate.nx -- GATE: REAL value for LOTS of popular activities. T1 reference prices set (grounded w/ 2// sources). T2 compost value = real ref x quantity (not invented). T3 cook-from-pantry = NET savings (takeout 3// avoided minus home cost). T4 multi-activity total = the real seasonal positive. T5 HONEST: zero-quantity and 4// unknown activity yield 0 (never a fabricated number). T6 composes with nx_rewards (the total becomes a REAL 5// reward) + renders + ships. license_tier: ORIGINAL 6import "nx_activities.nx" 7import "nx_rewards.nx" 8import "nx_publisher.nx" 9import "nx_seg_store.nx" 10import "nx_syscalls.nx" 11 12const AG_ACT: *u8 = "knowledge/store/act-" 13const AG_REWARD: *u8 = "knowledge/store/actrw-reward-" 14const AG_STAGE_FILE: *u8 = "knowledge/staging/act/positives.html" 15const AG_LIVE_FILE: *u8 = "knowledge/publish/act-live/positives.html" 16 17func 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 } 18func g_i(v: i64) -> i64 { 19 let bb: *u8 = sys_mmap(28); var m: i64 = v 20 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 21 let t: *u8 = sys_mmap(28); var k: i64 = 0 22 if m == 0 { t[0] = 48 as u8; k = 1 } 23 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 24 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0 25} 26func g_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 } 27func g_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { dst[off+i] = s[i]; i = i + 1 } return off + i } 28func g_num(dst: *u8, off: i64, n: i64) -> i64 { 29 var m: i64 = n; if m < 0 { m = 0 } 30 let t: *u8 = sys_mmap(28); var k: i64 = 0 31 if m == 0 { t[0] = 48 as u8; k = 1 } 32 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 33 var i: i64 = 0; while i < k { dst[off+i] = t[k-1-i]; i = i + 1 } 34 return off + k 35} 36 37func main() -> i64 { 38 g_p("=== nx_activities_gate (real value for lots of popular activities) ===\n" as *u8) 39 40 // PER-RUN ISOLATED store namespaces (rule 10 idempotency; segid=now_us convention). ROOT-CAUSE FIX 41 // 2026-07-14: the fixed shared prefixes accumulated act rows across runs -- a SECOND run saw sam's 42 // total DOUBLE (56000 vs 28000) and the rendered page said $560.00 -> T4+T6 false-RED. A gate must 43 // be safe to run twice; fresh per-run namespaces make every run measure exactly THIS run's season. 44 let actp: *u8 = sys_mmap(256) 45 var ao: i64 = 0 46 ao = g_cat(actp, ao, AG_ACT) 47 ao = g_num(actp, ao, sys_now_us()) 48 actp[ao] = 45 as u8 49 actp[ao+1] = 0 as u8 50 let rwp: *u8 = sys_mmap(256) 51 var ro: i64 = 0 52 ro = g_cat(rwp, ro, AG_REWARD) 53 ro = g_num(rwp, ro, sys_now_us()) 54 rwp[ro] = 45 as u8 55 rwp[ro+1] = 0 as u8 56 57 // grounded reference prices (each with a source) 58 ac_set_ref(actp, "compost_cuft" as *u8, 500, "cuft" as *u8, "garden-center price" as *u8) 59 ac_set_ref(actp, "seed_packet" as *u8, 300, "packet" as *u8, "seed-catalog price" as *u8) 60 ac_set_ref(actp, "takeout_meal" as *u8, 1500, "meal" as *u8, "menu price" as *u8) 61 ac_set_ref(actp, "home_meal" as *u8, 400, "meal" as *u8, "ingredient cost" as *u8) 62 ac_set_ref(actp, "preserve_jar" as *u8, 600, "jar" as *u8, "retail jar price" as *u8) 63 ac_set_ref(actp, "water_100gal" as *u8, 80, "100gal" as *u8, "water-utility rate" as *u8) 64 65 // Sam's season of popular activities 66 ac_log(actp, "sam" as *u8, "compost" as *u8, 10, 100, "kitchen + yard" as *u8) 67 ac_log(actp, "sam" as *u8, "seedsave" as *u8, 12, 110, "tomato + herb seed" as *u8) 68 ac_log(actp, "sam" as *u8, "cookpantry" as *u8, 8, 120, "weeknight dinners" as *u8) 69 ac_log(actp, "sam" as *u8, "preserve" as *u8, 15, 130, "summer glut" as *u8) 70 ac_log(actp, "sam" as *u8, "rainwater" as *u8, 20, 140, "two barrels" as *u8) 71 72 var pass: i64 = 0 73 var tot: i64 = 0 74 75 // T1 references grounded 76 tot = tot + 1 77 var ok1: i64 = 1 78 if ac_ref(actp, "compost_cuft" as *u8) != 500 { ok1 = 0 } 79 if ac_ref(actp, "takeout_meal" as *u8) != 1500 { ok1 = 0 } 80 if ok1 == 1 { pass = pass + 1; g_p("PASS T1 reference prices set + grounded with sources\n" as *u8) } else { g_p("FAIL T1\n" as *u8) } 81 82 // T2 compost value = ref x qty 83 let cv: i64 = ac_value_of(actp, "compost" as *u8, 10) 84 g_p("compost 10 cuft -> " as *u8); g_i(cv); g_p("c\n" as *u8) 85 tot = tot + 1 86 if cv == 5000 { pass = pass + 1; g_p("PASS T2 composting valued from real price (10 cuft x $5 = $50, not invented)\n" as *u8) } else { g_p("FAIL T2 cv=" as *u8); g_i(cv); g_p("\n" as *u8) } 87 88 // T3 cook-from-pantry = NET savings (takeout - home) 89 let kv: i64 = ac_value_of(actp, "cookpantry" as *u8, 8) 90 g_p("cookpantry 8 meals -> " as *u8); g_i(kv); g_p("c\n" as *u8) 91 tot = tot + 1 92 if kv == 8800 { pass = pass + 1; g_p("PASS T3 cook-from-pantry = NET savings (8 x ($15-$4) = $88)\n" as *u8) } else { g_p("FAIL T3 kv=" as *u8); g_i(kv); g_p("\n" as *u8) } 93 94 // T4 multi-activity total 95 let total: i64 = ac_user_value(actp, "sam" as *u8) 96 g_p("sam total real value = " as *u8); g_i(total); g_p("c\n" as *u8) 97 tot = tot + 1 98 if total == 28000 { pass = pass + 1; g_p("PASS T4 5 popular activities -> $280.00 real value (compost+seed+cook+preserve+rainwater)\n" as *u8) } else { g_p("FAIL T4 total=" as *u8); g_i(total); g_p("\n" as *u8) } 99 100 // T5 honest zeros 101 let z1: i64 = ac_value_of(actp, "cookpantry" as *u8, 0) 102 let z2: i64 = ac_value_of(actp, "tiktokdance" as *u8, 5) 103 g_p("zero-qty=" as *u8); g_i(z1); g_p(" unknown-activity=" as *u8); g_i(z2); g_p("\n" as *u8) 104 tot = tot + 1 105 if z1 == 0 { if z2 == 0 { pass = pass + 1; g_p("PASS T5 honest: zero quantity = 0, unknown/un-grounded activity = 0 (never fabricated)\n" as *u8) } else { g_p("FAIL T5 unknown\n" as *u8) } } else { g_p("FAIL T5 zero\n" as *u8) } 106 107 // T6 compose with rewards + render + ship 108 rw_def_achievement(rwp, "homestead_season" as *u8, "Homestead Season" as *u8, "homestead" as *u8, "VALUE" as *u8, total, "-" as *u8, "activity log" as *u8) 109 rw_grant(rwp, "sam" as *u8, "homestead_season" as *u8, 150) 110 let rv: i64 = rw_value_total(rwp, "sam" as *u8) 111 let page: *u8 = sys_mmap(65536) 112 let np: i64 = ac_render(actp, "sam" as *u8, page) 113 g_p("reward value=" as *u8); g_i(rv); g_p(" page=" as *u8); g_i(np); g_p(" bytes\n" as *u8) 114 tot = tot + 1 115 var ok6: i64 = 1 116 if rv != 28000 { ok6 = 0 } // the activity value became a REAL reward 117 if as_has_thirdparty_js(page, np) != 0 { ok6 = 0 } 118 if as_contains(page, np, "$280.00" as *u8) != 1 { ok6 = 0 } 119 if as_contains(page, np, "Composting" as *u8) != 1 { ok6 = 0 } 120 if as_contains(page, np, "Cooking from the pantry" as *u8) != 1 { ok6 = 0 } 121 if as_contains(page, np, "real money kept" as *u8) != 1 { ok6 = 0 } 122 sys_mkdir("knowledge/staging" as *u8, 0x1ed) 123 sys_mkdir("knowledge/staging/act" as *u8, 0x1ed) 124 let sfd: i64 = sys_openat_wr(AG_STAGE_FILE, 420); if sfd >= 0 { sys_write(sfd, page, np); sys_close(sfd) } 125 pub_init() 126 sys_mkdir("knowledge/publish/act-stage" as *u8, 0x1ed) 127 sys_mkdir("knowledge/publish/act-live" as *u8, 0x1ed) 128 pub_submit_to("knowledge/publish/act-queue.tsv" as *u8, AG_STAGE_FILE, "positives.html" as *u8, "nishifoodfamily" as *u8, "nishi-act" as *u8, "internal" as *u8) 129 pub_run_full("knowledge/publish/act-queue.tsv" as *u8, "knowledge/publish/act-ledger.tsv" as *u8, "knowledge/publish/act-stage" as *u8, "knowledge/publish/act-live" as *u8, "publish:act" as *u8) 130 if g_exists(AG_LIVE_FILE) != 1 { ok6 = 0 } 131 if ok6 == 1 { pass = pass + 1; g_p("PASS T6 activity value became a REAL reward ($280) + sovereign positives page shipped\n" as *u8) } else { g_p("FAIL T6\n" as *u8) } 132 133 g_p("nx_activities_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot) 134 if pass == tot { g_p(" verdict=GREEN (lots of popular activities, each a REAL measured positive, feeding real rewards)\n" as *u8); return 0 } 135 g_p(" verdict=RED\n" as *u8) 136 return 1 137}