nx_substrate_layers.nx source
↩ module page · 153 lines · 6040 B
1// nx_substrate_layers.nx -- bits-up layer enum + handoff quality.
2//
3// User directive 2026-05-16: "from the bits to bytes up handoffs so
4// we can get extreme precision on how capable we build out nishi
5// lang".
6//
7// Cardinal feedback-bits-up-canonical-layer-no-reinventing already
8// names the layer stack as an audit discipline ("audit L0(bits) ->
9// L1(containers) -> L2(transforms) -> L3(algorithms)"). This file
10// makes that stack a SEALED-ENUM PRIMITIVE so every substrate file
11// can self-declare its layer + the coverage scanner can produce a
12// bits-up roll-up that shows EVERY layer handoff.
13//
14// The six S-class substrate layers:
15//
16// L0 BITS raw i64 / u8 / pointer arithmetic; no containers
17// L1 CONTAINERS *u8 buffer + length, NxArena, Image, NxTensor,
18// NxStream -- typed shapes over L0 bits
19// L2 TRANSFORMS nx_scale_*, nx_image_*, nx_hash_*, nx_pk_eq_ci
20// -- pure functions over L1 containers
21// L3 ALGORITHMS nx_aes, nx_sha3, nx_ssim, parse, codegen --
22// stateful or multi-step over L2 transforms
23// L4 COMPOSITES racing primitives, capability audit, gauntlet --
24// orchestrators over L3 algorithms
25// L5 SURFACES visualizer output, dashboards, CLI wrappers --
26// user-facing presentation over L4 composites
27//
28// Handoff quality (the precision-of-handoff axis the user named):
29//
30// CLEAN typed, no leakage, sealed-enum verdict
31// DERIVED composed correctly, higher layer omits some typing
32// LEAKY lower-layer details leak through (e.g., raw *i64 where
33// *Image was canonical; the F-meta-4 syscall coupling)
34// BROKEN handoff doesn't compile or has a known regression
35//
36// Per cardinal user-owns-every-bit: substrate carries the SEALED
37// ENUMS (6 layers + 4 handoff verdicts). Which layers a particular
38// user-built substrate slice exercises is caller-driven.
39//
40// nx_capability_claims:
41// needs: [sealed_enum, integer_compare]
42// provides: [substrate_layer_enum, handoff_quality_enum,
43// layer_name, layer_is_valid, handoff_is_valid]
44// safety: [no_unchecked_deref, no_floating_point, no_syscall,
45// bit_equal_reproducible, target_agnostic, kind_isolated]
46// verdict: [sealed_enum_6_state, sealed_enum_4_state]
47// license: ORIGINAL
48// kind: racing_crew_specialist
49// layer: L4 (this file is a composite over L3 enum semantics)
50
51// ---- Sealed enum: substrate layer ---------------------------------
52
53const NX_LAYER_BITS: i64 = 0
54const NX_LAYER_CONTAINERS: i64 = 1
55const NX_LAYER_TRANSFORMS: i64 = 2
56const NX_LAYER_ALGORITHMS: i64 = 3
57const NX_LAYER_COMPOSITES: i64 = 4
58const NX_LAYER_SURFACES: i64 = 5
59const NX_LAYER_N: i64 = 6
60
61func nx_layer_is_valid(L: i64) -> i64 {
62 if L < 0 { return 0 }
63 if L >= NX_LAYER_N { return 0 }
64 return 1
65}
66
67// Returns a static *u8 name (caller does NOT free).
68func nx_layer_name(L: i64) -> *u8 {
69 if L == NX_LAYER_BITS { return "BITS" as *u8 }
70 if L == NX_LAYER_CONTAINERS { return "CONTAINERS" as *u8 }
71 if L == NX_LAYER_TRANSFORMS { return "TRANSFORMS" as *u8 }
72 if L == NX_LAYER_ALGORITHMS { return "ALGORITHMS" as *u8 }
73 if L == NX_LAYER_COMPOSITES { return "COMPOSITES" as *u8 }
74 if L == NX_LAYER_SURFACES { return "SURFACES" as *u8 }
75 return "INVALID" as *u8
76}
77
78func nx_layer_name_len(L: i64) -> i64 {
79 if L == NX_LAYER_BITS { return 4 }
80 if L == NX_LAYER_CONTAINERS { return 10 }
81 if L == NX_LAYER_TRANSFORMS { return 10 }
82 if L == NX_LAYER_ALGORITHMS { return 10 }
83 if L == NX_LAYER_COMPOSITES { return 10 }
84 if L == NX_LAYER_SURFACES { return 8 }
85 return 7
86}
87
88// Short tag "L0".."L5" (for compact log/telemetry annotation).
89func nx_layer_tag(L: i64) -> *u8 {
90 if L == NX_LAYER_BITS { return "L0" as *u8 }
91 if L == NX_LAYER_CONTAINERS { return "L1" as *u8 }
92 if L == NX_LAYER_TRANSFORMS { return "L2" as *u8 }
93 if L == NX_LAYER_ALGORITHMS { return "L3" as *u8 }
94 if L == NX_LAYER_COMPOSITES { return "L4" as *u8 }
95 if L == NX_LAYER_SURFACES { return "L5" as *u8 }
96 return "L?" as *u8
97}
98
99// Parse a "L0".."L5" tag back to enum (returns NX_LAYER_N on miss).
100func nx_layer_parse_tag(buf: *u8, n: i64) -> i64 {
101 if buf == (0 as *u8) { return NX_LAYER_N }
102 if n != 2 { return NX_LAYER_N }
103 if buf[0] != 0x4c { return NX_LAYER_N } // 'L'
104 let d: i64 = buf[1] as i64
105 if d < 0x30 { return NX_LAYER_N }
106 if d > 0x35 { return NX_LAYER_N }
107 return d - 0x30
108}
109
110// ---- Sealed enum: handoff quality ----------------------------------
111
112const NX_HANDOFF_CLEAN: i64 = 0
113const NX_HANDOFF_DERIVED: i64 = 1
114const NX_HANDOFF_LEAKY: i64 = 2
115const NX_HANDOFF_BROKEN: i64 = 3
116const NX_HANDOFF_N: i64 = 4
117
118func nx_handoff_is_valid(H: i64) -> i64 {
119 if H < 0 { return 0 }
120 if H >= NX_HANDOFF_N { return 0 }
121 return 1
122}
123
124func nx_handoff_name(H: i64) -> *u8 {
125 if H == NX_HANDOFF_CLEAN { return "CLEAN" as *u8 }
126 if H == NX_HANDOFF_DERIVED { return "DERIVED" as *u8 }
127 if H == NX_HANDOFF_LEAKY { return "LEAKY" as *u8 }
128 if H == NX_HANDOFF_BROKEN { return "BROKEN" as *u8 }
129 return "INVALID" as *u8
130}
131
132func nx_handoff_name_len(H: i64) -> i64 {
133 if H == NX_HANDOFF_CLEAN { return 5 }
134 if H == NX_HANDOFF_DERIVED { return 7 }
135 if H == NX_HANDOFF_LEAKY { return 5 }
136 if H == NX_HANDOFF_BROKEN { return 6 }
137 return 7
138}
139
140// Verdict severity (for sorting / coloring): CLEAN=0 best, BROKEN=3 worst.
141// This is the integer value itself; helper exists for clarity at call site.
142func nx_handoff_severity(H: i64) -> i64 {
143 if nx_handoff_is_valid(H) == 0 { return 99 }
144 return H
145}
146
147// Predicate: does this handoff verdict gate a substrate slice for
148// SSS-class graduation? CLEAN + DERIVED pass; LEAKY + BROKEN block.
149func nx_handoff_is_sss_gating(H: i64) -> i64 {
150 if H == NX_HANDOFF_LEAKY { return 1 }
151 if H == NX_HANDOFF_BROKEN { return 1 }
152 return 0
153}