code wiki / _hdl_build / nx_hr_provision_roster.nx
nx_hr_provision_roster.nx source
↩ module page · 72 lines · 5191 B
1// nx_hr_provision_roster.nx -- provisions the REAL family roster into STAGING HR stores (the operator confirmed the
2// handles + levels via AskUserQuestion: lowercase first names; brad/jensen/kelli = family members; andelinwest =
3// a SEPARATE realm; elderwesto = sole super-admin). It does NOT create any OPAQUE passphrase -- each person creates
4// their own when they sign up on the LAN (rule: Claude never fabricates a credential). It writes only the HR
5// DIRECTORY (the level/invite SSOT), keyed by cred_id derived from the handle.
6//
7// IDEMPOTENT BY CONSTRUCTION (#10): it TRUNCATES then rebuilds, so every run yields byte-identical stores (safe to
8// re-run; for INCREMENTAL changes after go-live use hra_invite/hra_suspend instead, which preserve history #13).
9// Output (staged -> the operator/publisher promotes to the NAS, where each realm's daemon reads it):
10// knowledge/publish/staging/nishi_hr.log (realm nishi_site_admin) -- the nishifamily.com roster
11// knowledge/publish/staging/andelinwest_hr.log (realm andelinwest_admin) -- the andelinwest.com roster (sealed)
12// Roster NOW (operator: "i should only see brad, jensen, kelli for now"): elderwesto(owner,active) + brad/jensen/
13// kelli(member,invited). Robert/Vanessa are provisioned as admins in the SEPARATE andelinwest store -> invisible to
14// nishifamily until andelinwest.com onboards them.
15import "nx_hr_admin.nx"
16import "nx_g_puts_lib.nx"
17import "nx_hr.nx"
18import "nx_syscalls.nx"
19
20func g_num(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" 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(1,bb,k); return 0 }
21func gtrunc(path: *u8) -> i64 { let fd: i64 = sys_openat_wr(path, 0x1a4); if fd>=0 { sys_close(fd) } return 0 }
22
23func main() -> i64 {
24 g_puts("=== NISHI HR -- PROVISION FAMILY ROSTER (staging) ===\n" as *u8)
25 let nishi: *u8 = "knowledge/publish/staging/nishi_hr-" as *u8 // seg_store prefix (cutover; was .log)
26 let andel: *u8 = "knowledge/publish/staging/andelinwest_hr-" as *u8
27 let NR: *u8 = "nishi_site_admin" as *u8; let NRN: i64 = 16
28 let AR: *u8 = "andelinwest_admin" as *u8; let ARN: i64 = 17
29 let famN: *u8 = "andelin" as *u8
30 let famA: *u8 = "andelinwest" as *u8
31 let now: i64 = sys_now_realtime_sec()
32 // seg_store is idempotent: re-provision overwrites identical records (auto-segid) -- no truncate needed (#10/#13).
33 let cid: *u8 = sys_mmap(96)
34
35 // --- nishifamily.com (realm nishi_site_admin) ---
36 // elderwesto = the SOLE super-admin, enrolled ACTIVE owner (already has an OPAQUE account; HR grants the level).
37 hra_enroll(nishi, NR, NRN, "elderwesto" as *u8, 10, HRA_LVL_OWNER, famN, now, "system" as *u8, cid)
38 // the three family members -- INVITED (they sign up on the LAN; no passphrase created here).
39 hra_invite(nishi, NR, NRN, "brad" as *u8, 4, HRA_LVL_MEMBER, famN, now, "elderwesto" as *u8, cid)
40 hra_invite(nishi, NR, NRN, "jensen" as *u8, 6, HRA_LVL_MEMBER, famN, now, "elderwesto" as *u8, cid)
41 hra_invite(nishi, NR, NRN, "kelli" as *u8, 5, HRA_LVL_MEMBER, famN, now, "elderwesto" as *u8, cid)
42
43 // --- andelinwest.com (realm andelinwest_admin -- SEPARATE property) ---
44 // robert + vanessa = admins THERE only; invited (claimed when andelinwest onboards them). Sealed from nishifamily.
45 hra_invite(andel, AR, ARN, "robert" as *u8, 6, HRA_LVL_OWNER, famA, now, "elderwesto" as *u8, cid)
46 hra_invite(andel, AR, ARN, "vanessa" as *u8, 7, HRA_LVL_OWNER, famA, now, "elderwesto" as *u8, cid)
47
48 // --- the roster the operator will see ---
49 g_puts("\nnishifamily.com (realm nishi_site_admin):\n" as *u8)
50 g_puts(" [ACTIVE owner ] elderwesto <- super-user admin: auto-access to everything (by construction)\n" as *u8)
51 g_puts(" [INVITED member] brad <- signs up on the LAN (creates own passphrase)\n" as *u8)
52 g_puts(" [INVITED member] jensen\n" as *u8)
53 g_puts(" [INVITED member] kelli\n" as *u8)
54 g_puts("\nandelinwest.com (realm andelinwest_admin -- separate, sealed from nishifamily):\n" as *u8)
55 g_puts(" [INVITED admin ] robert <- reserved; claims when andelinwest onboards\n" as *u8)
56 g_puts(" [INVITED admin ] vanessa\n" as *u8)
57
58 // --- VERIFY (counts COMPUTED from the stores, not asserted) ---
59 let n_active: i64 = hra_roster_count(nishi, HRA_ST_ACTIVE)
60 let n_invited: i64 = hra_roster_count(nishi, HRA_ST_INVITED)
61 let a_invited: i64 = hra_roster_count(andel, HRA_ST_INVITED)
62 g_puts("\nVERIFY nishifamily active=" as *u8); g_num(n_active)
63 g_puts(" invited=" as *u8); g_num(n_invited)
64 g_puts(" andelinwest invited=" as *u8); g_num(a_invited); g_puts("\n" as *u8)
65
66 var green: i64 = 0
67 if n_active == 1 { if n_invited == 3 { if a_invited == 2 { green = 1 } } }
68 if green==1 { g_puts("PROVISION verdict=GREEN (1 owner active + 3 invited members; 2 andelinwest admins reserved)\n" as *u8) }
69 else { g_puts("PROVISION verdict=RED\n" as *u8) }
70 if green==1 { sys_exit(0); return 0 }
71 sys_exit(1); return 1
72}