code wiki / _hdl_build / nx_ciq_field_imagegen.nx
nx_ciq_field_imagegen.nx source
↩ module page · 120 lines · 7305 B
1// nx_ciq_field_imagegen.nx -- CIQ field INGEST for the IMAGE-GENERATION market (breadth: proves the engine
2// generalizes "against all the market"). Writes the entity x capability matrix into the SOVEREIGN seg_store
3// (market namespace "imagegen") + read-appends "imagegen" to the markets registry. NO TSV. Cells are HONEST:
4// Nishi's image-gen is a REAL product (local ggml fork = elder_sdcpp, beauty.db 548k quality evals, rights
5// spine) -- strong on LOCAL / no-surveillance / quality-eval / censorship-free, but HONESTLY level-1 (not the
6// quality king) on raw photoreal vs Midjourney/Flux, and only partial sovereignty (a ggml fork, not a
7// from-scratch sovereign stack like the .nx organs). Incumbent levels = publicly-established facts
8// (ev="public"); Nishi level-2 cells cite the real product organ; unknown -> U. The engine will place Nishi
9// DIFFERENTLY here than in Connect -- the honest point of breadth (Nishi is not always #1). license_tier: ORIGINAL expect_exit: 0
10import "nx_syscalls.nx"
11import "nx_canon_cid.nx"
12import "nx_seg_store.nx"
13import "nx_uxf_decode.nx"
14const FI_MAGIC_2048: i64 = 2048
15const FI_MAGIC_8192: i64 = 8192
16const FI_MAGIC_1024: i64 = 1024
17
18const FI_STORE: *u8 = "knowledge/store/ciq-"
19
20func fw(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 }
21func fi_streq(a: *u8, b: *u8) -> i64 { var i: i64=0; while a[i]!=(0 as u8){ if a[i]!=b[i]{return 0} i=i+1 } if b[i]!=(0 as u8){return 0} return 1 }
22func fi_copy(src: *u8, dst: *u8) -> i64 { var i: i64=0; while src[i]!=(0 as u8){ dst[i]=src[i]; i=i+1 } dst[i]=0 as u8; return i }
23func fi_contains(hay: *u8, needle: *u8) -> i64 { var i: i64=0; while hay[i]!=(0 as u8){ var j: i64=0; var ok: i64=1; while needle[j]!=(0 as u8){ if hay[i+j]!=needle[j]{ ok=0; j=0; while needle[j]!=(0 as u8){j=j+1} } else { j=j+1 } } if ok==1 { return 1 } i=i+1 } return 0 }
24
25func fi_row(w: *i64, caps: *u8, coff: *i64, nm: *u8, axs: *u8, wts: *u8, cells: *u8) -> i64 {
26 let rk: *i64 = sys_mmap(8 * 8) as *i64
27 let rv: *i64 = sys_mmap(8 * 8) as *i64
28 rk[0] = "ax" as *u8 as i64; rv[0] = axs as i64
29 rk[1] = "wt" as *u8 as i64; rv[1] = wts as i64
30 rk[2] = "cells" as *u8 as i64; rv[2] = cells as i64
31 let recb: *u8 = sys_mmap(FI_MAGIC_2048)
32 let recl: i64 = canon_encode(rk, rv, 3, recb)
33 let kb: *u8 = sys_mmap(128)
34 var ko: i64 = 0
35 ko = ss_cat(kb, ko, "ciq:imagegen:cap:" as *u8)
36 ko = ss_cat(kb, ko, nm)
37 kb[ko] = 0 as u8
38 ss_add(w, 1, kb, recb, recl)
39 var o: i64 = coff[0]
40 o = ss_cat(caps, o, nm)
41 caps[o] = 44 as u8
42 coff[0] = o + 1
43 return 0
44}
45
46func main() -> i64 {
47 let w: *i64 = ss_begin()
48 let caps: *u8 = sys_mmap(FI_MAGIC_8192)
49 let coff: *i64 = sys_mmap(8) as *i64
50 coff[0] = 0
51
52 // name ax wt nishi;stablediffusion;midjourney;dalle3;flux
53 fi_row(w, caps, coff, "photoreal-image-quality" as *u8, "E" as *u8, "3" as *u8, "1;1;2!public;2!public;2!public" as *u8)
54 fi_row(w, caps, coff, "prompt-adherence" as *u8, "E" as *u8, "3" as *u8, "1;1;1;2!public;2!public" as *u8)
55 fi_row(w, caps, coff, "resolution-detail" as *u8, "E" as *u8, "2" as *u8, "1;2!public;2!public;1;2!public" as *u8)
56 fi_row(w, caps, coff, "generation-speed" as *u8, "E" as *u8, "2" as *u8, "1;2!public;1;1;2!public" as *u8)
57 fi_row(w, caps, coff, "inpaint-outpaint-control" as *u8, "E" as *u8, "2" as *u8, "1;2!public;1;1;1" as *u8)
58 fi_row(w, caps, coff, "identity-consistency" as *u8, "E" as *u8, "2" as *u8, "1;1;1;U;U" as *u8)
59 fi_row(w, caps, coff, "local-on-device-run" as *u8, "E" as *u8, "3" as *u8, "2!elder_sdcpp;2!public;0;0;2!public" as *u8)
60 fi_row(w, caps, coff, "batch-throughput-ops" as *u8, "E" as *u8, "2" as *u8, "1;2!public;1;1;1" as *u8)
61
62 fi_row(w, caps, coff, "open-weights-sovereignty" as *u8, "V" as *u8, "3" as *u8, "1;2!public;0;0;1" as *u8)
63 fi_row(w, caps, coff, "provenance-content-credentials" as *u8, "V" as *u8, "2" as *u8, "1;0;0;1;0" as *u8)
64 fi_row(w, caps, coff, "consent-rights-clean-training" as *u8, "V" as *u8, "3" as *u8, "1;0;0;1;0" as *u8)
65 fi_row(w, caps, coff, "no-content-surveillance" as *u8, "V" as *u8, "2" as *u8, "2!elder_sdcpp;2!public;0;0;1" as *u8)
66 fi_row(w, caps, coff, "censorship-free-local-control" as *u8, "V" as *u8, "2" as *u8, "2!elder_sdcpp;2!public;0;0;1" as *u8)
67 fi_row(w, caps, coff, "quality-eval-feedback-loop" as *u8, "V" as *u8, "2" as *u8, "2!beautydb;U;U;U;U" as *u8)
68 fi_row(w, caps, coff, "fine-tune-customization" as *u8, "V" as *u8, "2" as *u8, "1;2!public;0;0;1" as *u8)
69
70 caps[coff[0]] = 0 as u8
71
72 let mk: *i64 = sys_mmap(8 * 4) as *i64
73 let mv: *i64 = sys_mmap(8 * 4) as *i64
74 mk[0] = "entities" as *u8 as i64; mv[0] = "nishi,stablediffusion,midjourney,dalle3,flux" as *u8 as i64
75 mk[1] = "caps" as *u8 as i64; mv[1] = caps as i64
76 let mb: *u8 = sys_mmap(FI_MAGIC_8192)
77 let ml: i64 = canon_encode(mk, mv, 2, mb)
78 ss_add(w, 1, "ciq:imagegen:meta" as *u8, mb, ml)
79
80 // read-append "imagegen" into the markets registry (idempotent; preserves "connect")
81 let gp: *i64 = sys_mmap(8) as *i64
82 let gl: *i64 = sys_mmap(8) as *i64
83 let dk: *i64 = sys_mmap(8 * 16) as *i64
84 let dv: *i64 = sys_mmap(8 * 16) as *i64
85 let cur: *u8 = sys_mmap(FI_MAGIC_1024); cur[0] = 0 as u8
86 if ss_get(FI_STORE, "ciq:markets" as *u8, gp, gl) == 1 {
87 let mnf: i64 = canon_decode(gp[0] as *u8, gl[0], dk, dv, 16)
88 var f: i64 = 0
89 while f < mnf { if fi_streq(dk[f] as *u8, "list" as *u8) == 1 { fi_copy(dv[f] as *u8, cur) } f = f + 1 }
90 }
91 if fi_contains(cur, "imagegen" as *u8) == 0 {
92 var ce: i64 = 0; while cur[ce] != (0 as u8) { ce = ce + 1 }
93 if ce > 0 { cur[ce] = 44 as u8; ce = ce + 1 } // ','
94 var k: i64 = 0; let ig: *u8 = "imagegen" as *u8
95 while ig[k] != (0 as u8) { cur[ce] = ig[k]; ce = ce + 1; k = k + 1 }
96 cur[ce] = 0 as u8
97 }
98 let gk: *i64 = sys_mmap(8 * 2) as *i64
99 let gv: *i64 = sys_mmap(8 * 2) as *i64
100 gk[0] = "list" as *u8 as i64; gv[0] = cur as i64
101 let gb: *u8 = sys_mmap(FI_MAGIC_1024)
102 let gl2: i64 = canon_encode(gk, gv, 1, gb)
103 ss_add(w, 1, "ciq:markets" as *u8, gb, gl2)
104
105 ss_commit(FI_STORE, w, sys_now_ms())
106
107 // self-test: round-trip a cap + the markets list now includes imagegen
108 var st: i64 = 1
109 if ss_get(FI_STORE, "ciq:imagegen:cap:local-on-device-run" as *u8, gp, gl) != 1 { st = 0 }
110 if ss_get(FI_STORE, "ciq:markets" as *u8, gp, gl) == 1 {
111 let mnf: i64 = canon_decode(gp[0] as *u8, gl[0], dk, dv, 16)
112 var f: i64 = 0; var seen: i64 = 0
113 while f < mnf { if fi_streq(dk[f] as *u8, "list" as *u8) == 1 { if fi_contains(dv[f] as *u8, "imagegen" as *u8) == 1 { if fi_contains(dv[f] as *u8, "connect" as *u8) == 1 { seen = 1 } } } f = f + 1 }
114 if seen == 0 { st = 0 }
115 } else { st = 0 }
116
117 fw(1, "CIQ-FIELD-IMAGEGEN stored=15 caps (sovereign seg_store) + markets read-append " as *u8)
118 if st == 1 { fw(1, "selftest=OK verdict=GREEN\n" as *u8); sys_exit(0); return 0 }
119 fw(1, "selftest=FAIL verdict=RED\n" as *u8); sys_exit(1); return 1
120}