code wiki / _hdl_build / nx_vroom_emit.nx

nx_vroom_emit.nx source

↩ module page · 132 lines · 7929 B

1// nx_vroom_emit.nx -- RUNG 0 of making the LIVE /video/ client NISHI-EMITTED (operator 2026-06-23: 2// "why do we have javascript, we were nishi ecosystem all the way -- organ emits the client (SSOT)"). 3// The live family room = sites/nishifamily/video/{index.html, app.js} (app.js = the browser-primitive 4// SHIM driving the Nishi WASM core -- browser glue is allowed, but it must be ORGAN-EMITTED, not hand- 5// authored). This organ OWNS the emit: it reads the source, applies the camera-mirror fix IN the emit, 6// and writes the deployable client to knowledge/staging/video/. Edit the organ -> emit -> deploy (vault 7// organs) -> verify LIVE via nx_live_verify (find THIS marker in the served bytes). No more hand-editing 8// the deployed JS; the organ is the SSOT of the transform. 9// 10// RUNG 0 fix = SELF-VIEW MIRROR (the reported camera-flip): mark the self tile (class "tile self") + a 11// CSS rule mirrors ONLY the self <video> (selfie feel); the SENT frame stays un-mirrored (remote correct). 12// RUNG 1 (next) = TX flip-toggle + inter-frame coding into the emit. GREEN = emitted output carries the fix. 13// Evidence -> knowledge/status/vroom_emit.log. license_tier: ORIGINAL 14import "nx_syscalls.nx" 15const VE_MAGIC_262144: i64 = 262144 16const VE_MAGIC_4096: i64 = 4096 17 18const VE_LOG: *u8 = "knowledge/status/vroom_emit.log" 19const SRC_HTML: *u8 = "sites/nishifamily/video/index.html" 20const SRC_JS: *u8 = "sites/nishifamily/video/app.js" 21const OUT_DIR: *u8 = "knowledge/staging/video" 22const OUT_HTML: *u8 = "knowledge/staging/video/index.html" 23const OUT_JS: *u8 = "knowledge/staging/video/app.js" 24// the camera-mirror fix, injected at emit time: 25const SELF_OLD: *u8 = "selfTile.className = \"tile\"" 26const SELF_NEW: *u8 = "selfTile.className = \"tile self\"" 27const CSS_MARK: *u8 = "</style>" 28const CSS_INJECT: *u8 = " /* nishi-emit: self-view mirror (selfie feel); sent frame stays un-mirrored */\n .tile.self video, .tile.self canvas { transform: scaleX(-1); }\n</style>" 29 30func ew(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 } 31func en(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(fd,"-" as *u8,1)} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1} sys_write(fd,bb,k); return 0 } 32func slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 33// first index of needle in hay[0..n), or -1 34func find_sub(hay: *u8, n: i64, needle: *u8) -> i64 { 35 let m: i64 = slen(needle) 36 if m == 0 { return 0 } 37 var i: i64=0 38 while i + m <= n { 39 var j: i64=0; var ok: i64=1 40 while j < m { if hay[i+j] != needle[j] { ok=0; j=m } else { j=j+1 } } 41 if ok==1 { return i } 42 i=i+1 43 } 44 return 0 - 1 45} 46// copy s into dst at off; return new off 47func put(dst: *u8, off: i64, s: *u8, n: i64) -> i64 { var i: i64=0; while i<n { dst[off+i]=s[i]; i=i+1 } return off+n } 48// replace the FIRST occurrence of `oldp` in src[0..n) with `newp`; write into out; return out length (or -1 if not found) 49func replace_one(src: *u8, n: i64, oldp: *u8, newp: *u8, out: *u8) -> i64 { 50 let idx: i64 = find_sub(src, n, oldp) 51 if idx < 0 { return 0 - 1 } 52 let ol: i64 = slen(oldp); let nl: i64 = slen(newp) 53 var o: i64 = put(out, 0, src, idx) // before 54 o = put(out, o, newp, nl) // replacement 55 o = put(out, o, (src as i64 + idx + ol) as *u8, n - idx - ol) // after 56 return o 57} 58func write_file(path: *u8, buf: *u8, n: i64) -> i64 { 59 let fd: i64 = sys_openat_wr(path, 0x1a4) 60 if fd < 0 { return 0 - 1 } 61 sys_write(fd, buf, n); sys_close(fd) 62 return n 63} 64 65func main() -> i64 { 66 sys_mkdir("knowledge/staging" as *u8, 0x1ed) 67 sys_mkdir(OUT_DIR, 0x1ed) 68 let cap: i64 = VE_MAGIC_262144 69 let inb: *u8 = sys_mmap(cap) 70 let out: *u8 = sys_mmap(cap + VE_MAGIC_4096) 71 let lb: *i64 = sys_mmap(8) as *i64 72 73 ew(1, "=== nx_vroom_emit RUNG 0 -- emit the /video/ client (SSOT) with the self-view mirror fix ===\n") 74 75 // ---- index.html: inject the self-view mirror CSS before </style> ---- 76 let h: *u8 = sys_read_file(SRC_HTML, lb) 77 if (h as i64) == 0 { ew(1, " FATAL: source index.html not found at "); ew(1, SRC_HTML); ew(1, "\n"); sys_exit(1); return 1 } 78 let hn: i64 = lb[0] 79 var i: i64=0; while i<hn { inb[i]=h[i]; i=i+1 } 80 // idempotent: if the mirror CSS is already present (source previously emitted/staged into Gitea), pass through unchanged 81 var ho: i64 = 0 82 if find_sub(inb, hn, "scaleX(-1)" as *u8) >= 0 { 83 var z: i64=0; while z<hn { out[z]=inb[z]; z=z+1 } ho=hn 84 ew(1, " index.html: already-fixed source -> idempotent pass-through\n") 85 } else { 86 ho = replace_one(inb, hn, CSS_MARK, CSS_INJECT, out) 87 } 88 var html_ok: i64=0 89 if ho > 0 { write_file(OUT_HTML, out, ho); html_ok=1 } 90 ew(1, " index.html: read="); en(1, hn); ew(1, "B emit="); en(1, ho); ew(1, "B (css mirror present)\n") 91 92 // ---- app.js: mark the self tile so the CSS targets only the self-view ---- 93 let a: *u8 = sys_read_file(SRC_JS, lb) 94 if (a as i64) == 0 { ew(1, " FATAL: source app.js not found at "); ew(1, SRC_JS); ew(1, "\n"); sys_exit(1); return 1 } 95 let an: i64 = lb[0] 96 i=0; while i<an { inb[i]=a[i]; i=i+1 } 97 // idempotent: if the self tile is already marked (source previously emitted/staged into Gitea), pass through unchanged 98 var ao: i64 = 0 99 if find_sub(inb, an, "tile self" as *u8) >= 0 { 100 var z2: i64=0; while z2<an { out[z2]=inb[z2]; z2=z2+1 } ao=an 101 ew(1, " app.js: already-fixed source -> idempotent pass-through\n") 102 } else { 103 ao = replace_one(inb, an, SELF_OLD, SELF_NEW, out) 104 } 105 var js_ok: i64=0 106 if ao > 0 { write_file(OUT_JS, out, ao); js_ok=1 } 107 ew(1, " app.js: read="); en(1, an); ew(1, "B emit="); en(1, ao); ew(1, "B (self tile 'tile self' present)\n") 108 109 // ---- SELF-VERIFY: the emitted output must carry the fix markers ---- 110 let eh: *u8 = sys_read_file(OUT_HTML, lb); let ehn: i64 = lb[0] 111 let css_live: i64 = find_sub(eh, ehn, "scaleX(-1)" as *u8) 112 let ej: *u8 = sys_read_file(OUT_JS, lb); let ejn: i64 = lb[0] 113 let self_live: i64 = find_sub(ej, ejn, "tile self" as *u8) 114 115 var ok: i64=1 116 if html_ok != 1 { ok=0 } 117 if js_ok != 1 { ok=0 } 118 if css_live < 0 { ok=0 } // emitted index.html HAS the mirror CSS 119 if self_live < 0 { ok=0 } // emitted app.js HAS the self-tile marker 120 121 ew(1, " T1 emitted index.html has mirror CSS (scaleX(-1) @"); en(1, css_live); ew(1, "): "); if css_live>=0 { ew(1,"PASS") } else { ew(1,"FAIL") } 122 ew(1, "\n T2 emitted app.js marks the self tile (tile self @"); en(1, self_live); ew(1, "): "); if self_live>=0 { ew(1,"PASS") } else { ew(1,"FAIL") } 123 ew(1, "\n emitted to knowledge/staging/video/ (the DEPLOYABLE, organ-emitted client)\n") 124 ew(1, " NEXT: deploy this staging dir to the /video/ web root via the vault organs, then nx_live_verify must find scaleX(-1) in the LIVE app.js/index.html before it is 'done'.\n") 125 ew(1, " RUNG 1: TX flip-toggle + inter-frame coding into the emit. (browser runs only the primitive shim; organ is the SSOT)\n") 126 if ok==1 { ew(1, "VERDICT: GREEN (client organ-emitted with the camera-mirror fix; verified in the emitted bytes)\n") } else { ew(1, "VERDICT: RED (emit or fix-injection failed)\n") } 127 128 let lfd: i64 = sys_openat_append(VE_LOG, 420) 129 if lfd>=0 { ew(lfd, "VROOMEMIT html_in="); en(lfd, hn); ew(lfd, " html_out="); en(lfd, ho); ew(lfd, " js_in="); en(lfd, an); ew(lfd, " js_out="); en(lfd, ao); ew(lfd, " css_live="); en(lfd, css_live); ew(lfd, " self_live="); en(lfd, self_live); if ok==1 { ew(lfd, " verdict=GREEN\n") } else { ew(lfd, " verdict=RED\n") } sys_close(lfd) } 130 if ok==1 { sys_exit(0) } else { sys_exit(1) } 131 return 0 132}