code wiki / (root) / nx_edgar_gate.nx

nx_edgar_gate.nx source

↩ module page · 118 lines · 5222 B

1// nx_edgar_gate.nx -- F986 INDEPENDENT GATE: SEC EDGAR extraction on a REAL banked filing. 2// Reads a banked slice of Apple's actual SEC companyconcept JSON (fetched live over the sovereign TLS) 3// and proves the latest fact + its provenance parse correctly, and that a value-less response fails 4// closed with EDGAR_NOVAL (the same sentinel the F-score reads as INCOMPLETE) -- never a fabricated fact. 5// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 6 7import "nx_edgar_lib.nx" 8 9func eg_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 10func eg_putn(v: i64) -> i64 { 11 let t: *u8 = sys_mmap(32) 12 var o: i64 = 0 13 var m: i64 = v 14 if m < 0 { t[o] = 45 as u8; o = o + 1; m = 0 - m } 15 let d: *u8 = sys_mmap(32) 16 var k: i64 = 0 17 if m == 0 { d[0] = 48 as u8; k = 1 } 18 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 19 var i: i64 = 0 20 while i < k { t[o] = d[k - 1 - i]; o = o + 1; i = i + 1 } 21 sys_write(1, t, o) 22 return 0 23} 24func eg_ck(cnt: *i64, name: *u8, got: i64, want: i64) -> i64 { 25 if got == want { 26 cnt[0] = cnt[0] + 1 27 eg_puts(" PASS " as *u8); eg_puts(name); eg_puts(" = " as *u8); eg_putn(got); eg_puts("\n" as *u8) 28 return 1 29 } 30 cnt[1] = cnt[1] + 1 31 eg_puts(" FAIL " as *u8); eg_puts(name); eg_puts(" got " as *u8); eg_putn(got) 32 eg_puts(" want " as *u8); eg_putn(want); eg_puts("\n" as *u8) 33 return 0 34} 35func eg_ckstr(cnt: *i64, name: *u8, got: *u8, want: *u8) -> i64 { 36 if mt_streq(got, want) == 1 { 37 cnt[0] = cnt[0] + 1 38 eg_puts(" PASS " as *u8); eg_puts(name); eg_puts(" = " as *u8); eg_puts(got); eg_puts("\n" as *u8) 39 return 1 40 } 41 cnt[1] = cnt[1] + 1 42 eg_puts(" FAIL " as *u8); eg_puts(name); eg_puts(" got " as *u8); eg_puts(got); eg_puts("\n" as *u8) 43 return 0 44} 45 46func main(argc: i64, argv: *i64) -> i64 { 47 let cnt: *i64 = sys_mmap(16) as *i64 48 cnt[0] = 0 49 cnt[1] = 0 50 51 eg_puts("NISHI-EDGAR-GATE (F986 real SEC data: latest fact + provenance, fail-closed)\n" as *u8) 52 53 let json: *u8 = sys_mmap(1048576) 54 let jl: i64 = edgar_read("knowledge/status/edgar_aapl_equity.json" as *u8, json, 1048576) 55 var loaded: i64 = 0 56 if jl > 0 { loaded = 1 } 57 eg_ck(cnt, "E1 banked real filing loaded" as *u8, loaded, 1) 58 59 // ---- E2: the LATEST StockholdersEquity value = the most recent entry (2026-03-28, $106.491B) ---- 60 eg_ck(cnt, "E2 latest StockholdersEquity = 106491000000 (real, 2026-03-28)" as *u8, 61 edgar_latest_value(json, jl), 106491000000) 62 63 // ---- E3: the entity name from the header ---- 64 let ent: *u8 = sys_mmap(128) 65 edgar_entity(json, jl, ent) 66 eg_ckstr(cnt, "E3 entity = Apple Inc." as *u8, ent, "Apple Inc." as *u8) 67 68 // ---- E4: PROVENANCE -- the latest fact's form and filing date ---- 69 let form: *u8 = sys_mmap(64) 70 edgar_latest_form(json, jl, form) 71 eg_ckstr(cnt, "E4 latest form = 10-Q" as *u8, form, "10-Q" as *u8) 72 let filed: *u8 = sys_mmap(64) 73 edgar_latest_filed(json, jl, filed) 74 eg_ckstr(cnt, "E4a latest filed date = 2026-05-01" as *u8, filed, "2026-05-01" as *u8) 75 76 // ---- E5: an arbitrary concept-name key round-trips (tag) ---- 77 let tag: *u8 = sys_mmap(64) 78 edgar_str_first(json, jl, "tag" as *u8, tag) 79 eg_ckstr(cnt, "E5 tag = StockholdersEquity" as *u8, tag, "StockholdersEquity" as *u8) 80 81 // ---- E6: FAIL-CLOSED -- a key that is absent returns EDGAR_NOVAL (the pipeline reads it as missing) ---- 82 eg_ck(cnt, "E6 absent numeric key -> EDGAR_NOVAL (composes as missing, not zero)" as *u8, 83 edgar_num_last(json, jl, "NoSuchConcept" as *u8), EDGAR_NOVAL) 84 85 // ---- E7: a response with NO USD data at all -> EDGAR_NOVAL, never a fabricated value ---- 86 let empty: *u8 = sys_mmap(256) 87 let emkey: *u8 = sys_mmap(64) 88 let ek: i64 = edgar_mkkey("entityName" as *u8, emkey) 89 // build {"entityName":"Ghost Co"} at runtime (no val) 90 var o: i64 = 0 91 empty[o] = 123 as u8; o = o + 1 // { 92 var e2: i64 = 0 93 while emkey[e2] != (0 as u8) { empty[o] = emkey[e2]; o = o + 1; e2 = e2 + 1 } 94 empty[o] = EDGAR_Q as u8; o = o + 1 95 let gc: *u8 = "Ghost Co" as *u8 96 var e3: i64 = 0 97 while gc[e3] != (0 as u8) { empty[o] = gc[e3]; o = o + 1; e3 = e3 + 1 } 98 empty[o] = EDGAR_Q as u8; o = o + 1 99 empty[o] = 125 as u8; o = o + 1 // } 100 empty[o] = 0 as u8 101 eg_ck(cnt, "E7 value-less response -> EDGAR_NOVAL (no fabricated fact)" as *u8, 102 edgar_latest_value(empty, o), EDGAR_NOVAL) 103 104 // ---- E8: EDGAR_NOVAL == the F-score / XBRL missing sentinel (-999999999) so the pipeline composes ---- 105 eg_ck(cnt, "E8 EDGAR_NOVAL == -999999999 (composes with nx_xbrl / nx_piotroski)" as *u8, 106 EDGAR_NOVAL, 0 - 999999999) 107 108 eg_puts("nx_edgar_gate: pass=" as *u8); eg_putn(cnt[0]) 109 eg_puts(" fail=" as *u8); eg_putn(cnt[1]); eg_puts("\n" as *u8) 110 if cnt[1] == 0 { 111 eg_puts("F986 nx_edgar: VERDICT=GREEN (real SEC fact + provenance; fail-closed to a missing-sentinel the pipeline composes)\n" as *u8) 112 sys_exit(0) 113 return 0 114 } 115 eg_puts("F986 nx_edgar: VERDICT=RED\n" as *u8) 116 sys_exit(1) 117 return 1 118}