code wiki / _hdl_build / nx_acct_admin_handoff.nx
nx_acct_admin_handoff.nx source
↩ module page · 98 lines · 10153 B
1// nx_acct_admin_handoff.nx -- COORDINATION HANDOFF on the SOVEREIGN store (operator: "pass the wiring work to the
2// appropriate nishi team queues" + "no tsv -- nishi ecosystem only" [[feedback-no-3rd-party-tsv-sovereign-store]]).
3// Each work-request is a CANON-ENCODED record (nx_canon_cid) in a content-addressed, append-only, crash-safe
4// nx_seg_store (knowledge/store/coord-), keyed by sha(to_team|title) -- NOT a flat .tsv. Follows the blessed handoff
5// pattern (nx_pub_teacher_handoff: REQUEST through the owning role's queue, isolated, don't reinvent). Idempotent
6// (#10): re-filing the same (team,title) is a no-op. Each request carries the capability ref + gate evidence the
7// team needs, so no team is blocked on a missing primitive.
8// fields: to_team, from, title, ref, evidence, priority, status(OPEN)
9import "nx_sovjson_lib.nx"
10import "nx_seg_store.nx" // ss_begin / ss_add / ss_commit / ss_open / ss_hget
11import "nx_canon_cid.nx" // canon_encode
12import "nx_sha256.nx" // sha256_digest
13import "nx_syscalls.nx"
14const AH_MAGIC_2048: i64 = 2048
15const AH_MAGIC_8192: i64 = 8192
16
17func g_w(s: *u8) -> i64 { return sj_puts(s) }
18func g_n(v: i64) -> i64 { var m: i64=v; if m<0{g_w("-" as *u8);m=0-m} let t:*u8=sys_mmap(24); 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; let o:*u8=sys_mmap(24); while i<k{o[i]=t[k-1-i];i=i+1} sys_write(1,o,k); return 0 }
19func g_row(id: *u8, ok: i64, pass: *i64) -> i64 { g_w(" " as *u8); g_w(id); g_w(": " as *u8); if ok==1 { g_w("OK\n" as *u8); pass[0]=pass[0]+1 } else { g_w("FAIL\n" as *u8) } return 0 }
20func ah_cat(dst: *u8, off: i64, s: *u8) -> i64 { return sj_cat(dst, off, s) }
21func ah_hex(dig: *u8, n: i64, out: *u8) -> i64 { let hx: *u8="0123456789abcdef" as *u8; var i: i64=0; while i<n { out[i*2]=hx[((dig[i] as i64)>>4)&15]; out[i*2+1]=hx[(dig[i] as i64)&15]; i=i+1 } out[n*2]=0 as u8; return n*2 }
22// idempotency / store key = hex(sha256(to_team || "|" || title)).
23func ah_idkey(to_team: *u8, title: *u8, out: *u8) -> i64 {
24 let b: *u8=sys_mmap(AH_MAGIC_2048); var o: i64=0; o=ah_cat(b,o,to_team); b[o]=124 as u8;o=o+1; o=ah_cat(b,o,title)
25 let dig: *u8=sys_mmap(32); sha256_digest(b, o, dig); return ah_hex(dig, 32, out)
26}
27// 1 iff a request for (to_team,title) is already in the store.
28func ah_has(prefix: *u8, to_team: *u8, title: *u8) -> i64 {
29 let idk: *u8=sys_mmap(72); ah_idkey(to_team, title, idk)
30 let h: *i64=ss_open(prefix); if (h as i64)==0 { return 0 }
31 let pp: *i64=sys_mmap(16) as *i64; let ll: *i64=sys_mmap(16) as *i64
32 if ss_hget(h, idk, pp, ll)==1 { return 1 }
33 return 0
34}
35// IDEMPOTENT file: skip if (to_team,title) already queued; else canon record -> seg_store (segid UNIQUE per commit).
36func ah_file(prefix: *u8, to_team: *u8, from: *u8, title: *u8, ref: *u8, evid: *u8, prio: *u8, segid: i64, filed: *i64) -> i64 {
37 if ah_has(prefix, to_team, title)==1 { return 0 }
38 let idk: *u8=sys_mmap(72); ah_idkey(to_team, title, idk)
39 let keys: *i64=sys_mmap(8*8) as *i64; let vals: *i64=sys_mmap(8*8) as *i64
40 keys[0]="to_team" as *u8 as i64; vals[0]=to_team as i64
41 keys[1]="from" as *u8 as i64; vals[1]=from as i64
42 keys[2]="title" as *u8 as i64; vals[2]=title as i64
43 keys[3]="ref" as *u8 as i64; vals[3]=ref as i64
44 keys[4]="evidence" as *u8 as i64; vals[4]=evid as i64
45 keys[5]="priority" as *u8 as i64; vals[5]=prio as i64
46 keys[6]="status" as *u8 as i64; vals[6]="OPEN" as *u8 as i64
47 let buf: *u8=sys_mmap(AH_MAGIC_8192); let blen: i64=canon_encode(keys, vals, 7, buf)
48 let w: *i64=ss_begin(); ss_add(w, 1, idk, buf, blen); ss_commit(prefix, w, segid)
49 filed[0]=filed[0]+1; return 1
50}
51
52const AH_FROM: *u8 = "acct-admin-32992a14" as *u8
53const AH_Q: *u8 = "knowledge/store/coord-" as *u8 // the sovereign seg_store prefix (NOT a .tsv)
54
55func main() -> i64 {
56 let pass: *i64 = sys_mmap(8) as *i64; pass[0]=0
57 g_w("=== ACCOUNT-ADMIN -> NISHI TEAMS coordination handoff (sovereign seg_store, no tsv) ===\n" as *u8)
58 __syscall(83, "knowledge/store" as i64, 493, 0, 0, 0, 0)
59
60 // ---- PROOF on a fresh per-run test store (now_ms-suffixed; pids get REUSED -> stale, so use the clock) ----
61 let pid: i64=sys_now_ms()
62 let tq: *u8=sys_mmap(128); var po: i64=ah_cat(tq,0,"/tmp/nx_ahst_" as *u8); let nb: *u8=sys_mmap(24)
63 var m: i64=pid; var k: i64=0; if m==0{nb[0]=48 as u8;k=1} while m>0{nb[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var z: i64=k-1; while z>=0{tq[po]=nb[z];po=po+1;z=z-1} tq[po]=0 as u8
64 let tfiled: *i64=sys_mmap(8) as *i64; tfiled[0]=0
65 ah_file(tq, "teamA" as *u8, AH_FROM, "do X" as *u8, "ref" as *u8, "gate" as *u8, "P2" as *u8, 1, tfiled)
66 ah_file(tq, "teamA" as *u8, AH_FROM, "do X" as *u8, "ref" as *u8, "gate" as *u8, "P2" as *u8, 2, tfiled) // dup
67 ah_file(tq, "teamB" as *u8, AH_FROM, "do Y" as *u8, "ref" as *u8, "gate" as *u8, "P1" as *u8, 3, tfiled)
68 g_row("idempotent: 2 distinct of 3 calls filed (dup skipped)" as *u8, (tfiled[0]==2) as i64, pass)
69 g_row("routed: teamA + teamB addressed; unknown not present" as *u8, ((ah_has(tq,"teamA" as *u8,"do X" as *u8)==1) as i64) & ((ah_has(tq,"teamB" as *u8,"do Y" as *u8)==1) as i64) & ((ah_has(tq,"teamZ" as *u8,"nope" as *u8)==0) as i64), pass)
70
71 // ---- REAL: file every recommendation to the owning team, idempotent, with capability + evidence ----
72 let filed: *i64=sys_mmap(8) as *i64; filed[0]=0
73 let base: i64 = pid*8
74 ah_file(AH_Q, "gallery (Engineer)" as *u8, AH_FROM, "Adopt nx_hr_access: gate /gallery resources via hac_gate (required=1 family, 3 owner); retire flat/realm-only gating" as *u8, "runtime/_hdl_build/nx_hr_access.nx" as *u8, "nx_hr_access_gate 14/14 GREEN (auth!=authz; live-suspend)" as *u8, "P2" as *u8, base+1, filed)
75 ah_file(AH_Q, "hub (Engineer)" as *u8, AH_FROM, "Adopt nx_hr_access: resolve hub access via hac_gate at resource boundaries; retire realm-only gating" as *u8, "runtime/_hdl_build/nx_hr_access.nx" as *u8, "nx_hr_access_gate 14/14 GREEN; torrent already on HR" as *u8, "P2" as *u8, base+2, filed)
76 ah_file(AH_Q, "publisher (Builder)" as *u8, AH_FROM, "Rebuild superuser-aware nx_opaque_login_daemon + nx_lan_signup_daemon from source, pub_submit them; drop the stale reg-close .elf rows" as *u8, "knowledge/publish/staging/ACCOUNT_ADMIN_DEPLOY.md" as *u8, "11 gates GREEN + nx_account_admin_census GREEN" as *u8, "P1" as *u8, base+3, filed)
77 ah_file(AH_Q, "hosting (Caretaker)" as *u8, AH_FROM, "After publisher approval: atomic-promote the 2 HR stores + restart opaque login; bring nx_lan_signup_daemon up on LAN with the hub keys; never-brick #26" as *u8, "knowledge/publish/staging/ACCOUNT_ADMIN_DEPLOY.md" as *u8, "HR stores queued PENDING (R6 hold) + socket-proven" as *u8, "P1" as *u8, base+4, filed)
78 ah_file(AH_Q, "publisher (Builder)" as *u8, AH_FROM, "Wire receipt emission: after pub_run publishes, call nx_pub_receipt.rcpt_emit so every submitter gets a SIGNED return-and-report receipt (built + censused, seg_store-backed)" as *u8, "runtime/_hdl_build/nx_pub_receipt.nx" as *u8, "nx_pub_receipt_gate 13/13 + census 7/3 GREEN (sovereign store)" as *u8, "P2" as *u8, base+5, filed)
79 // NO-TSV doctrine ([[feedback-no-3rd-party-tsv-sovereign-store]]): route the REMAINING existing-organ .tsv migrations
80 // to their owners (don't unilaterally rewrite shared gate-proven organs). The pattern is proven: nx_native_config
81 // + my receipts/coord migration = seg_store + canon, API kept stable, re-gate.
82 ah_file(AH_Q, "hr (Engineer)" as *u8, AH_FROM, "Migrate nx_hr store (nishi_hr.log) + nx_hr_admin/audit scanners off TSV to nx_seg_store+canon (keep the API stable so daemons/torrent/gallery/hub are unaffected); re-gate the HR stack" as *u8, "runtime/_hdl_build/nx_pub_receipt.nx (the migration exemplar) + nx_native_config" as *u8, "receipts+coord already migrated GREEN; seg_store idiom proven" as *u8, "P2" as *u8, base+6, filed)
83 ah_file(AH_Q, "publisher (Builder)" as *u8, AH_FROM, "Migrate the publisher queue (knowledge/publish/queue.tsv) off TSV to nx_seg_store+canon records (idempotent keyed put), like nx_native_config" as *u8, "runtime/nx_native_config.nx (exemplar)" as *u8, "seg_store idiom proven in nx_pub_receipt/nx_acct_admin_handoff" as *u8, "P2" as *u8, base+7, filed)
84 ah_file(AH_Q, "hosting (Caretaker)" as *u8, AH_FROM, "Migrate nishi_entitlements.tsv off TSV: small fixed map -> inline NishiLang table, or seg_store if it grows (NO-TSV doctrine)" as *u8, "feedback-no-3rd-party-tsv-sovereign-store" as *u8, "doctrine: inline small maps / seg_store for growing data" as *u8, "P3" as *u8, base+8, filed)
85
86 g_row("gallery wiring handed off" as *u8, ah_has(AH_Q,"gallery (Engineer)" as *u8,"Adopt nx_hr_access: gate /gallery resources via hac_gate (required=1 family, 3 owner); retire flat/realm-only gating" as *u8), pass)
87 g_row("hub wiring handed off" as *u8, ah_has(AH_Q,"hub (Engineer)" as *u8,"Adopt nx_hr_access: resolve hub access via hac_gate at resource boundaries; retire realm-only gating" as *u8), pass)
88 g_row("daemon rebuild handed off to the publisher" as *u8, ah_has(AH_Q,"publisher (Builder)" as *u8,"Rebuild superuser-aware nx_opaque_login_daemon + nx_lan_signup_daemon from source, pub_submit them; drop the stale reg-close .elf rows" as *u8), pass)
89 g_row("promote/restart handed off to hosting" as *u8, ah_has(AH_Q,"hosting (Caretaker)" as *u8,"After publisher approval: atomic-promote the 2 HR stores + restart opaque login; bring nx_lan_signup_daemon up on LAN with the hub keys; never-brick #26" as *u8), pass)
90 g_w(" filed "); g_n(filed[0]); g_w(" new request(s) this run (idempotent: re-file is a no-op). store=knowledge/store/coord- (seg_store)\n" as *u8)
91
92 g_w("ACCT-ADMIN-HANDOFF rows=6 pass="); g_n(pass[0])
93 if pass[0]==6 { g_w(" verdict=GREEN\n" as *u8)
94 let lg: i64=sys_openat_append("knowledge/status/acct_admin_handoff.log" as *u8, 0x1a4)
95 if lg>=0 { sys_write(lg, "ACCT-ADMIN-HANDOFF pass=6/6 verdict=GREEN\n" as *u8, 41); sys_close(lg) }
96 sys_exit(0); return 0 }
97 g_w(" verdict=RED\n" as *u8); sys_exit(1); return 1
98}