code wiki / _hdl_build / nx_pattern_library.nx

nx_pattern_library.nx source

↩ module page · 156 lines · 10656 B

1// nx_pattern_library.nx -- the BUILDER's PATTERN LIBRARY (operator: "get the builders pattern library 2// truly s class exceed comprehensive"). The scaffold author emits BOILERPLATE; the gap is the module 3// CORE. But most module cores aren't novel -- they fit a small set of recurring SHAPES. This library 4// catalogs those shapes so the Builder authors the core itself, dropping bp_claude_touch toward 0. The 5// more shapes covered, the more of the team's build work is autonomous = the S-class-exceed measure. 6// Derived from the REAL modules built this session (each is one of these shapes): 7// VERDICT_GATE -- thresholds -> a named verdict (jam_check, litho_stepper dose, dose verdict) 8// PARSER_KAT -- bytes -> value, exact KATs (claim_extract, stl parse, gcode emit) 9// COMPARATOR -- a vs b -> winner/score, no self-grade(research_exceed, referee) 10// THRESHOLD_TABLE-- interpolated lookup (jam capacity, metrology class) 11// ACCUMULATOR -- fold over an array -> a metric (metrology deviation, autonomy permil, breadth) 12// GOVERNOR -- rate/pace/backoff over per-host state (polite_crawl) 13// STATE_FLOW -- stages + transitions + verdict (build_raci, build_pipeline, ingest verdict) 14// SCAFFOLD -- module+test+register boilerplate (scaffold_author -- already team-owned) 15// GEOMETRY -- nm coords + area/spacing/DRC (mask_geom, micron_geom, fab_slice) 16// PID_LOOP -- error -> control, plant sim oracle (heater_pid) 17// A spec's `shape_id` (from the assignment) maps to a pattern; covered shapes are team-authorable. 18// RACI: the BUILDER owns this (the AUTHOR's pattern catalog). Wires to bp_core_autonomous (a covered 19// shape means pattern_id>0 -> autonomous core). LAWS: struct-free, integer-only. license_tier: ORIGINAL 20import "nx_syscalls.nx" 21 22// the catalog: each shape a distinct pattern id (>0 = a known, team-authorable pattern; 0 = novel) 23const PL_VERDICT_GATE: i64 = 1 24const PL_PARSER_KAT: i64 = 2 25const PL_COMPARATOR: i64 = 3 26const PL_THRESHOLD_TABLE: i64 = 4 27const PL_ACCUMULATOR: i64 = 5 28const PL_GOVERNOR: i64 = 6 29const PL_STATE_FLOW: i64 = 7 30const PL_SCAFFOLD: i64 = 8 31const PL_GEOMETRY: i64 = 9 32const PL_PID_LOOP: i64 = 10 33// shapes 11-14: the post-census growth rungs (emit6-9 -- MATH_KERNEL from the math-engine arc, 34// WIRE_TLV/STRUCT_WALK/IO_CONTRACT from the browser/race arcs). Census synced 2026-06-10 after 35// nx_classifier_sync caught the drift (emitters at 14, census stuck at 10). 36const PL_MATH_KERNEL: i64 = 11 37const PL_WIRE_TLV: i64 = 12 38const PL_STRUCT_WALK: i64 = 13 39const PL_IO_CONTRACT: i64 = 14 40// shape 15 (emit10): WIRE_MARKER -- JPEG-style prefix+marker streams (standalone table, inclusive 41// lengths, terminator). Grown from a measured race loss; synced same-day when nx_classifier_sync 42// went RED(15/14/14) on its FIRST pulse beat -- the drift gate working live. 43const PL_WIRE_MARKER: i64 = 15 44// shape 16 (emit11): PREDICTOR_CODER -- lossless predictor/residual coders (fixed linear predict 45// + zigzag + exact-inverse law + out-of-range refusal). Grown from the NV1 FLAC-class LPC rung 46// (nx_nv1_lpc) the library could not author hands-off. 47const PL_PREDICTOR_CODER: i64 = 16 48// shape 17 (emit12): TEMPLATE_TABLE -- HTML-fragment renderer cores from a row table (escaped/raw 49// payload modes, two-slot rows, unknown-kind refusal). Census row added by the AUDITOR's 50// classifier_sync drift gate firing (emit12 shipped without the sync -- the gate did its job). 51const PL_TEMPLATE_TABLE: i64 = 17 52// shape 18 (emit13): STATE_MACHINE -- deterministic FSMs from a transition table (baked step/run, 53// undefined-transition refusal). First rung of the advanced-stack ladders (DirectX pipeline 54// validation / CUDA queue lifecycles / Klipper G-code modes / TLS flight order); first machine = 55// _pe_tlshs, the TLS 1.3 handshake-order validator (gate 8/8: every reorder/replay/skip refused). 56const PL_STATE_MACHINE: i64 = 18 57// shape 19 (emit15): PNG_INGEST -- the COMPOSE-shape (DECLARED-SCAFFOLD, operator-authorized 58// R3, X-AUT-NCF-001 / spec 2026-06-13-keystone-newcontrolflow-route-decision.md names "the 59// 5-stage ingest compose" verbatim). Unlike every leaf emitter (one fn over one buffer), this 60// authors <name>_ingest(buf,flen,prefix) that LOOPS over all PNG chunks and CALLS the green 61// organs (_pe_pngchunk/_pe_pngtext -> canon_encode/cid_of -> ss_get/ss_begin/ss_add/ss_commit): 62// cross-organ composition + per-chunk loop + idempotent store side-effects = new control flow 63// no existing data-driven shape emits. BOOTSTRAP-PROVISIONAL (X-AUT-NCF-BOOT) -- author=tutor, 64// DEBITED vs autonomy; the FIRST rider (nx_store_ingest) is organ-authored from a DATA spec. 65const PL_PNG_INGEST: i64 = 19 66// shape 20 (emit14/pe14): LOG_SCAN -- the PERMIL_VERDICT scoreboard core. Composes the proven 67// nx_census_run scan/count substrate with a baked permil=count*1000/total + ordered verdict-band 68// ladder (emitter-of-emitters bootstrap fruit, X-AUT-004b). Routed by features reads_log+derives_permil. 69const PL_LOG_SCAN: i64 = 20 70// shape 21 (RANK_FUSE): a K-way Reciprocal-Rank-Fusion core over the team-owned nx_rrf -- the researcher's 71// internal+external fusion shape. Emitter = nx_pattern_emit_rankfuse (claims shape 21); proven team-authorable 72// (rf_authored.nx compiled+passed end-to-end). First of the session's 5-emitter autonomy backlog; the core 73// organ nx_rrf already existed, so the emitter just wires it K times (a covered-shape autonomy win). 74const PL_RANK_FUSE: i64 = 21 75// shape 22 (RANK_RETRIEVE): a deterministic term-frequency retrieval core with a baked relevance floor -- the 76// researcher's internal-arm shape (faithful: returns -1 when nothing clears the floor). Emitter = 77// nx_pattern_emit_rankretrieve (claims shape 22); proven team-authorable (rr_authored.nx compiled+passed). 2nd 78// of the session's 5-emitter autonomy backlog. 79const PL_RANK_RETRIEVE: i64 = 22 80// shape 23 (RTL_SYNTH): lowers a 3-address op-DAG spec to a baked dataflow core (AND/OR/XOR/ADD composed by data 81// dependency) -- the NRTL synthesis shape. Emitter = nx_pattern_emit_rtlsynth (shape 23); proven team-authorable 82// (rs_authored.nx compiled+passed). 3rd of the session's 5-emitter autonomy backlog (a meatier core than the rank emitters). 83const PL_RTL_SYNTH: i64 = 23 84// shape 24 (NETLIST_COMPOSE): a K-way fabric fold composing the team-owned fab_append (nx_fpga_compose net-remap 85// primitive). Emitter = nx_pattern_emit_netcompose (shape 24); proven team-authorable (nc_authored.nx compiled+passed). 86// 4th of the session's 5-emitter autonomy backlog. 87const PL_NETLIST_COMPOSE: i64 = 24 88// shape 25 (FABRIC_NETLIST): a W-bit per-bit LUT4 fabric builder (cells+nets, runs on team-owned fab_eval) -- the 89// foundational gate-level shape. Emitter = nx_pattern_emit_fabricnetlist (shape 25); proven team-authorable 90// (fn_authored.nx compiled+passed on fab_eval). 5th + LAST of the session's autonomy backlog -- the EDA + researcher 91// shapes this session built Claude-authored are now ALL team-authorable. 92const PL_FABRIC_NETLIST: i64 = 25 93const PL_N_PATTERNS: i64 = 25 94 95// how many patterns the library covers (the breadth of the Builder's autonomy) 96func pl_n_patterns() -> i64 { return PL_N_PATTERNS } 97 98// is a shape_id a known pattern? (1 = team-authorable core; 0 = novel -> NEEDS_TUTOR) 99func pl_covered(shape_id: i64) -> i64 { 100 if shape_id >= 1 { if shape_id <= PL_N_PATTERNS { return 1 } } 101 return 0 102} 103 104// map a spec's shape to its pattern id (here the shape_id IS the pattern id for covered shapes; a real 105// classifier would infer shape from the spec's in/out types -- the flagged next rung). 0 = novel. 106func pl_match(shape_id: i64) -> i64 { 107 if pl_covered(shape_id) == 1 { return shape_id } 108 return 0 109} 110 111// the COMPREHENSIVENESS metric: over a set of module shapes (e.g. a backlog of assignments), what 112// fraction does the pattern library cover? per-mil. Drives the team's autonomous-build fraction. 113func pl_coverage_permil(shape_ids: *i64, n: i64) -> i64 { 114 if n <= 0 { return 0 } 115 var covered: i64 = 0 116 var i: i64 = 0 117 while i < n { if pl_covered(shape_ids[i]) == 1 { covered = covered + 1 } i = i + 1 } 118 return covered * 1000 / n 119} 120 121// S-CLASS-EXCEED gate: the library is comprehensive iff it covers at least `floor_permil` of a 122// representative spec set. (S-class = broad enough that novel cores are the exception, not the rule.) 123func pl_is_comprehensive(shape_ids: *i64, n: i64, floor_permil: i64) -> i64 { 124 if pl_coverage_permil(shape_ids, n) >= floor_permil { return 1 } 125 return 0 126} 127 128// the pattern name (for the Builder's report / the catalog) 129func pl_name(pattern_id: i64) -> *u8 { 130 if pattern_id == PL_VERDICT_GATE { return "VERDICT_GATE" as *u8 } 131 if pattern_id == PL_PARSER_KAT { return "PARSER_KAT" as *u8 } 132 if pattern_id == PL_COMPARATOR { return "COMPARATOR" as *u8 } 133 if pattern_id == PL_THRESHOLD_TABLE { return "THRESHOLD_TABLE" as *u8 } 134 if pattern_id == PL_ACCUMULATOR { return "ACCUMULATOR" as *u8 } 135 if pattern_id == PL_GOVERNOR { return "GOVERNOR" as *u8 } 136 if pattern_id == PL_STATE_FLOW { return "STATE_FLOW" as *u8 } 137 if pattern_id == PL_SCAFFOLD { return "SCAFFOLD" as *u8 } 138 if pattern_id == PL_GEOMETRY { return "GEOMETRY" as *u8 } 139 if pattern_id == PL_PID_LOOP { return "PID_LOOP" as *u8 } 140 if pattern_id == PL_MATH_KERNEL { return "MATH_KERNEL" as *u8 } 141 if pattern_id == PL_WIRE_TLV { return "WIRE_TLV" as *u8 } 142 if pattern_id == PL_STRUCT_WALK { return "STRUCT_WALK" as *u8 } 143 if pattern_id == PL_IO_CONTRACT { return "IO_CONTRACT" as *u8 } 144 if pattern_id == PL_WIRE_MARKER { return "WIRE_MARKER" as *u8 } 145 if pattern_id == PL_PREDICTOR_CODER { return "PREDICTOR_CODER" as *u8 } 146 if pattern_id == PL_TEMPLATE_TABLE { return "TEMPLATE_TABLE" as *u8 } 147 if pattern_id == PL_STATE_MACHINE { return "STATE_MACHINE" as *u8 } 148 if pattern_id == PL_PNG_INGEST { return "PNG_INGEST" as *u8 } 149 if pattern_id == PL_LOG_SCAN { return "LOG_SCAN" as *u8 } 150 if pattern_id == PL_RANK_FUSE { return "RANK_FUSE" as *u8 } 151 if pattern_id == PL_RANK_RETRIEVE { return "RANK_RETRIEVE" as *u8 } 152 if pattern_id == PL_RTL_SYNTH { return "RTL_SYNTH" as *u8 } 153 if pattern_id == PL_NETLIST_COMPOSE { return "NETLIST_COMPOSE" as *u8 } 154 if pattern_id == PL_FABRIC_NETLIST { return "FABRIC_NETLIST" as *u8 } 155 return "NOVEL(needs-tutor)" as *u8 156}