nx_supply_research_fetch.nx source
↩ module page · 121 lines · 10464 B
1// nx_supply_research_fetch.nx -- the Nishi RESEARCHER expanded into SUPPLY-CHAIN / COST-INTELLIGENCE (operator:
2// "upgrade the nishi researcher ... understand the transformation from raw material to what we buy and where the
3// costs are coming from -- government laws and regulations to middle men to corruption to the actual material cost
4// to organized crime or just crime to real estate"). Grows the SOVEREIGN corpus (the partnership research leg is
5// rate-limited; the sovereign Wikipedia-orientation fetch WORKS) across the operator's named cost sources: supply
6// chain & logistics, trade/tariffs/tax (govt regulation), middlemen & margins, raw-material commodities, friction
7// (crime/corruption/real estate), and cost economics. Mirrors nx_battery_research_fetch: own TLS-1.3
8// (nx_https_fetch_follow) + Mozilla CA, idempotent have-skip -> knowledge/fetched/supply_*.raw. Grounds the
9// nx_cost_decompose memex. 100% sovereign (no curl/gcc). COVERAGE: 44 sources. expect_exit: 0 license_tier: ORIGINAL
10import "nx_syscalls.nx"
11import "nx_x509_trust_store.nx"
12import "nx_trust_store_load_from_certdata.nx"
13import "nx_https_fetch_follow.nx"
14const K_MAGIC_4194304: i64 = 4194304
15const K_MAGIC_8388608: i64 = 8388608
16
17func ff_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
18func ff_putn(v: i64) -> i64 {
19 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 }
20 var m: i64 = v
21 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
22 let d: *u8 = sys_mmap(24); var k: i64 = 0
23 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
24 // REPAIRED 2026-07-31 (debt 1785516650): this line was a run of 119 0x0E (Shift-Out) control
25 // bytes -- the digit-emit loop had been OVERWRITTEN, not omitted. nx_fs read rendered it as an
26 // innocent blank line, so every status= and bytes= this organ printed came out EMPTY.
27 var j: i64 = k - 1
28 while j >= 0 { sys_write(1, ((d as i64)+j) as *u8, 1); j = j - 1 }
29 return 0
30}
31func have_file(path: *u8) -> i64 {
32 let fd: i64 = sys_openat_rd(path)
33 if fd < 0 { return 0 }
34 sys_close(fd)
35 return 1
36}
37func fetch_save(url: *u8, opath: *u8, store: *TrustStore, out: *u8, cap: i64) -> i64 {
38 if have_file(opath) == 1 { ff_puts(opath); ff_puts(" [have-skip]\n" as *u8); return 1 }
39 let status: *i64 = sys_mmap(8) as *i64
40 let n: i64 = nx_https_fetch_follow(url, store, out, cap, 6, status)
41 ff_puts(url); ff_puts(" status=" as *u8); ff_putn(status[0]); ff_puts(" bytes=" as *u8); ff_putn(n)
42 if n <= 0 { ff_puts(" FETCH-FAIL\n" as *u8); return 0 }
43 var gz: i64 = 0
44 if n >= 2 { if out[0] == 0x1f as u8 { if out[1] == 0x8b as u8 { gz = 1 } } }
45 if gz == 1 { ff_puts(" [GZIP-skip]\n" as *u8); return 0 }
46 let fd: i64 = sys_openat_wr(opath, 0x1a4)
47 if fd < 0 { ff_puts(" SAVE-FAIL\n" as *u8); return 0 }
48 sys_write(fd, out, n)
49 sys_close(fd)
50 ff_puts(" SAVED\n" as *u8)
51 return 1
52}
53
54func main() -> i64 {
55 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304)
56 if r <= 0 { ff_puts("SUPPLY: certdata load failed\n" as *u8); return 1 }
57 let store: *TrustStore = r as *TrustStore
58 ff_puts("CA roots=" as *u8); ff_putn(trust_store_count(store)); ff_puts("\n" as *u8)
59 let cap: i64 = K_MAGIC_8388608
60 let out: *u8 = sys_mmap(cap)
61 var ok: i64 = 0
62
63 ff_puts("== A. SUPPLY CHAIN & LOGISTICS ==\n" as *u8)
64 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Supply_chain" as *u8, "knowledge/fetched/supply_a1_supply_chain.raw" as *u8, store, out, cap)
65 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Supply_chain_management" as *u8, "knowledge/fetched/supply_a2_scm.raw" as *u8, store, out, cap)
66 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Global_value_chain" as *u8, "knowledge/fetched/supply_a3_gvc.raw" as *u8, store, out, cap)
67 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Logistics" as *u8, "knowledge/fetched/supply_a4_logistics.raw" as *u8, store, out, cap)
68 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Containerization" as *u8, "knowledge/fetched/supply_a5_containerization.raw" as *u8, store, out, cap)
69 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Incoterms" as *u8, "knowledge/fetched/supply_a6_incoterms.raw" as *u8, store, out, cap)
70 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Freight_transport" as *u8, "knowledge/fetched/supply_a7_freight.raw" as *u8, store, out, cap)
71 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Container_ship" as *u8, "knowledge/fetched/supply_a8_container_ship.raw" as *u8, store, out, cap)
72 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Port" as *u8, "knowledge/fetched/supply_a9_port.raw" as *u8, store, out, cap)
73
74 ff_puts("== B. TRADE, TARIFFS & TAX (government laws/regulation) ==\n" as *u8)
75 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Tariff" as *u8, "knowledge/fetched/supply_b1_tariff.raw" as *u8, store, out, cap)
76 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Section_301_of_the_Trade_Act_of_1974" as *u8, "knowledge/fetched/supply_b2_section301.raw" as *u8, store, out, cap)
77 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Trade_war" as *u8, "knowledge/fetched/supply_b3_trade_war.raw" as *u8, store, out, cap)
78 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Customs" as *u8, "knowledge/fetched/supply_b4_customs.raw" as *u8, store, out, cap)
79 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Dumping_(pricing_policy)" as *u8, "knowledge/fetched/supply_b5_dumping.raw" as *u8, store, out, cap)
80 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Regulation" as *u8, "knowledge/fetched/supply_b6_regulation.raw" as *u8, store, out, cap)
81 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Value-added_tax" as *u8, "knowledge/fetched/supply_b7_vat.raw" as *u8, store, out, cap)
82 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Sales_tax" as *u8, "knowledge/fetched/supply_b8_sales_tax.raw" as *u8, store, out, cap)
83 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Corporate_tax" as *u8, "knowledge/fetched/supply_b9_corporate_tax.raw" as *u8, store, out, cap)
84
85 ff_puts("== C. MIDDLEMEN & MARGINS ==\n" as *u8)
86 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Intermediary" as *u8, "knowledge/fetched/supply_c1_intermediary.raw" as *u8, store, out, cap)
87 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Wholesaling" as *u8, "knowledge/fetched/supply_c2_wholesaling.raw" as *u8, store, out, cap)
88 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Retail" as *u8, "knowledge/fetched/supply_c3_retail.raw" as *u8, store, out, cap)
89 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Profit_margin" as *u8, "knowledge/fetched/supply_c4_profit_margin.raw" as *u8, store, out, cap)
90 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Markup_(business)" as *u8, "knowledge/fetched/supply_c5_markup.raw" as *u8, store, out, cap)
91 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Price" as *u8, "knowledge/fetched/supply_c6_price.raw" as *u8, store, out, cap)
92
93 ff_puts("== D. RAW MATERIALS / COMMODITIES ==\n" as *u8)
94 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Lithium" as *u8, "knowledge/fetched/supply_d1_lithium.raw" as *u8, store, out, cap)
95 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Cobalt" as *u8, "knowledge/fetched/supply_d2_cobalt.raw" as *u8, store, out, cap)
96 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Nickel" as *u8, "knowledge/fetched/supply_d3_nickel.raw" as *u8, store, out, cap)
97 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Graphite" as *u8, "knowledge/fetched/supply_d4_graphite.raw" as *u8, store, out, cap)
98 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Commodity_market" as *u8, "knowledge/fetched/supply_d5_commodity_market.raw" as *u8, store, out, cap)
99 ok = ok + fetch_save("https://en.wikipedia.org/wiki/London_Metal_Exchange" as *u8, "knowledge/fetched/supply_d6_lme.raw" as *u8, store, out, cap)
100 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Mining" as *u8, "knowledge/fetched/supply_d7_mining.raw" as *u8, store, out, cap)
101 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Rare_earth_element" as *u8, "knowledge/fetched/supply_d8_rare_earth.raw" as *u8, store, out, cap)
102
103 ff_puts("== E. FRICTION: CRIME, CORRUPTION, REAL ESTATE ==\n" as *u8)
104 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Corruption" as *u8, "knowledge/fetched/supply_e1_corruption.raw" as *u8, store, out, cap)
105 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Political_corruption" as *u8, "knowledge/fetched/supply_e2_political_corruption.raw" as *u8, store, out, cap)
106 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Transparency_International" as *u8, "knowledge/fetched/supply_e3_transparency_intl.raw" as *u8, store, out, cap)
107 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Corruption_Perceptions_Index" as *u8, "knowledge/fetched/supply_e4_cpi.raw" as *u8, store, out, cap)
108 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Organized_crime" as *u8, "knowledge/fetched/supply_e5_organized_crime.raw" as *u8, store, out, cap)
109 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Counterfeit_consumer_goods" as *u8, "knowledge/fetched/supply_e6_counterfeit.raw" as *u8, store, out, cap)
110 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Smuggling" as *u8, "knowledge/fetched/supply_e7_smuggling.raw" as *u8, store, out, cap)
111 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Commercial_property" as *u8, "knowledge/fetched/supply_e8_commercial_property.raw" as *u8, store, out, cap)
112 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Renting" as *u8, "knowledge/fetched/supply_e9_renting.raw" as *u8, store, out, cap)
113
114 ff_puts("== F. COST ECONOMICS ==\n" as *u8)
115 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Cost_of_goods_sold" as *u8, "knowledge/fetched/supply_f1_cogs.raw" as *u8, store, out, cap)
116 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Factors_of_production" as *u8, "knowledge/fetched/supply_f2_factors.raw" as *u8, store, out, cap)
117 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Value_chain" as *u8, "knowledge/fetched/supply_f3_value_chain.raw" as *u8, store, out, cap)
118
119 ff_puts("READABLE SOURCES SAVED THIS PASS+HAVE: " as *u8); ff_putn(ok); ff_puts(" / 44\n" as *u8)
120 return 0
121}