code wiki / _hdl_build / nx_gonogo.nx

nx_gonogo.nx source

↩ module page · 170 lines · 9495 B

1// nx_gonogo.nx -- THE dmkt CAPSTONE (F317 / milestone M9): the GO / NO-GO decision gate. 2// 3// The lane's charter claims a CLOSED idea-to-market loop. Without this organ the loop was open: 4// nx_product_score could score CAPABILITY COVERAGE but had no economics, and nx_sourcing_path could 5// price a sourcing mix but had no verdict. This joins them. 6// 7// ★★THE DESIGN HINGES ON A THIRD VERDICT. A gate that can only answer GO or NO-GO **will fabricate**: 8// asked to decide with a missing input it must invent one, and the invented one is always the one 9// nobody can check. So the verdict space is GO | NO-GO | BLOCKED-ON-EVIDENCE, and the blocked state 10// NAMES the evidence it lacks. This is the operator's no-fake-numbers law expressed as control flow 11// rather than as a comment. 12// 13// ★★THE ASYMMETRY IS THE WHOLE VALUE. Missing evidence blocks a GO but must NEVER block a NO-GO. 14// A product whose priced mix loses money is rejectable TODAY, with no demand study, no market 15// research and no propensity model -- you do not need to know how many people want a thing to know 16// you cannot afford to make it. Checking hard failures FIRST is what stops this gate degenerating 17// into a permanently-blocked oracle that answers nothing. Cheap disqualification is a feature. 18// 19// DATA, NOT CODE (rule 11): every threshold is a plane row. There is not one hardcoded bar here. 20// `gonogothresh-` : <id> TAB <label> TAB <value> 21// margin_floor_permil | domestic_floor_permil | risk_ceiling | coverage_floor_permil 22// `demand-` : ANY row = demand evidence exists. ZERO rows = the demand gate is BLIND. 23// Set a threshold to 0 to disable that gate deliberately -- an explicit, auditable waiver. 24// 25// Composes nx_sourcing_path (which composes nx_landed_cost) -- one duty implementation, one mix 26// pricer, no copies. Target-imports-target is proven and gated by nx_lcimport_test. 27// 28// VERBS: 29// nx_gonogo verdict <bomprefix> <units> <unitprice_c> <ocean01> <pref01> <incprefix> <threshprefix> <demandprefix> [coverage_permil|-1] 30// nx_gonogo selftest 31// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 32import "nx_syscalls.nx" 33import "nx_sourcing_path.nx" 34import "nx_evidence.nx" 35 36const GG_GO: i64 = 0 37const GG_NOGO: i64 = 1 38const GG_BLOCKED: i64 = 2 39const GG_UNKNOWN: i64 = 0 - 1 40const GG_BUF: i64 = 65536 41 42// reason slots in k[]: which gate fired. 0 margin 1 risk 2 coverage 3 domestic | 4 demand-missing 5 coverage-missing 43func gg_decide(margin: i64, margin_floor: i64, risk: i64, risk_ceil: i64, cov: i64, cov_floor: i64, dom: i64, dom_floor: i64, demand_rows: i64, k: *i64) -> i64 { 44 var i: i64 = 0 45 while i < 8 { k[i] = 0; i = i + 1 } 46 var hard: i64 = 0 47 // ---- HARD FAILURES FIRST. Each is decidable from evidence we ALREADY hold, so none of them 48 // needs the demand study. A threshold of 0 means the operator deliberately disabled that gate. 49 if margin_floor > 0 { if margin < margin_floor { hard = 1; k[0] = 1 } } 50 if risk_ceil > 0 { if risk > risk_ceil { hard = 1; k[1] = 1 } } 51 if cov_floor > 0 { if cov != GG_UNKNOWN { if cov < cov_floor { hard = 1; k[2] = 1 } } } 52 if dom_floor > 0 { if dom < dom_floor { hard = 1; k[3] = 1 } } 53 if hard == 1 { return GG_NOGO } 54 // ---- only now does absent evidence matter. Nothing above could be rescued by it. 55 var missing: i64 = 0 56 if demand_rows <= 0 { missing = 1; k[4] = 1 } 57 if cov == GG_UNKNOWN { if cov_floor > 0 { missing = 1; k[5] = 1 } } 58 if missing == 1 { return GG_BLOCKED } 59 return GG_GO 60} 61 62func gg_thresh(buf: *u8, n: i64, id: *u8, scratch: *u8, dflt: i64) -> i64 { 63 var r: i64 = 0 64 let cnt: i64 = sp_rowcount(buf, n) 65 while r < cnt { 66 let rs: i64 = sp_row_start(buf, n, r) 67 if rs >= 0 { 68 lc_extract(buf, n, rs, 0, scratch, SP_FLDBUF) 69 if lc_eq(scratch, id) == 1 { return sp_num(buf, n, rs, 2, scratch) } 70 } 71 r = r + 1 72 } 73 return dflt 74} 75 76func gg_word(v: i64) -> *u8 { 77 if v == GG_GO { return "GO" as *u8 } 78 if v == GG_NOGO { return "NO-GO" as *u8 } 79 return "BLOCKED-ON-EVIDENCE" as *u8 80} 81 82func gg_reason(out: *u8, o: i64, k: *i64) -> i64 { 83 var p: i64 = o 84 var first: i64 = 1 85 p = lc_lit(out, p, ",\"failed_gates\":[" as *u8) 86 if k[0] == 1 { if first == 0 { out[p] = 44 as u8; p = p + 1 } first = 0; p = lc_lit(out, p, "\"margin_below_floor\"" as *u8) } 87 if k[1] == 1 { if first == 0 { out[p] = 44 as u8; p = p + 1 } first = 0; p = lc_lit(out, p, "\"supply_risk_above_ceiling\"" as *u8) } 88 if k[2] == 1 { if first == 0 { out[p] = 44 as u8; p = p + 1 } first = 0; p = lc_lit(out, p, "\"capability_coverage_below_floor\"" as *u8) } 89 if k[3] == 1 { if first == 0 { out[p] = 44 as u8; p = p + 1 } first = 0; p = lc_lit(out, p, "\"domestic_content_below_floor\"" as *u8) } 90 p = lc_lit(out, p, "],\"missing_evidence\":[" as *u8) 91 first = 1 92 if k[4] == 1 { first = 0; p = lc_lit(out, p, "\"demand: no CORROBORATED demand evidence. Rows may exist and still count zero -- an ECHO of a single incentive class, sources too weak to judge, or failure-class rows that prove the category breaks rather than that anyone will buy\"" as *u8) } 93 if k[5] == 1 { if first == 0 { out[p] = 44 as u8; p = p + 1 } p = lc_lit(out, p, "\"capability_coverage: pass it in, or run nx_product_score\"" as *u8) } 94 p = lc_lit(out, p, "]" as *u8) 95 return p 96} 97 98func main(argc: i64, argv: *i64) -> i64 { 99 if argc < 2 { spw(2, "usage: nx_gonogo verdict <bomprefix> <units> <unitprice_c> <ocean01> <pref01> <incprefix> <threshprefix> <demandprefix> [coverage_permil|-1]\n" as *u8); return 2 } 100 let verb: *u8 = argv[1] as *u8 101 if lc_eq(verb, "verdict" as *u8) == 0 { spw(2, "usage: nx_gonogo verdict <bomprefix> <units> <unitprice_c> <ocean01> <pref01> <incprefix> <threshprefix> <demandprefix> [coverage_permil|-1]\n" as *u8); return 2 } 102 if argc < 10 { spw(2, "verdict needs 8 args: <bomprefix> <units> <unitprice_c> <ocean01> <pref01> <incprefix> <threshprefix> <demandprefix> [coverage_permil|-1]\n" as *u8); return 2 } 103 let bom: *u8 = sys_mmap(GG_BUF) 104 let bn: i64 = sts_load(argv[2] as *u8, bom, GG_BUF) 105 if bn <= 0 { spw(2, "BOM PLANE EMPTY OR ABSENT -- refusing to judge a product that was never described\n" as *u8); return 3 } 106 let units: i64 = lc_atoi(argv[3] as *u8) 107 let price: i64 = lc_atoi(argv[4] as *u8) 108 let ocean: i64 = lc_atoi(argv[5] as *u8) 109 let pref: i64 = lc_atoi(argv[6] as *u8) 110 let scratch: *u8 = sys_mmap(SP_FLDBUF) 111 var incpermil: i64 = 0 112 let ibuf: *u8 = sys_mmap(GG_BUF) 113 let inn: i64 = sts_load(argv[7] as *u8, ibuf, GG_BUF) 114 if inn > 0 { incpermil = sp_inc_permil(ibuf, inn, scratch) } 115 let tbuf: *u8 = sys_mmap(GG_BUF) 116 let tn: i64 = sts_load(argv[8] as *u8, tbuf, GG_BUF) 117 let dbuf: *u8 = sys_mmap(GG_BUF) 118 let dn: i64 = sts_load(argv[9] as *u8, dbuf, GG_BUF) 119 // ★NOT sp_rowcount. A ROW COUNT IS NOT EVIDENCE -- it measures harvesting effort, not truth. 120 // ev_count admits a row only if its grades are VALID and ACTIONABLE (Admiralty F/6 are honest 121 // cannot-judge states that owe a fetch-task, never a verdict), and then returns ZERO unless the 122 // admitted rows span >=2 DISTINCT incentive classes. Ten rows from one interest is one voice. 123 // It also filters by CLASS: a product-recall row is failure-mode evidence and proves the 124 // category breaks, never that anyone will buy it. Conflating those was this gate's own defect. 125 var demand_rows: i64 = 0 126 if dn > 0 { demand_rows = ev_count(dbuf, dn, "demand" as *u8, scratch) } 127 var cov: i64 = GG_UNKNOWN 128 if argc >= 11 { 129 let covs: *u8 = argv[10] as *u8 130 if covs[0] == (45 as u8) { cov = GG_UNKNOWN } else { cov = lc_atoi(covs) } 131 } 132 let mfloor: i64 = gg_thresh(tbuf, tn, "margin_floor_permil" as *u8, scratch, 0) 133 let rceil: i64 = gg_thresh(tbuf, tn, "risk_ceiling" as *u8, scratch, 0) 134 let cfloor: i64 = gg_thresh(tbuf, tn, "coverage_floor_permil" as *u8, scratch, 0) 135 let dfloor: i64 = gg_thresh(tbuf, tn, "domestic_floor_permil" as *u8, scratch, 0) 136 let rbuf: *u8 = sys_mmap(LC_REGBUF) 137 let rn: i64 = lc_load_regime(rbuf) 138 let res: *i64 = sys_mmap(128) as *i64 139 sp_mix(bom, bn, rbuf, rn, units, price, ocean, pref, incpermil, 0, res) 140 let k: *i64 = sys_mmap(64) as *i64 141 let v: i64 = gg_decide(res[9], mfloor, res[6], rceil, cov, cfloor, res[5], dfloor, demand_rows, k) 142 let out: *u8 = sys_mmap(GG_BUF) 143 var o: i64 = 0 144 o = lc_lit(out, o, "{\"verdict\":\"" as *u8) 145 o = lc_lit(out, o, gg_word(v)) 146 o = lc_lit(out, o, "\",\"margin_permil\":" as *u8) 147 o = lc_num(out, o, res[9]) 148 o = lc_lit(out, o, ",\"margin_floor_permil\":" as *u8) 149 o = lc_num(out, o, mfloor) 150 o = lc_lit(out, o, ",\"domestic_permil\":" as *u8) 151 o = lc_num(out, o, res[5]) 152 o = lc_lit(out, o, ",\"domestic_floor_permil\":" as *u8) 153 o = lc_num(out, o, dfloor) 154 o = lc_lit(out, o, ",\"supply_risk\":" as *u8) 155 o = lc_num(out, o, res[6]) 156 o = lc_lit(out, o, ",\"risk_ceiling\":" as *u8) 157 o = lc_num(out, o, rceil) 158 o = lc_lit(out, o, ",\"coverage_permil\":" as *u8) 159 o = lc_num(out, o, cov) 160 o = lc_lit(out, o, ",\"net_landed_c\":" as *u8) 161 o = lc_num(out, o, res[8]) 162 o = lc_lit(out, o, ",\"demand_rows\":" as *u8) 163 o = lc_num(out, o, demand_rows) 164 o = gg_reason(out, o, k) 165 o = lc_lit(out, o, "}" as *u8) 166 out[o] = 10 as u8; o = o + 1 167 out[o] = 0 as u8 168 spw(1, out) 169 return 0 170}