code wiki / _hdl_build / nx_site_factory_ws_register.nx

nx_site_factory_ws_register.nx source

↩ module page · 78 lines · 4421 B

1// nx_site_factory_ws_register.nx -- register the SITE FACTORY arc into the WMS registry SSOT 2// (knowledge/store/ws-, via nx_workstream_store / nx_seg_store) so the resume manifest + other empires SEE 3// it. Additive + idempotent (rule 10 / 13): reads the LIVE ws:ids index (~1265 streams) and appends our id 4// ONLY IF absent (ws_member dedup -- it NEVER clobbers the enumeration), then commits the ws:<id> record and 5// verifies read-back. Mirrors nx_hub_ws_register (the safe read-modify-write registrar) -- NOT 6// nx_workstream_seed, whose static 15-id ws:ids would shrink the board and vanish ~1250 streams. Empire 7// E-WEB (this arc EMITS web properties: andelinwest.com, nishifamily.com, ...). license_tier: ORIGINAL 8import "nx_workstream_store.nx" 9import "nx_seg_store.nx" 10import "nx_syscalls.nx" 11const K_MAGIC_262144: i64 = 262144 12 13func rw_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 14func rw_len(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 15 16// append "\t<id>" to idsbuf at olenp[0] iff id is not already a TAB-member. keeps the index de-duped. 17func rw_addid(idsbuf: *u8, olenp: *i64, id: *u8) -> i64 { 18 if ws_member(idsbuf, olenp[0], id) == 1 { return 0 } 19 var o: i64 = olenp[0] 20 if o > 0 { idsbuf[o] = 9 as u8; o = o + 1 } 21 var i: i64 = 0 22 while id[i] != (0 as u8) { idsbuf[o] = id[i]; o = o + 1; i = i + 1 } 23 olenp[0] = o 24 return 1 25} 26 27func rw_rec(w: *i64, key: *u8, val: *u8) -> i64 { return ss_add(w, 1, key, val, rw_len(val)) } 28 29func main() -> i64 { 30 let w: *i64 = ss_begin() 31 let pq: *i64 = sys_mmap(16) as *i64 32 let lq: *i64 = sys_mmap(16) as *i64 33 let idsbuf: *u8 = sys_mmap(K_MAGIC_262144) 34 let olenp: *i64 = sys_mmap(8) as *i64 35 olenp[0] = 0 36 // read the LIVE ws:ids index (the full enumeration; ~1265 streams) and copy it in. 37 if ws_get("ws:ids\x00" as *u8, pq, lq) == 1 { 38 let src: *u8 = pq[0] as *u8 39 let n: i64 = lq[0] 40 var i: i64 = 0 41 while i < n { idsbuf[i] = src[i]; i = i + 1 } 42 olenp[0] = n 43 } 44 let before: i64 = olenp[0] 45 rw_addid(idsbuf, olenp, "SITE-FACTORY\x00" as *u8) 46 ss_add(w, 1, "ws:ids\x00" as *u8, idsbuf, olenp[0]) 47 // the workstream record (id \t empire \t state \t last_touched \t memory \t code \t deps). 48 rw_rec(w, "ws:SITE-FACTORY\x00" as *u8, "SITE-FACTORY\tE-WEB\tACTIVE\t0\tproject-nishi-site-factory-2026-07-02.md\truntime/_hdl_build/nx_site_factory_census.nx\t-\x00" as *u8) 49 let segid: i64 = ws_seg_next(WS_PREFIX) 50 let rc: i64 = ss_commit(WS_PREFIX, w, segid) 51 if rc != 0 { rw_w("nx_site_factory_ws_register: COMMIT FAILED\n\x00" as *u8); return 1 } 52 // verify: the record reads back AND the id is a member of the (preserved) live ws:ids. 53 var ver: i64 = 0 54 if ws_get("ws:SITE-FACTORY\x00" as *u8, pq, lq) == 1 { ver = 1 } 55 let cq: *i64 = sys_mmap(16) as *i64 56 let cl: *i64 = sys_mmap(16) as *i64 57 var inids: i64 = 0 58 var idslen: i64 = 0 59 if ws_get("ws:ids\x00" as *u8, cq, cl) == 1 { 60 idslen = cl[0] 61 if ws_member(cq[0] as *u8, cl[0], "SITE-FACTORY\x00" as *u8) == 1 { inids = 1 } 62 } 63 // NO-REGRESSION guard: the enumeration must have GROWN (or held, if already present), never shrunk. 64 var grew_ok: i64 = 0 65 if idslen >= before { grew_ok = 1 } 66 rw_w("nx_site_factory_ws_register: SITE-FACTORY (E-WEB, ACTIVE) -> record_ver=\x00" as *u8) 67 let bb: *u8 = sys_mmap(8); bb[0] = (48 + ver) as u8; sys_write(1, bb, 1) 68 rw_w(" in_ws_ids=\x00" as *u8) 69 let cc: *u8 = sys_mmap(8); cc[0] = (48 + inids) as u8; sys_write(1, cc, 1) 70 rw_w(" ws_ids_bytes_before=\x00" as *u8); let n1: i64 = before 71 // tiny inline decimal (avoid extra helper) 72 var m: i64 = n1; let tb: *u8 = sys_mmap(24); var k: i64 = 0; if m==0 {tb[0]=48;k=1} while m>0 {tb[k]=(48+(m%10)) as u8; m=m/10; k=k+1} let ob: *u8=sys_mmap(24); var q: i64=k-1; var wq: i64=0; while q>=0 {ob[wq]=tb[q]; wq=wq+1; q=q-1} sys_write(1, ob, wq) 73 rw_w(" after=\x00" as *u8) 74 var m2: i64 = idslen; let tb2: *u8 = sys_mmap(24); var k2: i64 = 0; if m2==0 {tb2[0]=48;k2=1} while m2>0 {tb2[k2]=(48+(m2%10)) as u8; m2=m2/10; k2=k2+1} let ob2: *u8=sys_mmap(24); var q2: i64=k2-1; var wq2: i64=0; while q2>=0 {ob2[wq2]=tb2[q2]; wq2=wq2+1; q2=q2-1} sys_write(1, ob2, wq2) 75 rw_w("\n\x00" as *u8) 76 if ver == 1 { if inids == 1 { if grew_ok == 1 { return 0 } } } 77 return 1 78}