code wiki / _hdl_build / nx_activities_gate.nx
nx_activities_gate.nx source
↩ module page · 144 lines · 8524 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"
11import "nx_gate_verdict.nx"
12
13const AG_ACT: *u8 = "knowledge/store/act-"
14const AG_REWARD: *u8 = "knowledge/store/actrw-reward-"
15const AG_STAGE_FILE: *u8 = "knowledge/staging/act/positives.html"
16const AG_LIVE_FILE: *u8 = "knowledge/publish/act-live/positives.html"
17
18func 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 }
19func g_i(v: i64) -> i64 {
20 let bb: *u8 = sys_mmap(28); var m: i64 = v
21 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
22 let t: *u8 = sys_mmap(28); var k: i64 = 0
23 if m == 0 { t[0] = 48 as u8; k = 1 }
24 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
25 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0
26}
27func g_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
28func 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 }
29func g_num(dst: *u8, off: i64, n: i64) -> i64 {
30 var m: i64 = n; if m < 0 { m = 0 }
31 let t: *u8 = sys_mmap(28); var k: i64 = 0
32 if m == 0 { t[0] = 48 as u8; k = 1 }
33 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
34 var i: i64 = 0; while i < k { dst[off+i] = t[k-1-i]; i = i + 1 }
35 return off + k
36}
37
38func main() -> i64 {
39 g_p("=== nx_activities_gate (real value for lots of popular activities) ===\n" as *u8)
40
41 // PER-RUN ISOLATED store namespaces (rule 10 idempotency; segid=now_us convention). ROOT-CAUSE FIX
42 // 2026-07-14: the fixed shared prefixes accumulated act rows across runs -- a SECOND run saw sam's
43 // total DOUBLE (56000 vs 28000) and the rendered page said $560.00 -> T4+T6 false-RED. A gate must
44 // be safe to run twice; fresh per-run namespaces make every run measure exactly THIS run's season.
45 let actp: *u8 = sys_mmap(256)
46 var ao: i64 = 0
47 ao = g_cat(actp, ao, AG_ACT)
48 ao = g_num(actp, ao, sys_now_us())
49 actp[ao] = 45 as u8
50 actp[ao+1] = 0 as u8
51 let rwp: *u8 = sys_mmap(256)
52 var ro: i64 = 0
53 ro = g_cat(rwp, ro, AG_REWARD)
54 ro = g_num(rwp, ro, sys_now_us())
55 rwp[ro] = 45 as u8
56 rwp[ro+1] = 0 as u8
57
58 // grounded reference prices (each with a source)
59 ac_set_ref(actp, "compost_cuft" as *u8, 500, "cuft" as *u8, "garden-center price" as *u8)
60 ac_set_ref(actp, "seed_packet" as *u8, 300, "packet" as *u8, "seed-catalog price" as *u8)
61 ac_set_ref(actp, "takeout_meal" as *u8, 1500, "meal" as *u8, "menu price" as *u8)
62 ac_set_ref(actp, "home_meal" as *u8, 400, "meal" as *u8, "ingredient cost" as *u8)
63 ac_set_ref(actp, "preserve_jar" as *u8, 600, "jar" as *u8, "retail jar price" as *u8)
64 ac_set_ref(actp, "water_100gal" as *u8, 80, "100gal" as *u8, "water-utility rate" as *u8)
65
66 // Sam's season of popular activities
67 ac_log(actp, "sam" as *u8, "compost" as *u8, 10, 100, "kitchen + yard" as *u8)
68 ac_log(actp, "sam" as *u8, "seedsave" as *u8, 12, 110, "tomato + herb seed" as *u8)
69 ac_log(actp, "sam" as *u8, "cookpantry" as *u8, 8, 120, "weeknight dinners" as *u8)
70 ac_log(actp, "sam" as *u8, "preserve" as *u8, 15, 130, "summer glut" as *u8)
71 ac_log(actp, "sam" as *u8, "rainwater" as *u8, 20, 140, "two barrels" as *u8)
72
73 var pass: i64 = 0
74 var tot: i64 = 0
75
76 // T1 references grounded
77 tot = tot + 1
78 var ok1: i64 = 1
79 if ac_ref(actp, "compost_cuft" as *u8) != 500 { ok1 = 0 }
80 if ac_ref(actp, "takeout_meal" as *u8) != 1500 { ok1 = 0 }
81 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) }
82
83 // T2 compost value = ref x qty
84 let cv: i64 = ac_value_of(actp, "compost" as *u8, 10)
85 g_p("compost 10 cuft -> " as *u8); g_i(cv); g_p("c\n" as *u8)
86 tot = tot + 1
87 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) }
88
89 // T3 cook-from-pantry = NET savings (takeout - home)
90 let kv: i64 = ac_value_of(actp, "cookpantry" as *u8, 8)
91 g_p("cookpantry 8 meals -> " as *u8); g_i(kv); g_p("c\n" as *u8)
92 tot = tot + 1
93 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) }
94
95 // T4 multi-activity total
96 let total: i64 = ac_user_value(actp, "sam" as *u8)
97 g_p("sam total real value = " as *u8); g_i(total); g_p("c\n" as *u8)
98 tot = tot + 1
99 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) }
100
101 // T5 honest zeros
102 let z1: i64 = ac_value_of(actp, "cookpantry" as *u8, 0)
103 let z2: i64 = ac_value_of(actp, "tiktokdance" as *u8, 5)
104 g_p("zero-qty=" as *u8); g_i(z1); g_p(" unknown-activity=" as *u8); g_i(z2); g_p("\n" as *u8)
105 tot = tot + 1
106 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) }
107
108 // T6 compose with rewards + render + ship
109 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)
110 rw_grant(rwp, "sam" as *u8, "homestead_season" as *u8, 150)
111 let rv: i64 = rw_value_total(rwp, "sam" as *u8)
112 let page: *u8 = sys_mmap(65536)
113 let np: i64 = ac_render(actp, "sam" as *u8, page)
114 g_p("reward value=" as *u8); g_i(rv); g_p(" page=" as *u8); g_i(np); g_p(" bytes\n" as *u8)
115 tot = tot + 1
116 var ok6: i64 = 1
117 if rv != 28000 { ok6 = 0 } // the activity value became a REAL reward
118 if as_has_thirdparty_js(page, np) != 0 { ok6 = 0 }
119 if as_contains(page, np, "$280.00" as *u8) != 1 { ok6 = 0 }
120 if as_contains(page, np, "Composting" as *u8) != 1 { ok6 = 0 }
121 if as_contains(page, np, "Cooking from the pantry" as *u8) != 1 { ok6 = 0 }
122 if as_contains(page, np, "real money kept" as *u8) != 1 { ok6 = 0 }
123 sys_mkdir("knowledge/staging" as *u8, 0x1ed)
124 sys_mkdir("knowledge/staging/act" as *u8, 0x1ed)
125 let sfd: i64 = sys_openat_wr(AG_STAGE_FILE, 420); if sfd >= 0 { sys_write(sfd, page, np); sys_close(sfd) }
126 pub_init()
127 sys_mkdir("knowledge/publish/act-stage" as *u8, 0x1ed)
128 sys_mkdir("knowledge/publish/act-live" as *u8, 0x1ed)
129 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)
130 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)
131 if g_exists(AG_LIVE_FILE) != 1 { ok6 = 0 }
132 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) }
133
134 g_p("nx_activities_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot)
135 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
136 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
137 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
138 let ctr__dry: *i64 = gv_ctr()
139 ctr__dry[0] = pass
140 ctr__dry[1] = tot
141 let rc__dry: i64 = gv_verdict("ACTIVITIES-GATE" as *u8, ctr__dry, "lots of popular activities, each a REAL measured positive, feeding real rewards)" as *u8)
142 sys_exit(rc__dry)
143 return rc__dry
144}