code wiki / (root) / nx_forge_cascade.nx

nx_forge_cascade.nx source

↩ module page · 93 lines · 4015 B

1// nx_forge_cascade.nx -- THE CASCADE CONSUMER (dossier M4 consumer + M5 capture, 2026-07-16). 2// The no-paid-API cascade [[feedback-frontier-tier-via-subscription-not-api]]: the LOCAL tier 3// exhausts -> nx_forge_engine writes esc_<organ>.txt -> a SUBSCRIPTION Claude seat reads that 4// bundle, writes a candidate, and calls THIS organ to CLOSE it. The candidate is judged by the 5// SAME sovereign byte-exact lane (fg_run); a training pair is captured ONLY on GREEN, so the 6// frontier seat can never inject an unverified pair -- the compiler is the arbiter, always. 7// close <organ> <expectfile> <candfile> -> build FTASK|organ|expect|none|cand|1, fg_run it; 8// on GREEN append PAIR|organ|cand|us to knowledge/forge/cascade_pairs.tsv (the N7 corpus, 9// compile-verified BY CONSTRUCTION). Exit 0 iff GREEN. 10// This is the mechanism that reaches Fable-tier NishiLang TODAY (local does the easy rungs, the 11// sub seat handles the hard ones), with NO speed unlock and NO paid API -- every output judged. 12// license_tier: ORIGINAL 13import "nx_forge.nx" 14import "nx_sov_ledger.nx" 15const K_MAGIC_2048: i64 = 2048 16 17func fca_run(organ: *u8, expectf: *u8, candf: *u8) -> i64 { 18 // compose the FTASK spec into /tmp/cascade.spec (reuses the gate-proven fg_run judge) 19 let spec: *u8 = sys_mmap(K_MAGIC_2048) as *u8 20 var o: i64 = 0 21 let h: *u8 = "FTASK|" as *u8 22 var i: i64 = 0 23 while h[i] != (0 as u8) { spec[o] = h[i]; o = o + 1; i = i + 1 } 24 i = 0 25 while organ[i] != (0 as u8) { spec[o] = organ[i]; o = o + 1; i = i + 1 } 26 spec[o] = 124 as u8 27 o = o + 1 28 i = 0 29 while expectf[i] != (0 as u8) { spec[o] = expectf[i]; o = o + 1; i = i + 1 } 30 let mid: *u8 = "|none|" as *u8 31 i = 0 32 while mid[i] != (0 as u8) { spec[o] = mid[i]; o = o + 1; i = i + 1 } 33 i = 0 34 while candf[i] != (0 as u8) { spec[o] = candf[i]; o = o + 1; i = i + 1 } 35 let tail: *u8 = "|1\n" as *u8 36 i = 0 37 while tail[i] != (0 as u8) { spec[o] = tail[i]; o = o + 1; i = i + 1 } 38 let sfd: i64 = sys_openat_wr("/tmp/cascade.spec" as *u8, 420) 39 if sfd < 0 { return 0 - 2 } 40 let wr: i64 = fc_wb(sfd, spec, o) 41 sys_close(sfd) 42 if wr != 0 { return 0 - 2 } 43 // judge through the sovereign byte-exact lane 44 let rc: i64 = fg_run("/tmp/cascade.spec" as *u8) 45 std_puts("CASCADE close organ=" as *u8) 46 std_puts(organ) 47 std_puts(" judge-rc=" as *u8) 48 std_pdec(rc) 49 if rc <= 0 { 50 std_putln(" -> NOT-GREEN (no training pair; the judge refused)" as *u8) 51 return rc 52 } 53 // GREEN: capture the compile-verified training pair (M5 / N7 corpus) into the SOVEREIGN store 54 // (nx_sov_ledger / seg_store -- NO flat TSV, per the no-TSV law). Keyed by organ; latest-wins. 55 let val: *u8 = sys_mmap(512) as *u8 56 var vo: i64 = 0 57 var ci: i64 = 0 58 while candf[ci] != (0 as u8) { val[vo] = candf[ci]; vo = vo + 1; ci = ci + 1 } 59 let suf: *u8 = "|maker=claude-sub|verdict=GREEN|us=" as *u8 60 var si: i64 = 0 61 while suf[si] != (0 as u8) { val[vo] = suf[si]; vo = vo + 1; si = si + 1 } 62 let now: i64 = sys_now_us() 63 vo = vo + std_itoa(now, val + vo) 64 val[vo] = 0 as u8 65 sov_put_str("knowledge/store/cascade_pairs" as *u8, organ, val) 66 std_putln(" -> GREEN, training pair captured (sovereign store: knowledge/store/cascade_pairs)" as *u8) 67 return rc 68} 69 70func main(argc: i64, argv: *i64) -> i64 { 71 if argc < 5 { 72 std_putln("usage: nx_forge_cascade close <organ> <expectfile> <candfile>" as *u8) 73 sys_exit(2) 74 return 2 75 } 76 let a1: i64 = argv[1] 77 let verb: *u8 = a1 as *u8 78 if std_streq(verb, "close" as *u8) == 0 { 79 std_putln("unknown verb (only: close)" as *u8) 80 sys_exit(2) 81 return 2 82 } 83 let a2: i64 = argv[2] 84 let organ: *u8 = a2 as *u8 85 let a3: i64 = argv[3] 86 let expectf: *u8 = a3 as *u8 87 let a4: i64 = argv[4] 88 let candf: *u8 = a4 as *u8 89 let rc: i64 = fca_run(organ, expectf, candf) 90 if rc > 0 { sys_exit(0) } 91 sys_exit(1) 92 return 1 93}