nx_seed.nx source
↩ module page · 325 lines · 13318 B
1// nx_seed.nx -- capability + longevity-aware assembly from silicon up.
2//
3// Per META-CARDINAL feedback-forest-meta-vision-drift-lifecycle:
4// with niche known, nx_seed evaluates the device and grows it into the
5// HIGHEST capability it can sustain for the LONGEST viable lifecycle --
6// silicon-up, niche-shaped, no omni-tool bloat.
7//
8// V1 ships:
9// - sealed enum of organelle bundles (the six organelles per
10// NISHI_SOVEREIGN_RUNTIME_AND_STORAGE_ROADMAP composed into named
11// bundles by niche)
12// - lifecycle-longevity tracking (battery / NAND-wear / thermal /
13// generational hardware turnover)
14// - assembly state machine + per-niche organelle subset selection
15//
16// Composes:
17// nx_niche -- device-purpose verdict gates organelle bundle
18// nx_attest_silicon -- silicon-trust gates sovereignty-critical organelles
19// nx_spore -- successor to spore lifecycle (READY_FOR_SEED -> seed)
20// nx_chromatin -- organelle blocks fetched via chromatin
21// nx_budget -- per-cell budget profile per niche
22//
23// Per [[feedback-honest-perf-verdict-no-aspirational-claims]]:
24// the existing six-organelle substrate is per NISHI_SOVEREIGN_RUNTIME
25// roadmap (cell / brane / vacuole / chromatin / vesicle / lysosome);
26// V1 of nx_seed names the bundle composition WITHOUT yet wiring the
27// actual organelle-fetch pathway (that's V2 once chromatin block
28// transport ships).
29//
30// Gap list (V1 honest perf verdict):
31// - organelle bundle is sealed enum; actual fetch path is V2
32// - longevity targets are research-derived (thermal-design-power,
33// NAND P/E cycles, battery cycle life); per-host validation V2
34// - hardware silicon-up configuration (MMU/caches) is V2+ silicon
35// arc dependency
36//
37// genealogy_id: nishi_metacardinal_2026-05-19_forest_drift_lifecycle
38// lineage_id: substrate_seed_v1
39//
40// nx_safety_envelope:
41// intended_use: "Capability + longevity-aware seed assembly
42// state machine; niche-shaped organelle bundle
43// selection; substrate-level foundation for
44// cell supervisor bring-up"
45// sil_target: SIL2
46// evidence: [enum_sealed, state_machine_explicit,
47// longevity_targets_research_backed,
48// niche_aware_bundle_selection]
49// verdict: NOT_YET_EVALUATED
50
51import "nx_syscalls.nx"
52import "nx_tier.nx"
53const NX_MAGIC_2190: i64 = 2190
54const NX_MAGIC_1825: i64 = 1825
55const NX_MAGIC_1095: i64 = 1095
56const NX_MAGIC_2920: i64 = 2920
57const NX_MAGIC_3650: i64 = 3650
58const NX_MAGIC_5475: i64 = 5475
59
60// ===== Sealed enum: NxOrganelleBundle =============================
61//
62// Per-niche bundle of organelles + supplementary cells. V1 ships
63// canonical bundles for the common niches; V2 makes bundles per-niche
64// data-driven manifests.
65
66const NX_OB_MINIMAL_CORE: nx_int = 0 // all niches; the 6 organelles
67const NX_OB_WORKSTATION_FULL: nx_int = 1 // GAMING_WORKSTATION / DEV_WORKSTATION
68const NX_OB_LAPTOP_BATTERY_AWARE: nx_int = 2 // LAPTOP / TABLET
69const NX_OB_SMARTPHONE_RADIO_AWARE: nx_int = 3
70const NX_OB_NAS_STORAGE_HEAVY: nx_int = 4 // HOME_NAS
71const NX_OB_IOT_LIGHTWEIGHT: nx_int = 5 // EMBEDDED_SENSOR / IOT_HUB
72const NX_OB_INDUSTRIAL_REALTIME: nx_int = 6 // INDUSTRIAL_PLC / ROBOTIC_ARM / AGV
73const NX_OB_MEDICAL_SAFETY_GATED: nx_int = 7 // MEDICAL_DIAGNOSTIC / THERAPEUTIC
74const NX_OB_AUTOMOTIVE_SAFETY_CRITICAL: nx_int = 8 // AUTOMOTIVE_ECU
75const NX_OB_3DPRINTER_CNC_LASER: nx_int = 9 // DESKTOP_3DPRINTER / CNC / LASER
76const NX_OB_N_BUNDLES: nx_int = 10
77
78// ===== Sealed enum: NxSeedAssemblyState ===========================
79
80const NX_SE_PENDING_NICHE: nx_int = 0 // waiting for niche verdict
81const NX_SE_BUNDLE_SELECTED: nx_int = 1
82const NX_SE_TRUST_GATED: nx_int = 2 // silicon-trust check pending
83const NX_SE_FETCHING_ORGANELLES: nx_int = 3
84const NX_SE_VERIFYING_ORGANELLES: nx_int = 4
85const NX_SE_ASSEMBLED: nx_int = 5
86const NX_SE_FAILED: nx_int = 6
87const NX_SE_N_STATES: nx_int = 7
88
89// ===== Sealed enum: NxSeedVerdict =================================
90
91const NX_SE_V_OK: nx_int = 0
92const NX_SE_V_ERR_INVALID_NICHE: nx_int = 1
93const NX_SE_V_ERR_INVALID_BUNDLE: nx_int = 2
94const NX_SE_V_ERR_TRUST_INSUFFICIENT: nx_int = 3
95const NX_SE_V_ERR_NULL_INPUT: nx_int = 4
96const NX_SE_V_ERR_INVALID_TRANSITION: nx_int = 5
97const NX_SE_V_REFUSED_NICHE: nx_int = 6 // refused niche per nx_allelopathy
98const NX_SE_V_N_VERDICTS: nx_int = 7
99
100// ===== Struct: NxSeedAssembly =====================================
101
102struct NxSeedAssembly {
103 niche: nx_int,
104 bundle: nx_int,
105 silicon_trust_level: nx_int,
106 state: nx_int,
107 requires_safety_gate: nx_int,
108 expected_lifecycle_days: nx_int, // research-derived target
109 thermal_budget_w: nx_int, // sustained host TDP target
110 started_at_us: nx_size,
111 assembled_at_us: nx_size,
112}
113
114const NX_SE_BYTES: nx_int = 64
115
116// ===== nx_ob_bundle_is_valid ======================================
117
118func nx_ob_bundle_is_valid(b: nx_int) -> nx_int {
119 if b < 0 { return 0 }
120 if b >= NX_OB_N_BUNDLES { return 0 }
121 return 1
122}
123
124// ===== nx_se_state_is_valid =======================================
125
126func nx_se_state_is_valid(s: nx_int) -> nx_int {
127 if s < 0 { return 0 }
128 if s >= NX_SE_N_STATES { return 0 }
129 return 1
130}
131
132// ===== nx_se_v_is_valid ===========================================
133
134func nx_se_v_is_valid(v: nx_int) -> nx_int {
135 if v < 0 { return 0 }
136 if v >= NX_SE_V_N_VERDICTS { return 0 }
137 return 1
138}
139
140// ===== nx_ob_requires_safety_gate =================================
141//
142// Predicate: bundle requires operator safety-confirmation before
143// assembly proceeds (medical-therapeutic, automotive, industrial).
144
145func nx_ob_requires_safety_gate(b: nx_int) -> nx_int {
146 if b == NX_OB_MEDICAL_SAFETY_GATED { return 1 }
147 if b == NX_OB_AUTOMOTIVE_SAFETY_CRITICAL { return 1 }
148 if b == NX_OB_INDUSTRIAL_REALTIME { return 1 }
149 if b == NX_OB_3DPRINTER_CNC_LASER { return 1 }
150 return 0
151}
152
153// ===== nx_ob_select_for_niche =====================================
154//
155// Map nx_niche value to canonical organelle bundle. Caller passes
156// the niche int (matches NX_NICHE_* from nx_niche.nx).
157
158func nx_ob_select_for_niche(niche: nx_int) -> nx_int {
159 // GAMING_WORKSTATION (0) / DEV_WORKSTATION (1)
160 if niche == 0 { return NX_OB_WORKSTATION_FULL }
161 if niche == 1 { return NX_OB_WORKSTATION_FULL }
162 // LAPTOP (2) / TABLET (6)
163 if niche == 2 { return NX_OB_LAPTOP_BATTERY_AWARE }
164 if niche == 6 { return NX_OB_LAPTOP_BATTERY_AWARE }
165 // HOME_NAS (3)
166 if niche == 3 { return NX_OB_NAS_STORAGE_HEAVY }
167 // HOME_MEDIA_PLAYER (4) -- gets minimal core
168 if niche == 4 { return NX_OB_MINIMAL_CORE }
169 // SMARTPHONE (5)
170 if niche == 5 { return NX_OB_SMARTPHONE_RADIO_AWARE }
171 // DESKTOP_3D_PRINTER (7) / CNC (8) / LASER (9)
172 if niche == 7 { return NX_OB_3DPRINTER_CNC_LASER }
173 if niche == 8 { return NX_OB_3DPRINTER_CNC_LASER }
174 if niche == 9 { return NX_OB_3DPRINTER_CNC_LASER }
175 // INDUSTRIAL_ROBOTIC_ARM (10) / PLC (11) / VISION (12) / AGV (13)
176 if niche == 10 { return NX_OB_INDUSTRIAL_REALTIME }
177 if niche == 11 { return NX_OB_INDUSTRIAL_REALTIME }
178 if niche == 12 { return NX_OB_INDUSTRIAL_REALTIME }
179 if niche == 13 { return NX_OB_INDUSTRIAL_REALTIME }
180 // MEDICAL_DIAGNOSTIC (20) / THERAPEUTIC (21)
181 if niche == 20 { return NX_OB_MEDICAL_SAFETY_GATED }
182 if niche == 21 { return NX_OB_MEDICAL_SAFETY_GATED }
183 // AUTOMOTIVE_ECU (30)
184 if niche == 30 { return NX_OB_AUTOMOTIVE_SAFETY_CRITICAL }
185 // EMBEDDED_SENSOR (40) / FARM_SOIL_MONITOR (41) / HOME_IOT_HUB (42)
186 if niche == 40 { return NX_OB_IOT_LIGHTWEIGHT }
187 if niche == 41 { return NX_OB_IOT_LIGHTWEIGHT }
188 if niche == 42 { return NX_OB_IOT_LIGHTWEIGHT }
189 return NX_OB_MINIMAL_CORE
190}
191
192// ===== nx_ob_expected_lifecycle_days ==============================
193//
194// Per-bundle target lifecycle in days (research-derived from typical
195// hardware-class lifespan). Per Cardinal 11 (no magic numbers in code),
196// these are documented thresholds.
197
198func nx_ob_expected_lifecycle_days(b: nx_int) -> nx_int {
199 if b == NX_OB_WORKSTATION_FULL { return NX_MAGIC_2190 } // 6 years typical
200 if b == NX_OB_LAPTOP_BATTERY_AWARE { return NX_MAGIC_1825 } // 5 years
201 if b == NX_OB_SMARTPHONE_RADIO_AWARE { return NX_MAGIC_1095 } // 3 years
202 if b == NX_OB_NAS_STORAGE_HEAVY { return NX_MAGIC_2920 } // 8 years
203 if b == NX_OB_IOT_LIGHTWEIGHT { return NX_MAGIC_3650 } // 10 years
204 if b == NX_OB_INDUSTRIAL_REALTIME { return NX_MAGIC_5475 } // 15 years
205 if b == NX_OB_MEDICAL_SAFETY_GATED { return NX_MAGIC_3650 } // 10 years
206 if b == NX_OB_AUTOMOTIVE_SAFETY_CRITICAL { return NX_MAGIC_5475 } // 15 years
207 if b == NX_OB_3DPRINTER_CNC_LASER { return NX_MAGIC_2920 } // 8 years
208 if b == NX_OB_MINIMAL_CORE { return NX_MAGIC_1095 } // 3 years
209 return 0
210}
211
212// ===== nx_ob_thermal_budget_w =====================================
213
214func nx_ob_thermal_budget_w(b: nx_int) -> nx_int {
215 if b == NX_OB_WORKSTATION_FULL { return 65 }
216 if b == NX_OB_LAPTOP_BATTERY_AWARE { return 25 }
217 if b == NX_OB_SMARTPHONE_RADIO_AWARE { return 5 }
218 if b == NX_OB_NAS_STORAGE_HEAVY { return 35 }
219 if b == NX_OB_IOT_LIGHTWEIGHT { return 1 }
220 if b == NX_OB_INDUSTRIAL_REALTIME { return 15 }
221 if b == NX_OB_MEDICAL_SAFETY_GATED { return 20 }
222 if b == NX_OB_AUTOMOTIVE_SAFETY_CRITICAL { return 30 }
223 if b == NX_OB_3DPRINTER_CNC_LASER { return 25 }
224 if b == NX_OB_MINIMAL_CORE { return 10 }
225 return 0
226}
227
228// ===== _se_transition_allowed =====================================
229
230func _se_transition_allowed(from: nx_int, to: nx_int) -> nx_int {
231 if to == NX_SE_FAILED {
232 if from == NX_SE_ASSEMBLED { return 0 }
233 if from == NX_SE_FAILED { return 0 }
234 if nx_se_state_is_valid(from) == 1 { return 1 }
235 return 0
236 }
237 if from == NX_SE_PENDING_NICHE {
238 if to == NX_SE_BUNDLE_SELECTED { return 1 }
239 return 0
240 }
241 if from == NX_SE_BUNDLE_SELECTED {
242 if to == NX_SE_TRUST_GATED { return 1 }
243 return 0
244 }
245 if from == NX_SE_TRUST_GATED {
246 if to == NX_SE_FETCHING_ORGANELLES { return 1 }
247 return 0
248 }
249 if from == NX_SE_FETCHING_ORGANELLES {
250 if to == NX_SE_VERIFYING_ORGANELLES { return 1 }
251 return 0
252 }
253 if from == NX_SE_VERIFYING_ORGANELLES {
254 if to == NX_SE_ASSEMBLED { return 1 }
255 return 0
256 }
257 return 0
258}
259
260// ===== nx_se_assembly_new =========================================
261
262func nx_se_assembly_new(niche: nx_int,
263 silicon_trust_level: nx_int) -> *NxSeedAssembly {
264 let raw: *u8 = sys_mmap(NX_SE_BYTES)
265 let a: *NxSeedAssembly = raw as *NxSeedAssembly
266 a.niche = niche
267 a.bundle = NX_OB_MINIMAL_CORE
268 a.silicon_trust_level = silicon_trust_level
269 a.state = NX_SE_PENDING_NICHE
270 a.requires_safety_gate = 0
271 a.expected_lifecycle_days = 0
272 a.thermal_budget_w = 0
273 a.started_at_us = 0
274 a.assembled_at_us = 0
275 return a
276}
277
278// ===== nx_se_assembly_select_bundle ===============================
279//
280// Apply niche -> bundle mapping + record safety-gate requirement +
281// lifecycle target + thermal budget.
282
283func nx_se_assembly_select_bundle(a: *NxSeedAssembly,
284 now_us: nx_size) -> nx_int {
285 if (a as i64) == 0 { return NX_SE_V_ERR_NULL_INPUT }
286 if a.state != NX_SE_PENDING_NICHE { return NX_SE_V_ERR_INVALID_TRANSITION }
287 // niche values 50-53 are NX_NICHE_REFUSED_*
288 if a.niche >= 50 {
289 if a.niche <= 53 { return NX_SE_V_REFUSED_NICHE }
290 }
291 let b: nx_int = nx_ob_select_for_niche(a.niche)
292 if nx_ob_bundle_is_valid(b) == 0 { return NX_SE_V_ERR_INVALID_BUNDLE }
293 a.bundle = b
294 a.requires_safety_gate = nx_ob_requires_safety_gate(b)
295 a.expected_lifecycle_days = nx_ob_expected_lifecycle_days(b)
296 a.thermal_budget_w = nx_ob_thermal_budget_w(b)
297 a.state = NX_SE_BUNDLE_SELECTED
298 a.started_at_us = now_us
299 return NX_SE_V_OK
300}
301
302// ===== nx_se_assembly_advance =====================================
303//
304// Advance to next state in the assembly state machine.
305
306func nx_se_assembly_advance(a: *NxSeedAssembly,
307 to: nx_int,
308 now_us: nx_size) -> nx_int {
309 if (a as i64) == 0 { return NX_SE_V_ERR_NULL_INPUT }
310 if nx_se_state_is_valid(to) == 0 { return NX_SE_V_ERR_INVALID_TRANSITION }
311 if _se_transition_allowed(a.state, to) == 0 {
312 return NX_SE_V_ERR_INVALID_TRANSITION
313 }
314 a.state = to
315 if to == NX_SE_ASSEMBLED { a.assembled_at_us = now_us }
316 return NX_SE_V_OK
317}
318
319// ===== nx_se_assembly_is_complete =================================
320
321func nx_se_assembly_is_complete(a: *NxSeedAssembly) -> nx_int {
322 if (a as i64) == 0 { return 0 }
323 if a.state != NX_SE_ASSEMBLED { return 0 }
324 return 1
325}