code wiki / _hdl_build / nx_iot_ws_inject.nx
nx_iot_ws_inject.nx source
↩ module page · 86 lines · 4635 B
1// nx_iot_ws_inject.nx -- inject the IoT killer-feature workstreams into the WMS SSOT
2// (knowledge/store/ws-*, the registry the team/board reads) via the store's OWN API -- index-
3// consistent + idempotent + byte-verified (no raw seg-store write, no clobbering the seeder).
4// Registers: IOT-R4LIVE (DONE -- I built+gated nx_iot_hub_serve_realm) and PULSE-REVIVE (ACTIVE --
5// the engineer's progress-aware-revive task). Operator 2026-06-23 "both: inject + I build".
6// expect_exit: 0 license_tier: ORIGINAL
7import "nx_workstream_store.nx"
8import "nx_syscalls.nx"
9const K_MAGIC_262144: i64 = 262144
10
11func iwi_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
12func iwi_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 }
13func iwi_catn(dst: *u8, off: i64, v: i64) -> i64 {
14 var o: i64=off; var m: i64=v; let t: *u8=sys_mmap(28); var k: i64=0
15 if m==0 { t[0]=48; k=1 }
16 while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 }
17 var j: i64=k-1; while j>=0 { dst[o]=t[j]; o=o+1; j=j-1 } return o
18}
19// substring search: 1 if `needle` occurs in buf[0..n)
20func iwi_has(buf: *u8, n: i64, needle: *u8) -> i64 {
21 var nl: i64=0; while needle[nl]!=(0 as u8){nl=nl+1}
22 if nl==0 { return 1 }
23 var i: i64=0; let lim: i64=n-nl
24 while i<=lim { var j: i64=0; var ok: i64=1; while j<nl { if buf[i+j]!=needle[j] { ok=0; j=nl } else { j=j+1 } } if ok==1 { return 1 } i=i+1 }
25 return 0
26}
27// build a ws:<id> record into out: id<tab>empire<tab>state<tab>now<tab>mem<tab>code<tab>deps
28func iwi_rec(out: *u8, id: *u8, empire: *u8, state: *u8, now: i64, mem: *u8, code: *u8) -> i64 {
29 var o: i64=0
30 o=iwi_cat(out,o,id); out[o]=9 as u8; o=o+1
31 o=iwi_cat(out,o,empire); out[o]=9 as u8; o=o+1
32 o=iwi_cat(out,o,state); out[o]=9 as u8; o=o+1
33 o=iwi_catn(out,o,now); out[o]=9 as u8; o=o+1
34 o=iwi_cat(out,o,mem); out[o]=9 as u8; o=o+1
35 o=iwi_cat(out,o,code); out[o]=9 as u8; o=o+1
36 o=iwi_cat(out,o,"-" as *u8)
37 out[o]=0 as u8
38 return o
39}
40// put ws:<id> then read back + byte-verify; return 1 ok.
41func iwi_put_verify(idkey: *u8, rec: *u8) -> i64 {
42 ws_put(idkey, rec)
43 let pq: *i64=sys_mmap(16) as *i64; let lq: *i64=sys_mmap(16) as *i64
44 if ws_get(idkey, pq, lq) != 1 { return 0 }
45 let b: *u8=pq[0] as *u8; let n: i64=lq[0]
46 var rl: i64=0; while rec[rl]!=(0 as u8){rl=rl+1}
47 if n != rl { return 0 }
48 var i: i64=0; while i<n { if b[i]!=rec[i] { return 0 } i=i+1 }
49 return 1
50}
51
52func main() -> i64 {
53 let now: i64 = sys_now_realtime_sec()
54 let mem: *u8 = "project-iot-discovery-pairing-revival-2026-06-22" as *u8
55
56 // ---- the two records ----
57 let recA: *u8 = sys_mmap(512)
58 iwi_rec(recA, "IOT-R4LIVE-hub-hr-session-gate" as *u8, "E-ELDER" as *u8, "DONE" as *u8, now, mem, "nx_iot_hub_serve_realm" as *u8)
59 let recB: *u8 = sys_mmap(512)
60 iwi_rec(recB, "PULSE-REVIVE-progress-aware" as *u8, "E-PM" as *u8, "ACTIVE" as *u8, now, mem, "nx_boot_revive" as *u8)
61
62 if iwi_put_verify("ws:IOT-R4LIVE-hub-hr-session-gate" as *u8, recA) != 1 { iwi_w("INJECT: recA verify FAIL\n" as *u8); return 1 }
63 if iwi_put_verify("ws:PULSE-REVIVE-progress-aware" as *u8, recB) != 1 { iwi_w("INJECT: recB verify FAIL\n" as *u8); return 2 }
64
65 // ---- update the ws:ids index (append if absent; idempotent) ----
66 let pq: *i64=sys_mmap(16) as *i64; let lq: *i64=sys_mmap(16) as *i64
67 let g: i64 = ws_get("ws:ids" as *u8, pq, lq)
68 let cur: *u8 = sys_mmap(K_MAGIC_262144)
69 var clen: i64 = 0
70 if g == 1 { let b: *u8=pq[0] as *u8; clen=lq[0]; var i: i64=0; while i<clen { cur[i]=b[i]; i=i+1 } }
71 cur[clen]=0 as u8
72 var changed: i64 = 0
73 if iwi_has(cur, clen, "IOT-R4LIVE-hub-hr-session-gate" as *u8) == 0 { cur[clen]=9 as u8; clen=clen+1; clen=iwi_cat(cur,clen,"IOT-R4LIVE-hub-hr-session-gate" as *u8); changed=1 }
74 if iwi_has(cur, clen, "PULSE-REVIVE-progress-aware" as *u8) == 0 { cur[clen]=9 as u8; clen=clen+1; clen=iwi_cat(cur,clen,"PULSE-REVIVE-progress-aware" as *u8); changed=1 }
75 cur[clen]=0 as u8
76 if changed == 1 { ws_put("ws:ids" as *u8, cur) }
77
78 // ---- verify both ids now enumerated ----
79 if ws_get("ws:ids" as *u8, pq, lq) != 1 { iwi_w("INJECT: ws:ids missing\n" as *u8); return 3 }
80 let idx: *u8 = pq[0] as *u8; let idxn: i64 = lq[0]
81 if iwi_has(idx, idxn, "IOT-R4LIVE-hub-hr-session-gate" as *u8) == 0 { return 4 }
82 if iwi_has(idx, idxn, "PULSE-REVIVE-progress-aware" as *u8) == 0 { return 5 }
83
84 iwi_w("INJECT GREEN: IOT-R4LIVE=DONE + PULSE-REVIVE=ACTIVE in WMS ws:ids + records byte-verified\n" as *u8)
85 return 0
86}