code wiki / (root) / nx_maint_simpage.nx

nx_maint_simpage.nx source

↩ module page · 109 lines · 5268 B

1// nx_maint_simpage.nx -- the IN-BROWSER PROOF PAGE. Composes the closed-loop 2// simulation + RUL prognosis + business case into ONE zero-JS, privacy-first 3// HTML page that renders in the Nishi browser AND Chrome/Firefox/Edge -- the 4// operator's vision: simulate + prove the whole business in software, in the 5// browser, reproducibly, before a penny IRL. 6// 7// Operator (2026-06-23): "using software to simulate these things in our nishi 8// browser and 3rd party browsers ... proven via all modeling of the business, 9// legal, sensors, hardware." This is the capstone that makes the proof VIEWABLE. 10// 11// Reuses the nx_maint_render doctrine: 0 <script>, 0 third-party loads, 12// fail-closed (nx_maint_render_is_clean). Cross-browser by construction 13// (server-rendered, no JS). 14// 15// NEVER-BRICK (#26): builds bytes into a caller buffer; no syscalls, no writes. 16// 17// genealogy_id: project-maintenance-platform-sclass-2026-06-23 (in-browser proof page) 18// license_tier: ORIGINAL 19 20import "nx_maint_simloop.nx" // TwinThermal 21import "nx_maint_rul.nx" // RulEst + NX_RUL_* 22import "nx_maint_business.nx" // BizResult + NX_BIZ_* 23import "nx_maint_render.nx" // mr_cat + nx_maint_render_is_clean (zero-JS doctrine) 24const K_MAGIC_4096: i64 = 4096 25 26func nx_rul_name(v: i64) -> *u8 { 27 if v == NX_RUL_IMMINENT { return "Failure imminent" as *u8 } 28 if v == NX_RUL_SOON { return "Service soon" as *u8 } 29 if v == NX_RUL_PLAN { return "Plan service" as *u8 } 30 if v == NX_RUL_PLENTY { return "Plenty of life left" as *u8 } 31 if v == NX_RUL_STABLE { return "Stable (not wearing)" as *u8 } 32 if v == NX_RUL_FAILED { return "Already failed" as *u8 } 33 return "No prediction" as *u8 34} 35func nx_biz_name(v: i64) -> *u8 { 36 if v == NX_BIZ_VIABLE { return "VIABLE -- win-win" as *u8 } 37 if v == NX_BIZ_CUSTOMER_NEGATIVE { return "Customer-negative" as *u8 } 38 if v == NX_BIZ_BUSINESS_NEGATIVE { return "Business-negative" as *u8 } 39 if v == NX_BIZ_BOTH_NEGATIVE { return "Not viable" as *u8 } 40 return "--" as *u8 41} 42 43// append a signed decimal integer to buf at off (in-place, no scratch). 44func mr_int(buf: *u8, off: i64, v: i64) -> i64 { 45 if v == 0 { buf[off] = 48 as u8; return off + 1 } 46 var m: i64 = v 47 var o: i64 = off 48 if m < 0 { buf[o] = 45 as u8; o = o + 1; m = 0 - m } 49 var ndig: i64 = 0 50 var tmp: i64 = m 51 while tmp > 0 { ndig = ndig + 1; tmp = tmp / 10 } 52 var i: i64 = 0 53 var mm: i64 = m 54 while i < ndig { 55 let digit: i64 = mm % 10 56 buf[o + (ndig - 1 - i)] = (48 + digit) as u8 57 mm = mm / 10 58 i = i + 1 59 } 60 return o + ndig 61} 62 63// Render the proof page. Returns length (>=0), or -1 if cap too small. 64func nx_simpage_render(buf: *u8, cap: i64, twc: *TwinThermal, two: *TwinThermal, 65 rul: *RulEst, biz: *BizResult) -> i64 { 66 if cap < K_MAGIC_4096 { return 0 - 1 } 67 var o: i64 = 0 68 o = mr_cat(buf, o, "<!doctype html><html><head><meta charset=utf-8><style>" as *u8) 69 o = mr_cat(buf, o, "body{font:15px sans-serif;margin:20px;color:#222;max-width:560px}" as *u8) 70 o = mr_cat(buf, o, ".card{border:1px solid #ddd;border-radius:8px;padding:14px 16px;margin:12px 0}" as *u8) 71 o = mr_cat(buf, o, "h1{font-size:20px}h2{font-size:16px;margin:0 0 6px}.ok{color:#2e7d32;font-weight:700}" as *u8) 72 o = mr_cat(buf, o, ".bad{color:#c62828;font-weight:700}</style></head><body>" as *u8) 73 o = mr_cat(buf, o, "<h1>Maintenance platform -- proven in software (no IRL spend)</h1>" as *u8) 74 75 // 1. closed-loop simulation 76 o = mr_cat(buf, o, "<div class=card><h2>1. Closed-loop simulation</h2>" as *u8) 77 o = mr_cat(buf, o, "<p>Closed loop: <span class=ok>" as *u8) 78 o = mr_int(buf, o, twc.fixes_applied) 79 o = mr_cat(buf, o, " self-fixes, " as *u8) 80 o = mr_int(buf, o, twc.failures_seen) 81 o = mr_cat(buf, o, " failures</span> -- ends healthy.</p>" as *u8) 82 o = mr_cat(buf, o, "<p>Open loop (OBD-style): <span class=bad>" as *u8) 83 o = mr_int(buf, o, two.failures_seen) 84 o = mr_cat(buf, o, " failures</span> -- stays broken.</p></div>" as *u8) 85 86 // 2. prognosis 87 o = mr_cat(buf, o, "<div class=card><h2>2. Prognosis (predict before failure)</h2><p>" as *u8) 88 o = mr_cat(buf, o, nx_rul_name(rul.verdict)) 89 o = mr_cat(buf, o, " -- ~" as *u8) 90 o = mr_int(buf, o, rul.rul) 91 o = mr_cat(buf, o, " cycles to failure.</p></div>" as *u8) 92 93 // 3. business case (cents -> whole dollars) 94 o = mr_cat(buf, o, "<div class=card><h2>3. Business case (modeled, not guessed)</h2>" as *u8) 95 o = mr_cat(buf, o, "<p>Value created: $" as *u8) 96 o = mr_int(buf, o, biz.avoided_cost_cents / 100) 97 o = mr_cat(buf, o, "/asset-yr &middot; Customer net: $" as *u8) 98 o = mr_int(buf, o, biz.customer_savings_cents / 100) 99 o = mr_cat(buf, o, " &middot; ROI " as *u8) 100 o = mr_int(buf, o, biz.customer_roi_x100) 101 o = mr_cat(buf, o, "/100x.</p><p>Verdict: <span class=ok>" as *u8) 102 o = mr_cat(buf, o, nx_biz_name(biz.verdict)) 103 o = mr_cat(buf, o, "</span></p></div>" as *u8) 104 105 o = mr_cat(buf, o, "<p style=color:#666>Sovereign &middot; zero-JS &middot; renders in the Nishi browser and Chrome/Firefox/Edge.</p>" as *u8) 106 o = mr_cat(buf, o, "</body></html>" as *u8) 107 buf[o] = 0 as u8 108 return o 109}