code wiki / (root) / nx_licgate.nx

nx_licgate.nx source

↩ module page · 356 lines · 18741 B

1// nx_licgate.nx -- thin CLI over nx_licgate_lib (the shippability verdict). 2// 3// The table and the intersection live in the LIB so the EMIT PATH and this command line prove the 4// SAME code. A gate that only exists as a CLI is a gate the generator can forget to call. 5// 6// EXIT: 0 SHIP_OK | 3 REVIEW (a conditional term a machine may not settle) | 4 REFUSE | 2 usage. 7// REVIEW is not a pass -- it is a human's decision, unmade. 8// license_tier: ORIGINAL expect_exit: 0 9import "nx_syscalls.nx" 10import "nx_licgate_lib.nx" 11const K_MAGIC_262144: i64 = 262144 12 13// Append the VERBATIM table line whose tag matches and whose field-1 id equals `id`. 14// Verbatim on purpose: counsel should review the source row, not my transcription of it. A dossier 15// that paraphrases its own evidence is a summary, not a record. 16func lg_row_verbatim(out: *u8, at: i64, buf: *u8, n: i64, tag: i64, id: *u8) -> i64 { 17 let box: *i64 = sys_mmap(32) as *i64 18 var o: i64 = at 19 var p: i64 = 0 20 var done: i64 = 0 21 while p < n { 22 var q: i64 = p 23 var g: i64 = 1 24 while g == 1 { 25 if q >= n { g = 0 } 26 else { if buf[q] == (10 as u8) { g = 0 } else { q = q + 1 } } 27 } 28 if done == 0 { 29 if q > p + 1 { 30 if buf[p] == (tag as u8) { 31 if buf[p + 1] == (9 as u8) { 32 lg_field(buf, p, q, 1, box) 33 if lg_seq(buf, box[0], box[1], id) == 1 { 34 o = lg_putn(out, o, buf, p, q - p) 35 o = lg_put(out, o, "\n" as *u8) 36 done = 1 37 } 38 } 39 } 40 } 41 } 42 p = q + 1 43 } 44 if done == 0 { o = lg_put(out, o, " (NO ROW FOUND -- this component is unknown to the table)\n" as *u8) } 45 return o 46} 47 48func main(argc: i64, argv: *i64) -> i64 { 49 let out: *u8 = sys_mmap(K_MAGIC_262144) 50 var o: i64 = 0 51 if argc < 2 { 52 o = lg_put(out, o, "usage: nx_licgate {chain <model_id>... | list | selftest}\n" as *u8) 53 o = lg_put(out, o, " chain intersect output rights over a provenance chain\n" as *u8) 54 o = lg_put(out, o, " exit 0 SHIP_OK | 3 REVIEW | 4 REFUSE (unknown model or non-commercial output)\n" as *u8) 55 sys_write(1, out, o) 56 return 0 57 } 58 let verb: *u8 = argv[1] as *u8 59 let ctx: *i64 = lg_ctx() 60 if ctx[3] < 0 { 61 o = lg_put(out, o, "{\x22v\x22:1,\x22organ\x22:\x22nx_licgate\x22,\x22verdict\x22:\x22REFUSE\x22,\x22reason\x22:\x22rights table unreadable -- fail-closed\x22,\x22exit\x22:4}\n" as *u8) 62 sys_write(1, out, o) 63 sys_exit(4) 64 return 4 65 } 66 let buf: *u8 = ctx[0] as *u8 67 let n: i64 = ctx[1] 68 let lic: *i64 = ctx[2] as *i64 69 let nlic: i64 = ctx[3] 70 let mods: *i64 = ctx[4] as *i64 71 let nmod: i64 = ctx[5] 72 73 if lg_ceq(verb, "list" as *u8) == 1 { 74 o = lg_put(out, o, "{\x22v\x22:1,\x22organ\x22:\x22nx_licgate\x22,\x22verb\x22:\x22list\x22,\x22licenses\x22:" as *u8) 75 o = lg_putd(out, o, nlic) 76 o = lg_put(out, o, ",\x22models\x22:" as *u8) 77 o = lg_putd(out, o, nmod) 78 o = lg_put(out, o, ",\x22rows\x22:[" as *u8) 79 var i: i64 = 0 80 while i < nmod { 81 if i > 0 { o = lg_put(out, o, "," as *u8) } 82 o = lg_put(out, o, "{\x22model\x22:\x22" as *u8) 83 o = lg_putn(out, o, buf, mods[i * 5 + 0], mods[i * 5 + 1]) 84 o = lg_put(out, o, "\x22,\x22kind\x22:\x22" as *u8) 85 o = lg_putn(out, o, buf, mods[i * 5 + 3], mods[i * 5 + 4]) 86 o = lg_put(out, o, "\x22,\x22license\x22:\x22" as *u8) 87 let li: i64 = mods[i * 5 + 2] 88 if li >= 0 { 89 o = lg_putn(out, o, buf, lic[li * 7 + 0], lic[li * 7 + 1]) 90 o = lg_put(out, o, "\x22,\x22out_commercial\x22:" as *u8) 91 o = lg_putd(out, o, lic[li * 7 + 2]) 92 o = lg_put(out, o, ",\x22verified\x22:" as *u8) 93 o = lg_putd(out, o, lic[li * 7 + 6]) 94 } else { 95 o = lg_put(out, o, "UNRESOLVED\x22,\x22out_commercial\x22:0,\x22verified\x22:0" as *u8) 96 } 97 o = lg_put(out, o, "}" as *u8) 98 i = i + 1 99 } 100 o = lg_put(out, o, "]}\n" as *u8) 101 sys_write(1, out, o) 102 return 0 103 } 104 105 if lg_ceq(verb, "selftest" as *u8) == 1 { 106 let nm: *i64 = sys_mmap(64) as *i64 107 var pass: i64 = 0 108 var fail: i64 = 0 109 o = lg_put(out, o, "{\x22v\x22:1,\x22organ\x22:\x22nx_licgate\x22,\x22verb\x22:\x22selftest\x22,\x22teeth\x22:[" as *u8) 110 111 nm[0] = ("chroma1-hd" as *u8) as i64 112 o = lg_put(out, o, "{\x22t\x22:1,\x22name\x22:\x22permissive-single-ships\x22,\x22want\x22:0,\x22got\x22:" as *u8) 113 var g1: i64 = lg_verdict(nm, 1) 114 o = lg_putd(out, o, g1) 115 if g1 == 0 { pass = pass + 1; o = lg_put(out, o, ",\x22ok\x22:1}" as *u8) } else { fail = fail + 1; o = lg_put(out, o, ",\x22ok\x22:0}" as *u8) } 116 117 nm[0] = ("noobai-xl-1.0" as *u8) as i64 118 o = lg_put(out, o, ",{\x22t\x22:2,\x22name\x22:\x22noncommercial-output-refused\x22,\x22want\x22:4,\x22got\x22:" as *u8) 119 var g2: i64 = lg_verdict(nm, 1) 120 o = lg_putd(out, o, g2) 121 if g2 == 4 { pass = pass + 1; o = lg_put(out, o, ",\x22ok\x22:1}" as *u8) } else { fail = fail + 1; o = lg_put(out, o, ",\x22ok\x22:0}" as *u8) } 122 123 nm[0] = ("chroma1-hd" as *u8) as i64 124 nm[1] = ("noobai-xl-1.0" as *u8) as i64 125 o = lg_put(out, o, ",{\x22t\x22:3,\x22name\x22:\x22one-poisoned-link-poisons-chain\x22,\x22want\x22:4,\x22got\x22:" as *u8) 126 var g3: i64 = lg_verdict(nm, 2) 127 o = lg_putd(out, o, g3) 128 if g3 == 4 { pass = pass + 1; o = lg_put(out, o, ",\x22ok\x22:1}" as *u8) } else { fail = fail + 1; o = lg_put(out, o, ",\x22ok\x22:0}" as *u8) } 129 130 nm[0] = ("no-such-model-xyz" as *u8) as i64 131 o = lg_put(out, o, ",{\x22t\x22:4,\x22name\x22:\x22unknown-model-fails-closed\x22,\x22want\x22:4,\x22got\x22:" as *u8) 132 var g4: i64 = lg_verdict(nm, 1) 133 o = lg_putd(out, o, g4) 134 if g4 == 4 { pass = pass + 1; o = lg_put(out, o, ",\x22ok\x22:1}" as *u8) } else { fail = fail + 1; o = lg_put(out, o, ",\x22ok\x22:0}" as *u8) } 135 136 nm[0] = ("chroma1-hd" as *u8) as i64 137 nm[1] = ("wan2.2" as *u8) as i64 138 nm[2] = ("kokoro-82m" as *u8) as i64 139 o = lg_put(out, o, ",{\x22t\x22:5,\x22name\x22:\x22permissive-multimodal-ships\x22,\x22want\x22:0,\x22got\x22:" as *u8) 140 var g5: i64 = lg_verdict(nm, 3) 141 o = lg_putd(out, o, g5) 142 if g5 == 0 { pass = pass + 1; o = lg_put(out, o, ",\x22ok\x22:1}" as *u8) } else { fail = fail + 1; o = lg_put(out, o, ",\x22ok\x22:0}" as *u8) } 143 144 nm[0] = ("chroma1-hd" as *u8) as i64 145 nm[1] = ("xtts-v2" as *u8) as i64 146 o = lg_put(out, o, ",{\x22t\x22:6,\x22name\x22:\x22noncommercial-tts-caught\x22,\x22want\x22:4,\x22got\x22:" as *u8) 147 var g6: i64 = lg_verdict(nm, 2) 148 o = lg_putd(out, o, g6) 149 if g6 == 4 { pass = pass + 1; o = lg_put(out, o, ",\x22ok\x22:1}" as *u8) } else { fail = fail + 1; o = lg_put(out, o, ",\x22ok\x22:0}" as *u8) } 150 151 let res7: *i64 = sys_mmap(64) as *i64 152 nm[0] = ("illustrious-xl" as *u8) as i64 153 lg_eval(ctx, nm, 1, res7) 154 o = lg_put(out, o, ",{\x22t\x22:7,\x22name\x22:\x22deriv-must-open-propagates\x22,\x22want\x22:1,\x22got\x22:" as *u8) 155 o = lg_putd(out, o, res7[3]) 156 if res7[3] == 1 { pass = pass + 1; o = lg_put(out, o, ",\x22ok\x22:1}" as *u8) } else { fail = fail + 1; o = lg_put(out, o, ",\x22ok\x22:0}" as *u8) } 157 158 o = lg_put(out, o, ",{\x22t\x22:8,\x22name\x22:\x22empty-chain-not-a-pass\x22,\x22want\x22:4,\x22got\x22:" as *u8) 159 var g8: i64 = lg_verdict(nm, 0) 160 o = lg_putd(out, o, g8) 161 if g8 == 4 { pass = pass + 1; o = lg_put(out, o, ",\x22ok\x22:1}" as *u8) } else { fail = fail + 1; o = lg_put(out, o, ",\x22ok\x22:0}" as *u8) } 162 163 o = lg_put(out, o, "],\x22pass\x22:" as *u8) 164 o = lg_putd(out, o, pass) 165 o = lg_put(out, o, ",\x22fail\x22:" as *u8) 166 o = lg_putd(out, o, fail) 167 o = lg_put(out, o, ",\x22verdict\x22:\x22" as *u8) 168 if fail == 0 { o = lg_put(out, o, "GREEN" as *u8) } else { o = lg_put(out, o, "RED" as *u8) } 169 o = lg_put(out, o, "\x22}\n" as *u8) 170 sys_write(1, out, o) 171 if fail != 0 { sys_exit(1) } 172 return 0 173 } 174 175 if lg_ceq(verb, "dossier" as *u8) == 1 { 176 let cnt: i64 = argc - 2 177 let nm: *i64 = sys_mmap((cnt + 2) * 8) as *i64 178 var i: i64 = 0 179 while i < cnt { nm[i] = argv[i + 2]; i = i + 1 } 180 let res: *i64 = sys_mmap(64) as *i64 181 lg_eval(ctx, nm, cnt, res) 182 183 o = lg_put(out, o, "NISHI LICENCE DOSSIER -- PREPARED FOR COUNSEL REVIEW\n" as *u8) 184 o = lg_put(out, o, "====================================================\n\n" as *u8) 185 o = lg_put(out, o, "This document is a RECORD OF FACTS as transcribed into knowledge/model_license.conf.\n" as *u8) 186 o = lg_put(out, o, "It is NOT legal advice and NOT a determination that any use is permitted. No system in\n" as *u8) 187 o = lg_put(out, o, "this ecosystem acts on it: nothing is blocked or approved automatically on its basis.\n" as *u8) 188 o = lg_put(out, o, "Rows are reproduced VERBATIM so counsel reviews the source text, not a paraphrase.\n\n" as *u8) 189 o = lg_put(out, o, "RIGHT ENCODING: 0 = denied, 1 = conditional (a term a machine may not settle), 2 = granted.\n" as *u8) 190 o = lg_put(out, o, "COLUMNS (L rows): licence_id, sell_output, redistribute_weights, paid_service, derivatives_must_stay_open, verified, note\n" as *u8) 191 o = lg_put(out, o, "COLUMNS (M rows): model_id, licence_id, kind, note\n\n" as *u8) 192 o = lg_put(out, o, "COMPONENTS IN THE CHAIN UNDER REVIEW: " as *u8) 193 o = lg_putd(out, o, cnt) 194 o = lg_put(out, o, "\n\n" as *u8) 195 196 i = 0 197 while i < cnt { 198 let want: *u8 = nm[i] as *u8 199 o = lg_put(out, o, "--- component " as *u8) 200 o = lg_putd(out, o, i + 1) 201 o = lg_put(out, o, ": " as *u8) 202 o = lg_put(out, o, want) 203 o = lg_put(out, o, "\n model row (verbatim):\n " as *u8) 204 o = lg_row_verbatim(out, o, buf, n, 77, want) 205 let mi: i64 = lg_find_model(ctx, want) 206 if mi >= 0 { 207 let li: i64 = mods[mi * 5 + 2] 208 if li >= 0 { 209 let lid: *u8 = sys_mmap(128) 210 var z: i64 = lg_putn(lid, 0, buf, lic[li * 7 + 0], lic[li * 7 + 1]) 211 lid[z] = 0 as u8 212 o = lg_put(out, o, " licence row (verbatim):\n " as *u8) 213 o = lg_row_verbatim(out, o, buf, n, 76, lid) 214 if lic[li * 7 + 6] == 0 { 215 o = lg_put(out, o, " ** UNVERIFIED: this licence row was transcribed WITHOUT the licence being read.\n" as *u8) 216 o = lg_put(out, o, " Counsel must confirm it against the primary source before any reliance.\n" as *u8) 217 } 218 } 219 } 220 o = lg_put(out, o, "\n" as *u8) 221 i = i + 1 222 } 223 224 o = lg_put(out, o, "MOST RESTRICTIVE POSITION ACROSS THE WHOLE CHAIN\n" as *u8) 225 o = lg_put(out, o, "(a generation inherits the INTERSECTION of every component's terms)\n" as *u8) 226 o = lg_put(out, o, " sell output ................. " as *u8) 227 o = lg_putd(out, o, res[0]) 228 o = lg_put(out, o, "\n redistribute weights ........ " as *u8) 229 o = lg_putd(out, o, res[1]) 230 o = lg_put(out, o, "\n paid service ................ " as *u8) 231 o = lg_putd(out, o, res[2]) 232 o = lg_put(out, o, "\n derivatives must stay open .. " as *u8) 233 o = lg_putd(out, o, res[3]) 234 o = lg_put(out, o, "\n components absent from table " as *u8) 235 o = lg_putd(out, o, res[4]) 236 o = lg_put(out, o, "\n" as *u8) 237 if res[5] >= 0 { 238 o = lg_put(out, o, " MOST RESTRICTIVE COMPONENT ON 'sell output': " as *u8) 239 o = lg_put(out, o, nm[res[5]] as *u8) 240 o = lg_put(out, o, "\n" as *u8) 241 } 242 243 o = lg_put(out, o, "\nQUESTIONS FOR COUNSEL\n" as *u8) 244 o = lg_put(out, o, " 1. Are the reproduced rows a correct statement of each licence as it stands today?\n" as *u8) 245 o = lg_put(out, o, " 2. Any row marked verified=0 was NOT read against the primary source. Confirm or correct.\n" as *u8) 246 o = lg_put(out, o, " 3. Do you agree that output rights and weight rights are separable, and that the output\n" as *u8) 247 o = lg_put(out, o, " right of a generation is the intersection over its whole provenance chain?\n" as *u8) 248 o = lg_put(out, o, " 4. Any term above marked 1 (conditional) turns on a fact a machine cannot settle\n" as *u8) 249 o = lg_put(out, o, " (revenue thresholds, field of use). Please state the condition and who tracks it.\n" as *u8) 250 o = lg_put(out, o, "\nCOUNSEL SIGN-OFF\n Reviewed by: ______________________________ Date: ______________\n" as *u8) 251 o = lg_put(out, o, " Determination (counsel's, not the tool's): ____________________________________\n" as *u8) 252 sys_write(1, out, o) 253 return 0 254 } 255 256 if lg_ceq(verb, "chain" as *u8) == 1 { 257 let cnt: i64 = argc - 2 258 let nm: *i64 = sys_mmap((cnt + 2) * 8) as *i64 259 var i: i64 = 0 260 while i < cnt { nm[i] = argv[i + 2]; i = i + 1 } 261 let res: *i64 = sys_mmap(64) as *i64 262 lg_eval(ctx, nm, cnt, res) 263 264 o = lg_put(out, o, "{\x22v\x22:1,\x22organ\x22:\x22nx_licgate\x22,\x22verb\x22:\x22chain\x22,\x22chain\x22:[" as *u8) 265 i = 0 266 while i < cnt { 267 if i > 0 { o = lg_put(out, o, "," as *u8) } 268 let want: *u8 = nm[i] as *u8 269 let mi: i64 = lg_find_model(ctx, want) 270 o = lg_put(out, o, "{\x22model\x22:\x22" as *u8) 271 o = lg_put(out, o, want) 272 if mi < 0 { 273 o = lg_put(out, o, "\x22,\x22known\x22:0,\x22license\x22:\x22UNKNOWN\x22}" as *u8) 274 } else { 275 let li: i64 = mods[mi * 5 + 2] 276 o = lg_put(out, o, "\x22,\x22known\x22:1,\x22kind\x22:\x22" as *u8) 277 o = lg_putn(out, o, buf, mods[mi * 5 + 3], mods[mi * 5 + 4]) 278 o = lg_put(out, o, "\x22,\x22license\x22:\x22" as *u8) 279 if li >= 0 { 280 o = lg_putn(out, o, buf, lic[li * 7 + 0], lic[li * 7 + 1]) 281 o = lg_put(out, o, "\x22,\x22out_commercial\x22:" as *u8) 282 o = lg_putd(out, o, lic[li * 7 + 2]) 283 o = lg_put(out, o, ",\x22verified\x22:" as *u8) 284 o = lg_putd(out, o, lic[li * 7 + 6]) 285 o = lg_put(out, o, "}" as *u8) 286 } else { 287 o = lg_put(out, o, "UNRESOLVED\x22}" as *u8) 288 } 289 } 290 i = i + 1 291 } 292 o = lg_put(out, o, "],\x22rights\x22:{\x22out_commercial\x22:" as *u8) 293 o = lg_putd(out, o, res[0]) 294 o = lg_put(out, o, ",\x22weights_redist\x22:" as *u8) 295 o = lg_putd(out, o, res[1]) 296 o = lg_put(out, o, ",\x22paid_service\x22:" as *u8) 297 o = lg_putd(out, o, res[2]) 298 o = lg_put(out, o, ",\x22deriv_must_open\x22:" as *u8) 299 o = lg_putd(out, o, res[3]) 300 o = lg_put(out, o, "},\x22binding\x22:\x22" as *u8) 301 if res[5] >= 0 { o = lg_put(out, o, nm[res[5]] as *u8) } else { o = lg_put(out, o, "none" as *u8) } 302 o = lg_put(out, o, "\x22,\x22unknown\x22:" as *u8) 303 o = lg_putd(out, o, res[4]) 304 305 let rc: i64 = lg_rc(res) 306 o = lg_put(out, o, ",\x22verdict\x22:\x22" as *u8) 307 if rc == 4 { 308 if res[4] > 0 { o = lg_put(out, o, "REFUSE\x22,\x22reason\x22:\x22unknown model in chain -- silence is never permission" as *u8) } 309 else { o = lg_put(out, o, "REFUSE\x22,\x22reason\x22:\x22a model in this chain forbids commercialising generated output" as *u8) } 310 } else { 311 if rc == 3 { o = lg_put(out, o, "REVIEW\x22,\x22reason\x22:\x22a conditional term (revenue cap / field of use) a machine may not settle" as *u8) } 312 else { o = lg_put(out, o, "SHIP_OK\x22,\x22reason\x22:\x22every model in the chain grants commercial rights over its output" as *u8) } 313 } 314 o = lg_put(out, o, "\x22,\x22exit\x22:" as *u8) 315 o = lg_putd(out, o, rc) 316 317 // ---- THE ALL-AXIS ANSWER, ADDED 2026-08-25 ---- 318 // The two fields above keep their EXACT prior meaning (rule 19: adding is safe, changing 319 // breaks consumers) -- they answer "may I SELL the output" and nothing else, which is 320 // lg_rc's documented contract. But lg_eval computes FOUR axes and lg_rc reads TWO, so the 321 // other three were printed and reached no exit code at all. 322 // MEASURED on the live binary before this change: `chain illustrious-xl` -> SHIP_OK exit=0 323 // with paid_service=0 (that licence forbids the model powering a paid service) and 324 // deriv_must_open=1 (an undischarged obligation). A caller branching on exit 0 would stand 325 // that service up while every number saying otherwise sat in the same JSON. 326 let rca: i64 = lg_rc_axes(res) 327 o = lg_put(out, o, ",\x22verdict_all_axes\x22:\x22" as *u8) 328 if rca == LG_RC_REFUSE { o = lg_put(out, o, "REFUSE" as *u8) } 329 else { 330 if rca == LG_RC_REVIEW { o = lg_put(out, o, "REVIEW" as *u8) } 331 else { o = lg_put(out, o, "CLEAR" as *u8) } 332 } 333 o = lg_put(out, o, "\x22,\x22binding_axis\x22:\x22" as *u8) 334 o = lg_put(out, o, lg_axis_name(res)) 335 o = lg_put(out, o, "\x22,\x22exit_all_axes\x22:" as *u8) 336 o = lg_putd(out, o, rca) 337 338 // THE PROCESS EXIT IS THE WORST OF THE TWO, AND IT IS PRINTED so no reader has to infer it. 339 // A licence tool that has already computed a denial must not hand back 0 -- that is the 340 // whole defect. This is a STRICT TIGHTENING: worst() can only move an exit away from 0, 341 // never toward it, so nothing that was refused can become permitted. 342 var worst: i64 = rc 343 if rca > worst { worst = rca } 344 o = lg_put(out, o, ",\x22process_exit\x22:" as *u8) 345 o = lg_putd(out, o, worst) 346 o = lg_put(out, o, "}\n" as *u8) 347 sys_write(1, out, o) 348 if worst != 0 { sys_exit(worst) } 349 return 0 350 } 351 352 o = lg_put(out, o, "nx_licgate: unknown verb\n" as *u8) 353 sys_write(1, out, o) 354 sys_exit(2) 355 return 2 356}