code wiki / _hdl_build / nx_vizsla_tenant.nx

nx_vizsla_tenant.nx source

↩ module page · 180 lines · 8817 B

1// nx_vizsla_tenant.nx -- NISHI VIZSLA: the UNIVERSAL (multi-tenant) relationship manager. Operator 2026-06-22: 2// "i want these capabilities that can be universal also available to others on our other nishi systems so the 3// same thing giving me s class relationship management can help them achieve s class." The gated relate engine 4// (nx_vizsla_relate: cadence/ledger/thanks/brief) is ALREADY tenant-isolated BY CONSTRUCTION -- the seg_store 5// CID data plane separates each tenant by store PREFIX. This is the thin tenancy layer (rule 22: COMPOSES the 6// blessed _offc/nx_vizsla_relate.elf, re-implements NOTHING): it maps a <tenant-id> to that tenant's private 7// files+store and forks the engine. Every person gets the SAME S-class engine over THEIR OWN data, with no 8// cross-tenant bleed (proven by nx_vizsla_tenant_gate). Sovereign: no third-party, no shared cloud = 9// per-tenant isolation WITHOUT the snooping every cloud PRM does. 10// 11// <base><tid>.contacts.txt the tenant's people (TIER/CONTACT rows) 12// <base><tid>.relate_log.txt the tenant's interaction journal (TOUCH/OBLIGATION/THANKS/...) 13// <base><tid>.relate- the tenant's private seg_store prefix (isolated CID records) 14// 15// Commands (argv): all forward to the engine over the tenant's resolved paths -- 16// load <base> <tid> [segid] ingest the tenant's journal into their store 17// brief <base> <tid> <today> the tenant's daily counsel (followups/birthdays/thankyous/obligations) 18// cadence|thanks <base> <tid> <today> ; ledger <base> <tid> 19// SECURITY (law 12 -- defensive at the boundary): tenant-id is validated [A-Za-z0-9_-] only -- a '.' or '/' 20// is REJECTED so no tenant can path-traverse into another's files. expect_exit: 1 (no args) license_tier: ORIGINAL 21import "nx_syscalls.nx" 22const K_MAGIC_2048: i64 = 2048 23const K_MAGIC_1024: i64 = 1024 24 25func vt_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 26func vt_p(s: *u8) -> i64 { sys_write(1, s, vt_slen(s)); return 0 } 27 28func vt_eq(a: *u8, b: *u8) -> i64 { 29 var i: i64 = 0 30 var go: i64 = 1 31 while go == 1 { 32 if a[i] != b[i] { return 0 } 33 if a[i] == (0 as u8) { return 1 } 34 i = i + 1 35 } 36 return 0 37} 38 39func vt_cat(dst: *u8, off: i64, s: *u8) -> i64 { 40 var i: i64 = 0 41 while s[i] != (0 as u8) { dst[off + i] = s[i]; i = i + 1 } 42 return off + i 43} 44 45// tenant-id must be nonempty and only [A-Za-z0-9_-] -- rejects '.' and '/' (no path traversal) 46func vt_valid_tid(s: *u8) -> i64 { 47 if s[0] == (0 as u8) { return 0 } 48 var i: i64 = 0 49 while s[i] != (0 as u8) { 50 let c: i64 = s[i] as i64 51 var ok: i64 = 0 52 if c >= 48 { if c <= 57 { ok = 1 } } 53 if c >= 65 { if c <= 90 { ok = 1 } } 54 if c >= 97 { if c <= 122 { ok = 1 } } 55 if c == 45 { ok = 1 } 56 if c == 95 { ok = 1 } 57 if ok == 0 { return 0 } 58 i = i + 1 59 } 60 return 1 61} 62 63func vt_path(out: *u8, base: *u8, tid: *u8, suffix: *u8) -> i64 { 64 var o: i64 = 0 65 o = vt_cat(out, o, base) 66 o = vt_cat(out, o, tid) 67 o = vt_cat(out, o, suffix) 68 out[o] = 0 as u8 69 return o 70} 71 72// fork+exec the blessed relate engine with up to 4 trailing args (stdout inherited); return exit status 73func vt_run(a1: *u8, a2: *u8, a3: *u8, a4: *u8) -> i64 { 74 let pid: i64 = sys_fork() 75 if pid == 0 { 76 let argv: *i64 = sys_mmap(64) as *i64 77 argv[0] = "_offc/nx_vizsla_relate.elf" as *u8 as i64 78 var k: i64 = 1 79 if (a1 as i64) != 0 { argv[k] = a1 as i64; k = k + 1 } 80 if (a2 as i64) != 0 { argv[k] = a2 as i64; k = k + 1 } 81 if (a3 as i64) != 0 { argv[k] = a3 as i64; k = k + 1 } 82 if (a4 as i64) != 0 { argv[k] = a4 as i64; k = k + 1 } 83 argv[k] = 0 84 let envp: *i64 = sys_mmap(16) as *i64 85 envp[0] = 0 86 sys_execve("_offc/nx_vizsla_relate.elf" as *u8, argv, envp) 87 sys_exit(127) 88 } 89 let st: *i64 = sys_mmap(16) as *i64 90 sys_wait4(pid, st, 0) 91 let sig: i64 = st[0] & 0x7f 92 if sig != 0 { return 128 + sig } 93 return (st[0] >> 8) & 0xff 94} 95 96func vt_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 } 97 98func vt_writefile(path: *u8, content: *u8) -> i64 { 99 let fd: i64 = sys_openat_wr(path, 0x1a4) 100 if fd < 0 { return 0 - 1 } 101 sys_write(fd, content, vt_slen(content)) 102 sys_close(fd) 103 return 0 104} 105 106// append "a0 a1 a2 a3 a4\n" (skipping null trailing tokens) to a file -- the frictionless-capture writer 107func vt_append5(path: *u8, a0: *u8, a1: *u8, a2: *u8, a3: *u8, a4: *u8) -> i64 { 108 let buf: *u8 = sys_mmap(K_MAGIC_2048) 109 var o: i64 = 0 110 o = vt_cat(buf, o, a0) 111 if (a1 as i64) != 0 { buf[o] = 32 as u8; o = o + 1; o = vt_cat(buf, o, a1) } 112 if (a2 as i64) != 0 { buf[o] = 32 as u8; o = o + 1; o = vt_cat(buf, o, a2) } 113 if (a3 as i64) != 0 { buf[o] = 32 as u8; o = o + 1; o = vt_cat(buf, o, a3) } 114 if (a4 as i64) != 0 { buf[o] = 32 as u8; o = o + 1; o = vt_cat(buf, o, a4) } 115 buf[o] = 10 as u8; o = o + 1 116 let fd: i64 = sys_openat_append(path, 0x1a4) 117 if fd < 0 { return 0 - 1 } 118 sys_write(fd, buf, o) 119 sys_close(fd) 120 return 0 121} 122 123func main(argc: i64, argv: *i64) -> i64 { 124 if argc < 4 { vt_p("VIZSLA-TENANT usage: <provision|add-contact|touch|load|brief|cadence|ledger|thanks> <base> <tenant-id> [args] -- fail loud\n" as *u8); return 1 } 125 let cmd: *u8 = argv[1] as *u8 126 let base: *u8 = argv[2] as *u8 127 let tid: *u8 = argv[3] as *u8 128 if vt_valid_tid(tid) == 0 { vt_p("VIZSLA-TENANT invalid tenant-id (need [A-Za-z0-9_-], no . or /) -- fail loud\n" as *u8); return 1 } 129 130 let prefix: *u8 = sys_mmap(K_MAGIC_1024) 131 vt_path(prefix, base, tid, ".relate-" as *u8) 132 133 if vt_eq(cmd, "load" as *u8) == 1 { 134 let logp: *u8 = sys_mmap(K_MAGIC_1024) 135 vt_path(logp, base, tid, ".relate_log.txt" as *u8) 136 if argc > 4 { return vt_run("load" as *u8, logp, prefix, argv[4] as *u8) } 137 return vt_run("load" as *u8, logp, prefix, 0 as *u8) 138 } 139 140 let contacts: *u8 = sys_mmap(K_MAGIC_1024) 141 vt_path(contacts, base, tid, ".contacts.txt" as *u8) 142 let logp: *u8 = sys_mmap(K_MAGIC_1024) 143 vt_path(logp, base, tid, ".relate_log.txt" as *u8) 144 145 // provision: create a fresh tenant's starter files (idempotent -- never clobbers existing data) 146 if vt_eq(cmd, "provision" as *u8) == 1 { 147 if vt_exists(contacts) == 0 { vt_writefile(contacts, "CONF soon_days 14\nTIER inner 14\nTIER close 45\nTIER network 120\n" as *u8) } 148 if vt_exists(logp) == 0 { vt_writefile(logp, "# interaction journal -- append TOUCH/OBLIGATION/THANKS lines\n" as *u8) } 149 vt_p("VIZSLA-TENANT provisioned tenant=" as *u8); vt_p(tid); vt_p(" (now add-contact, or edit " as *u8); vt_p(contacts); vt_p(")\n" as *u8); return 0 150 } 151 // add-contact: append one person (tier must be an existing TIER in the tenant's contacts file) 152 if vt_eq(cmd, "add-contact" as *u8) == 1 { 153 if argc < 8 { vt_p("VIZSLA-TENANT add-contact needs <id> <display> <tier> <bday MM-DD|-> -- fail loud\n" as *u8); return 1 } 154 if vt_append5(contacts, "CONTACT" as *u8, argv[4] as *u8, argv[5] as *u8, argv[6] as *u8, argv[7] as *u8) != 0 { vt_p("VIZSLA-TENANT add-contact append FAILED -- fail loud\n" as *u8); return 1 } 155 vt_p("VIZSLA-TENANT add-contact " as *u8); vt_p(argv[4] as *u8); vt_p(" -> " as *u8); vt_p(tid); vt_p("\n" as *u8); return 0 156 } 157 // touch: log "I connected with them on <date>" -> append to journal + re-load the store 158 if vt_eq(cmd, "touch" as *u8) == 1 { 159 if argc < 7 { vt_p("VIZSLA-TENANT touch needs <date> <contact-id> <note> -- fail loud\n" as *u8); return 1 } 160 if vt_append5(logp, "TOUCH" as *u8, argv[4] as *u8, argv[5] as *u8, argv[6] as *u8, 0 as *u8) != 0 { vt_p("VIZSLA-TENANT touch append FAILED -- fail loud\n" as *u8); return 1 } 161 return vt_run("load" as *u8, logp, prefix, 0 as *u8) 162 } 163 164 if vt_eq(cmd, "ledger" as *u8) == 1 { return vt_run("ledger" as *u8, prefix, contacts, 0 as *u8) } 165 166 if vt_eq(cmd, "brief" as *u8) == 1 { 167 if argc < 5 { vt_p("VIZSLA-TENANT brief needs <today> -- fail loud\n" as *u8); return 1 } 168 return vt_run("brief" as *u8, prefix, contacts, argv[4] as *u8) 169 } 170 if vt_eq(cmd, "cadence" as *u8) == 1 { 171 if argc < 5 { vt_p("VIZSLA-TENANT cadence needs <today> -- fail loud\n" as *u8); return 1 } 172 return vt_run("cadence" as *u8, prefix, contacts, argv[4] as *u8) 173 } 174 if vt_eq(cmd, "thanks" as *u8) == 1 { 175 if argc < 5 { vt_p("VIZSLA-TENANT thanks needs <today> -- fail loud\n" as *u8); return 1 } 176 return vt_run("thanks" as *u8, prefix, contacts, argv[4] as *u8) 177 } 178 vt_p("VIZSLA-TENANT unknown command (load|brief|cadence|ledger|thanks) -- fail loud\n" as *u8) 179 return 1 180}