code wiki / _hdl_build / nx_oeuvre_graph.nx

nx_oeuvre_graph.nx source

↩ module page · 230 lines · 13153 B

1// nx_oeuvre_graph.nx -- SREACH-OEUVRE O1: the DV2.0 MANY-TO-MANY information graph 2// foundation, authored into the SOVEREIGN STORE (knowledge/store/oeuvre-) via nx_seg_store. 3// This is the read-side schema of the "an agent CREATES a product in a PLACE / a person 4// VIEWS|BUYS a product in a PLACE" model (operator, 2026-06-13): no privileged root -- 5// ANY node (agent person/org, work, franchise, character, medium, place) is a first-class 6// search anchor, and every relationship is many-to-many (the whole point: search "zatoichi" 7// -> its MANY feature films, like Google's knowledge panel but sovereign + ground-up). 8// 9// HONEST SCOPE (rule 5, no-overclaim): O1 proves the SCHEMA + the M:N TRAVERSAL MECHANISM on 10// a SEEDED FIXTURE (every hub source-anchor = "seed:fixture"). The LIVE enumeration of a real 11// producer's true body-of-work from wikidata/wikipedia/Commons is authored-by-organ in O2 12// (resolver) + O3 (enumerator) -- NOT claimed here. This gate is the floor everything founds on. 13// 14// IDEMPOTENT (rule 10): a record is written only if absent-or-changed; then EVERY record is 15// read back and the M:N traversals are recomputed FROM THE STORE -> verdict GREEN only when the 16// store actually holds + traverses what we intended. Negative control (a bogus link, and the 17// screwdriver NOT in a film series) MUST come back absent, so the gate cannot false-green. 18// Evidence -> knowledge/status/oeuvre_graph.log. license_tier: ORIGINAL 19// 20// module: nishi-core.search.oeuvre.graph 21// depends: nx_seg_store.nx, nx_syscalls.nx 22// capability: OEUVRE_GRAPH_SCHEMA 23import "nx_seg_store.nx" 24import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc) 25import "nx_syscalls.nx" 26 27const OG_PREFIX: *u8 = "knowledge/store/oeuvre-" 28const OG_LOG: *u8 = "knowledge/status/oeuvre_graph.log" 29 30func og_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 31 32func og_w(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 } 33 34// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer 35// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the 36// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls). 37// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign. 38func og_wn(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 } 39 40// 1 if the store's current value for `key` byte-equals `val` (NUL-terminated). Used for the 41// idempotent skip-if-unchanged write AND the post-commit round-trip verification. 42func og_streq(key: *u8, val: *u8) -> i64 { 43 let pq: *i64 = sys_mmap(16) as *i64 44 let lq: *i64 = sys_mmap(16) as *i64 45 if ss_get(OG_PREFIX, key, pq, lq) != 1 { return 0 } 46 let b: *u8 = pq[0] as *u8 47 let n: i64 = lq[0] 48 let vl: i64 = og_len(val) 49 if n != vl { return 0 } 50 var i: i64 = 0 51 while i < n { if b[i] != val[i] { return 0 } i = i + 1 } 52 return 1 53} 54 55// tab-separated field count of key's stored value (the size of the "many" side of an M:N edge); 56// -1 if the key is absent. This is how we PROVE many-to-many: a forward or reverse adjacency 57// list whose field count is >= 2 means the node fans out to multiple neighbors, read live. 58func og_fields(key: *u8) -> i64 { 59 let pq: *i64 = sys_mmap(16) as *i64 60 let lq: *i64 = sys_mmap(16) as *i64 61 if ss_get(OG_PREFIX, key, pq, lq) != 1 { return 0 - 1 } 62 let b: *u8 = pq[0] as *u8 63 let n: i64 = lq[0] 64 if n <= 0 { return 0 } 65 var fields: i64 = 1 66 var i: i64 = 0 67 while i < n { if b[i] == (9 as u8) { fields = fields + 1 } i = i + 1 } 68 return fields 69} 70 71// 1 if key's stored value contains NUL-terminated needle (locator-mode probe: ":view"/":buy"), 72// else 0 (also 0 if the key is absent). 73func og_has(key: *u8, needle: *u8) -> i64 { 74 let pq: *i64 = sys_mmap(16) as *i64 75 let lq: *i64 = sys_mmap(16) as *i64 76 if ss_get(OG_PREFIX, key, pq, lq) != 1 { return 0 } 77 let b: *u8 = pq[0] as *u8 78 let n: i64 = lq[0] 79 let m: i64 = og_len(needle) 80 if m == 0 { return 1 } 81 var i: i64 = 0 82 while i + m <= n { 83 var j: i64 = 0 84 var ok: i64 = 1 85 while j < m { if b[i + j] != needle[j] { ok = 0; j = m } else { j = j + 1 } } 86 if ok == 1 { return 1 } 87 i = i + 1 88 } 89 return 0 90} 91 92// 1 if key is absent/tombstoned (ss_get != 1) -- the negative-control discriminator. 93func og_absent(key: *u8) -> i64 { 94 let pq: *i64 = sys_mmap(16) as *i64 95 let lq: *i64 = sys_mmap(16) as *i64 96 if ss_get(OG_PREFIX, key, pq, lq) != 1 { return 1 } 97 return 0 98} 99 100func og_seg_next() -> i64 { 101 let segs: *i64 = sys_mmap(8 * 260) as *i64 102 let nseg: i64 = ss_manifest(OG_PREFIX, segs) 103 if nseg < 0 { return 1 } 104 return 1 + nseg 105} 106 107func og_emit(fd: i64, nrec: i64, written: i64, verified: i64, mns: i64, mnwa: i64, mnaw: i64, neg: i64, ok: i64) -> i64 { 108 og_w(fd, "OEUVRE-GRAPH authored=organ store=knowledge/store/oeuvre- records=" as *u8); og_wn(fd, nrec) 109 og_w(fd, " written=" as *u8); og_wn(fd, written) 110 og_w(fd, " verified=" as *u8); og_wn(fd, verified) 111 og_w(fd, " mn_series=" as *u8); og_wn(fd, mns) 112 og_w(fd, " mn_work_agents=" as *u8); og_wn(fd, mnwa) 113 og_w(fd, " mn_agent_works=" as *u8); og_wn(fd, mnaw) 114 og_w(fd, " span=film-view+photo-view+good-buy neg=" as *u8); og_wn(fd, neg) 115 og_w(fd, " scope=schema-fixture(live-enum=O2/O3)" as *u8) 116 if ok == 1 { og_w(fd, " verdict=GREEN\n" as *u8) } else { og_w(fd, " verdict=RED\n" as *u8) } 117 return 0 118} 119 120func main() -> i64 { 121 let keys: *i64 = sys_mmap(8 * 64) as *i64 122 let vals: *i64 = sys_mmap(8 * 64) as *i64 123 var n: i64 = 0 124 125 // ---- HUBS: key "hub:<type>:<bk>" -> "type|display|source-anchor" ---- 126 keys[n] = "hub:agent:diora_baird" as *u8 as i64; vals[n] = "agent|Diora Baird|wikidata:Q283504" as *u8 as i64; n = n + 1 127 keys[n] = "hub:agent:daiei" as *u8 as i64; vals[n] = "agent|Daiei Film studio|seed:fixture" as *u8 as i64; n = n + 1 128 keys[n] = "hub:agent:shintaro_katsu" as *u8 as i64; vals[n] = "agent|Shintaro Katsu|seed:fixture" as *u8 as i64; n = n + 1 129 keys[n] = "hub:agent:wera" as *u8 as i64; vals[n] = "agent|Wera Tools manufacturer|seed:fixture" as *u8 as i64; n = n + 1 130 keys[n] = "hub:agent:hokusai" as *u8 as i64; vals[n] = "agent|Katsushika Hokusai|seed:fixture" as *u8 as i64; n = n + 1 131 keys[n] = "hub:franchise:zatoichi" as *u8 as i64; vals[n] = "franchise|Zatoichi|seed:fixture" as *u8 as i64; n = n + 1 132 keys[n] = "hub:character:ichi" as *u8 as i64; vals[n] = "character|Ichi the blind swordsman|seed:fixture" as *u8 as i64; n = n + 1 133 keys[n] = "hub:medium:ukiyo_e" as *u8 as i64; vals[n] = "medium|Ukiyo-e woodblock prints|seed:fixture" as *u8 as i64; n = n + 1 134 keys[n] = "hub:work:zatoichi_1962" as *u8 as i64; vals[n] = "work|film|Tale of Zatoichi 1962|seed:fixture" as *u8 as i64; n = n + 1 135 keys[n] = "hub:work:zatoichi_1989" as *u8 as i64; vals[n] = "work|film|Zatoichi Darkness Is His Ally 1989|seed:fixture" as *u8 as i64; n = n + 1 136 keys[n] = "hub:work:diora_baird_shoot" as *u8 as i64; vals[n] = "work|photo|Diora Baird photo shoot|seed:fixture" as *u8 as i64; n = n + 1 137 keys[n] = "hub:work:wera_screwdriver" as *u8 as i64; vals[n] = "work|good|Wera Kraftform screwdriver|seed:fixture" as *u8 as i64; n = n + 1 138 keys[n] = "hub:work:hokusai_great_wave" as *u8 as i64; vals[n] = "work|print|The Great Wave off Kanagawa|seed:fixture" as *u8 as i64; n = n + 1 139 keys[n] = "hub:place:vk_com" as *u8 as i64; vals[n] = "place|vk.com|view-host" as *u8 as i64; n = n + 1 140 keys[n] = "hub:place:archive_org" as *u8 as i64; vals[n] = "place|archive.org|view-host" as *u8 as i64; n = n + 1 141 keys[n] = "hub:place:wera_store" as *u8 as i64; vals[n] = "place|wera.de store|buy-host" as *u8 as i64; n = n + 1 142 keys[n] = "hub:place:amazon" as *u8 as i64; vals[n] = "place|amazon|buy-host" as *u8 as i64; n = n + 1 143 144 // ---- LINKS (many-to-many adjacency, tab-separated bk lists; available_at = bk:mode) ---- 145 keys[n] = "link:creates:daiei" as *u8 as i64; vals[n] = "zatoichi_1962" as *u8 as i64; n = n + 1 146 keys[n] = "link:creates:shintaro_katsu" as *u8 as i64; vals[n] = "zatoichi_1962\tzatoichi_1989" as *u8 as i64; n = n + 1 147 keys[n] = "link:creates:diora_baird" as *u8 as i64; vals[n] = "diora_baird_shoot" as *u8 as i64; n = n + 1 148 keys[n] = "link:creates:wera" as *u8 as i64; vals[n] = "wera_screwdriver" as *u8 as i64; n = n + 1 149 keys[n] = "link:creates:hokusai" as *u8 as i64; vals[n] = "hokusai_great_wave" as *u8 as i64; n = n + 1 150 keys[n] = "link:created_by:zatoichi_1962" as *u8 as i64; vals[n] = "daiei\tshintaro_katsu" as *u8 as i64; n = n + 1 151 keys[n] = "link:created_by:zatoichi_1989" as *u8 as i64; vals[n] = "shintaro_katsu" as *u8 as i64; n = n + 1 152 keys[n] = "link:part_of_series:zatoichi_1962" as *u8 as i64; vals[n] = "zatoichi" as *u8 as i64; n = n + 1 153 keys[n] = "link:part_of_series:zatoichi_1989" as *u8 as i64; vals[n] = "zatoichi" as *u8 as i64; n = n + 1 154 keys[n] = "link:series_works:zatoichi" as *u8 as i64; vals[n] = "zatoichi_1962\tzatoichi_1989" as *u8 as i64; n = n + 1 155 keys[n] = "link:features:zatoichi_1962" as *u8 as i64; vals[n] = "ichi" as *u8 as i64; n = n + 1 156 keys[n] = "link:in_medium:hokusai_great_wave" as *u8 as i64; vals[n] = "ukiyo_e" as *u8 as i64; n = n + 1 157 keys[n] = "link:medium_works:ukiyo_e" as *u8 as i64; vals[n] = "hokusai_great_wave" as *u8 as i64; n = n + 1 158 keys[n] = "link:available_at:zatoichi_1962" as *u8 as i64; vals[n] = "vk_com:view\tarchive_org:view" as *u8 as i64; n = n + 1 159 keys[n] = "link:available_at:diora_baird_shoot" as *u8 as i64; vals[n] = "vk_com:view" as *u8 as i64; n = n + 1 160 keys[n] = "link:available_at:wera_screwdriver" as *u8 as i64; vals[n] = "wera_store:buy\tamazon:buy" as *u8 as i64; n = n + 1 161 keys[n] = "link:available_at:hokusai_great_wave" as *u8 as i64; vals[n] = "archive_org:view" as *u8 as i64; n = n + 1 162 163 let nrec: i64 = n 164 165 og_w(1, "=== SREACH-OEUVRE O1: many-to-many graph schema foundation (sovereign store) ===\n" as *u8) 166 167 // idempotent write: only records absent-or-changed (additive versions otherwise). 168 let w: *i64 = ss_begin() 169 var towrite: i64 = 0 170 var i: i64 = 0 171 while i < nrec { 172 let key: *u8 = keys[i] as *u8 173 let val: *u8 = vals[i] as *u8 174 if og_streq(key, val) == 0 { ss_add(w, 1, key, val, og_len(val)); towrite = towrite + 1 } 175 i = i + 1 176 } 177 var committed: i64 = 0 178 if towrite > 0 { 179 let segid: i64 = og_seg_next() 180 let rc: i64 = ss_commit(OG_PREFIX, w, segid) 181 if rc == 0 { committed = 1 } 182 } 183 184 // round-trip: every record reads back byte-exact FROM the store. 185 var verified: i64 = 0 186 i = 0 187 while i < nrec { if og_streq(keys[i] as *u8, vals[i] as *u8) == 1 { verified = verified + 1 } i = i + 1 } 188 189 // many-to-many traversals, recomputed live from the store (not from the seed arrays): 190 let mn_series: i64 = og_fields("link:series_works:zatoichi" as *u8) // search a FRANCHISE -> many films 191 let mn_work_agents: i64 = og_fields("link:created_by:zatoichi_1962" as *u8) // one WORK <- many agents (cast+studio) 192 let mn_agent_works: i64 = og_fields("link:creates:shintaro_katsu" as *u8) // one AGENT -> many works 193 194 // polymorphic availability across the full product span (operator: beauty -> screwdriver -> film): 195 let span_film_view: i64 = og_has("link:available_at:zatoichi_1962" as *u8, ":view" as *u8) 196 let span_photo_view: i64 = og_has("link:available_at:diora_baird_shoot" as *u8, ":view" as *u8) 197 let span_good_buy: i64 = og_has("link:available_at:wera_screwdriver" as *u8, ":buy" as *u8) 198 199 // negative control -- these MUST be absent or the traversal is faking edges: 200 let neg_bogus: i64 = og_absent("link:series_works:__bogus__" as *u8) 201 let neg_screwdriver_series: i64 = og_absent("link:part_of_series:wera_screwdriver" as *u8) 202 let neg: i64 = neg_bogus + neg_screwdriver_series 203 204 var ok: i64 = 1 205 if verified != nrec { ok = 0 } 206 if towrite > 0 { if committed == 0 { ok = 0 } } 207 if mn_series < 2 { ok = 0 } 208 if mn_work_agents < 2 { ok = 0 } 209 if mn_agent_works < 2 { ok = 0 } 210 if span_film_view != 1 { ok = 0 } 211 if span_photo_view != 1 { ok = 0 } 212 if span_good_buy != 1 { ok = 0 } 213 if neg != 2 { ok = 0 } 214 if og_absent("hub:work:zatoichi_1962" as *u8) != 0 { ok = 0 } 215 if og_absent("hub:work:diora_baird_shoot" as *u8) != 0 { ok = 0 } 216 if og_absent("hub:work:wera_screwdriver" as *u8) != 0 { ok = 0 } 217 218 og_emit(1, nrec, towrite, verified, mn_series, mn_work_agents, mn_agent_works, neg, ok) 219 let lf: i64 = sys_openat_append(OG_LOG, 420) 220 if lf >= 0 { og_emit(lf, nrec, towrite, verified, mn_series, mn_work_agents, mn_agent_works, neg, ok); sys_close(lf) } 221 222 if ok == 1 { 223 og_w(1, " OEUVRE-GRAPH O1: PASS\n" as *u8) 224 sys_exit(0) 225 return 0 226 } 227 og_w(1, " OEUVRE-GRAPH O1: FAIL\n" as *u8) 228 sys_exit(1) 229 return 1 230}