code wiki / (root) / nx_matter_intake_gate.nx

nx_matter_intake_gate.nx source

↩ module page · 100 lines · 5450 B

1// nx_matter_intake_gate.nx -- INDEPENDENT gate for the new-matter intake composition (imports 2// the SAME shipped nx_matter_intake_lib = atlas validation edge). Proves the 6 office 3// capabilities compose as ONE flow with all 3 compliance gates validate-then-commit: clean 4// intake writes through every capability; conflict/rule/consent gates each fire pre-write with 5// NO partial state. SELF-PUBLISHES knowledge/status/office_intake_gate.log (ts= + per-tooth). 6// IDEMPOTENT BY CONSTRUCTION: store prefixes carry a per-run epoch suffix, so a prior run's 7// persisted /tmp state can never poison T1 (the first-run-GREEN-forever-after-RED class, 8// debt 1785883407). license_tier: ORIGINAL 9 10import "nx_matter_intake_lib.nx" 11 12const K_PATHBUF: i64 = 64 13const K_EXIT_MMAP: i64 = 99 14 15func ig_path(prefix: *u8, now: i64) -> *u8 { 16 let b: *u8 = sys_mmap(K_PATHBUF) 17 if (b as i64) == 0 { return 0 as *u8 } 18 var o: i64 = 0 19 o = mt_catcopy(b, o, prefix) 20 o = mt_catn(b, o, now) 21 b[o] = 0 as u8 22 return b 23} 24 25func main() -> i64 { 26 let now: i64 = sys_now_realtime_sec() 27 let pa: *u8 = ig_path("/tmp/nx_intake_gateA-" as *u8, now) 28 let pb: *u8 = ig_path("/tmp/nx_intake_gateB-" as *u8, now) 29 let pc: *u8 = ig_path("/tmp/nx_intake_gateC-" as *u8, now) 30 if (pa as i64) == 0 { return __syscall(93, K_EXIT_MMAP, 0, 0, 0, 0, 0) } 31 if (pb as i64) == 0 { return __syscall(93, K_EXIT_MMAP, 0, 0, 0, 0, 0) } 32 if (pc as i64) == 0 { return __syscall(93, K_EXIT_MMAP, 0, 0, 0, 0, 0) } 33 var t1: i64 = 0 34 var t2: i64 = 0 35 var t3: i64 = 0 36 var t4: i64 = 0 37 var t5: i64 = 0 38 var t6: i64 = 0 39 var t7: i64 = 0 40 // --- scenario A: a clean intake writes through ALL capabilities; a 2nd conflicts --- 41 dk_rule_put(pa, "answer" as *u8, 21, 0, "answer" as *u8) 42 let m1: i64 = intake_new_matter(pa, "acme" as *u8, "Acme Corp" as *u8, "M-001" as *u8, "Acme v.Baker" as *u8, "lit" as *u8, 500000, "Bob Baker" as *u8, "answer" as *u8, 100, "yes" as *u8) 43 // T1 clean intake returns the docketed deadline (day100 + 21cal = 121) 44 if m1 == 121 { t1 = 1 } 45 // T2 trust retainer really deposited (RPC 1.15) 46 if trust_balance(pa, "acme" as *u8) == 500000 { t2 = 1 } 47 // T3 engagement letter boxed AND flagged privileged (e-discovery) 48 let npriv: *i64 = sys_mmap(16) as *i64 49 let plog: *u8 = sys_mmap(256) 50 if (npriv as i64) == 0 { return __syscall(93, K_EXIT_MMAP, 0, 0, 0, 0, 0) } 51 if (plog as i64) == 0 { return __syscall(93, K_EXIT_MMAP, 0, 0, 0, 0, 0) } 52 let nd: i64 = box_matter_scan(pa, "M-001" as *u8, npriv, plog) 53 if nd >= 1 { if npriv[0] == 1 { t3 = 1 } } 54 // T4 conflict of interest: 2nd matter, SAME adverse party -> GATE (RPC 1.7/1.9) 55 let m2: i64 = intake_new_matter(pa, "delta" as *u8, "Delta LLC" as *u8, "M-002" as *u8, "Delta v.Baker" as *u8, "lit" as *u8, 300000, "Bob Baker" as *u8, "answer" as *u8, 100, "yes" as *u8) 56 if m2 == 0 - 1 { t4 = 1 } 57 // T5 the conflict gate blocked ALL of M-002's downstream writes (validate-then-commit: no partial trust) 58 if trust_balance(pa, "delta" as *u8) == 0 { t5 = 1 } 59 // --- scenario B: docket fail-closed on an unknown rule (GATE 2, pre-write) --- 60 let mb: i64 = intake_new_matter(pb, "echo" as *u8, "Echo Inc" as *u8, "M-010" as *u8, "Echo matter" as *u8, "lit" as *u8, 100000, "Zed Zulu" as *u8, "no_such_rule" as *u8, 100, "yes" as *u8) 61 // T6 unknown docket rule -> -2, and NO client was created (pre-write gate = no half-open matter) 62 if mb == 0 - 2 { if trust_balance(pb, "echo" as *u8) == 0 { t6 = 1 } } 63 // --- scenario C: UETA consent gate (GATE 3, pre-write) --- 64 dk_rule_put(pc, "answer" as *u8, 21, 0, "answer" as *u8) 65 let mc: i64 = intake_new_matter(pc, "foxtrot" as *u8, "Foxtrot Co" as *u8, "M-020" as *u8, "Foxtrot matter" as *u8, "lit" as *u8, 100000, "Yan York" as *u8, "answer" as *u8, 100, "no" as *u8) 66 // T7 no client consent -> -3, and NO retainer deposited (UETA/ESIGN, pre-write) 67 if mc == 0 - 3 { if trust_balance(pc, "foxtrot" as *u8) == 0 { t7 = 1 } } 68 69 let pass: i64 = t1 + t2 + t3 + t4 + t5 + t6 + t7 70 let out: *u8 = sys_mmap(512) 71 if (out as i64) == 0 { return __syscall(93, K_EXIT_MMAP, 0, 0, 0, 0, 0) } 72 var o: i64 = 0 73 o = mt_catcopy(out, o, "OFFICE-INTAKE-GATE ts=" as *u8) 74 o = mt_catn(out, o, now) 75 o = mt_catcopy(out, o, " tests=7 pass=" as *u8) 76 o = mt_catn(out, o, pass) 77 o = mt_catcopy(out, o, " t1=" as *u8) 78 o = mt_catn(out, o, t1) 79 o = mt_catcopy(out, o, " t2=" as *u8) 80 o = mt_catn(out, o, t2) 81 o = mt_catcopy(out, o, " t3=" as *u8) 82 o = mt_catn(out, o, t3) 83 o = mt_catcopy(out, o, " t4=" as *u8) 84 o = mt_catn(out, o, t4) 85 o = mt_catcopy(out, o, " t5=" as *u8) 86 o = mt_catn(out, o, t5) 87 o = mt_catcopy(out, o, " t6=" as *u8) 88 o = mt_catn(out, o, t6) 89 o = mt_catcopy(out, o, " t7=" as *u8) 90 o = mt_catn(out, o, t7) 91 o = mt_catcopy(out, o, " clean-intake+trust-deposit+boxed-privileged+conflict-gate+no-partial-write+docket-failclosed+consent-gate | 6-caps-composed-validate-then-commit VERDICT=" as *u8) 92 if pass == 7 { o = mt_catcopy(out, o, "GREEN" as *u8) } 93 if pass != 7 { o = mt_catcopy(out, o, "RED" as *u8) } 94 out[o] = 10 as u8 95 o = o + 1 96 ss_writefile("knowledge/status/office_intake_gate.log" as *u8, out, o) 97 sys_write(1, out, o) 98 if pass == 7 { return __syscall(93, 0, 0, 0, 0, 0, 0) } 99 return __syscall(93, 100 + pass, 0, 0, 0, 0, 0) 100}