code wiki / _hdl_build / nx_carflip_deal.nx

nx_carflip_deal.nx source

↩ module page · 74 lines · 3383 B

1// nx_carflip_deal.nx -- R6-v2 DATA-DRIVEN deal scorer for the Car-Flip lane. Fuses the 2// knowledge/store/carflip-fail- failure-prior plane (REAL NHTSA-derived rows, seeded via 3// nx_store_put -- compose, never re-implement the store) with the P10-gated calc from 4// nx_carflip_lib. For the given vehicle key it prints every known failure-mode row as a 5// warn= line BEFORE the verdict, so the operator prices repair_high with eyes open (the 6// 2013-Focus DPS6 class of trap has NO safety recall; only the plane carries it -- a 7// recall-only view is a flip trap). FAIL-CLOSED: absent plane = exit 3, a missing priors 8// plane is a defect, never a clean bill (rule 20 fail-fast + no-vacuity). warns=0 for a 9// covered call emits an explicit coverage caveat rather than silent cleanliness. 10// usage: nx_carflip_deal <vehicle-key> <asking> <resale_typ> <resale_low> <repair_typ> <repair_high> <recon> <transport> <fees> <sell_cost> <holding> 11// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 12import "nx_carflip_lib.nx" 13import "nx_store_seed_lib.nx" 14import "nx_seg_store.nx" 15import "nx_syscalls.nx" 16 17const CFD_CAP: i64 = 1048576 18const CFD_MARGIN: i64 = 4096 19const CFD_NL: i64 = 10 20 21// does row span [i,le) of buffer b contain the NUL-terminated needle q? 22func cfd_rowhas(b: *u8, i: i64, le: i64, q: *u8) -> i64 { 23 var ql: i64 = 0 24 while q[ql] != (0 as u8) { ql = ql + 1 } 25 if ql == 0 { return 0 } 26 var p: i64 = i 27 while p + ql <= le { 28 var k: i64 = 0 29 var ok: i64 = 1 30 while k < ql { if b[p + k] != q[k] { ok = 0; k = ql } else { k = k + 1 } } 31 if ok == 1 { return 1 } 32 p = p + 1 33 } 34 return 0 35} 36 37func main(argc: i64, argv: *i64) -> i64 { 38 if argc < 12 { 39 cf_puts("usage: nx_carflip_deal <vehicle-key> <asking> <resale_typ> <resale_low> <repair_typ> <repair_high> <recon> <transport> <fees> <sell_cost> <holding> (whole USD)\n" as *u8) 40 sys_exit(2) 41 return 2 42 } 43 let vkey: *u8 = argv[1] as *u8 44 let b: *u8 = sys_mmap(CFD_CAP) 45 let n: i64 = sts_load("knowledge/store/carflip-fail-" as *u8, b, CFD_CAP - CFD_MARGIN) 46 if n <= 0 { 47 cf_puts("CARFLIP-DEAL\nerror=PRIORS-PLANE-ABSENT knowledge/store/carflip-fail- (fail-closed: a missing priors plane is a defect, not a clean bill)\n" as *u8) 48 sys_exit(3) 49 return 3 50 } 51 cf_puts("CARFLIP-DEAL\n" as *u8) 52 cf_puts("vehicle=" as *u8) 53 cf_puts(vkey) 54 cf_puts("\n" as *u8) 55 var warns: i64 = 0 56 var i: i64 = 0 57 while i < n { 58 var le: i64 = i 59 var s: i64 = 1 60 while s == 1 { if le >= n { s = 0 } else { if b[le] == (CFD_NL as u8) { s = 0 } else { le = le + 1 } } } 61 if le > i { if cfd_rowhas(b, i, le, vkey) == 1 { 62 warns = warns + 1 63 cf_puts("warn=" as *u8) 64 sys_write(1, (b as i64 + i) as *u8, le - i) 65 cf_puts("\n" as *u8) 66 } } 67 i = le + 1 68 } 69 cf_kv("warns" as *u8, warns) 70 if warns == 0 { cf_puts("coverage=NO-PRIORS-FOR-VEHICLE (verify plane coverage before trusting a clean scan)\n" as *u8) } 71 cf_score(cf_atoi(argv[2] as *u8), cf_atoi(argv[3] as *u8), cf_atoi(argv[4] as *u8), cf_atoi(argv[5] as *u8), cf_atoi(argv[6] as *u8), cf_atoi(argv[7] as *u8), cf_atoi(argv[8] as *u8), cf_atoi(argv[9] as *u8), cf_atoi(argv[10] as *u8), cf_atoi(argv[11] as *u8)) 72 sys_exit(0) 73 return 0 74}