code wiki / (root) / nx_incumbent_lib.nx

nx_incumbent_lib.nx

buildroot/runtime/nx_incumbent_lib.nx

61815 B1427 linesdepth 2pulls 2 transitivereach 3 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_incumbent_lib.nx -- THE ONE RULER FOR A RUNG CONTRACT'S INCUMBENTS AND THE RECORD'S REJECTIONS (engineshift ES28). Operator 2026-09-14, on the search R0 review: "this is the stuff we need the search and nishi estate to do proactively not rely on you treasure hunting." A prior seat rebuilt the R0 rerank arm as a learned fusion over PPMI while the estate already held the trained dense embedding (knowledge/index/embed_v1.bin), the lib that scores with it (nx_dr_densejudge) and, in that lib's own header, the MEASURED REJECTION of exactly that fusion (DR-13). The reviewing seat found all three by glob and header reads: a retrieval failure, not a discovery. nx_capsearch ranks registered tools and libs by name, title and grammar; it cannot see a header's prose, a data asset, or a rejection. This lib answers a rung's contract from the record itself, and nx_compare_rank prints the answer on every open rung so no seat starts a build from its own memory. THE INDEX (a derived artefact, stamped, refused when stale): one row per organ source in the two runtime roots org|<name>|<root>|<header words, lowercase, unique, first 12 bytes each>|<knowledge/ paths the header names>|<rejection lines> and one per data asset under knowledge/index: asset|<name>|<name words> headed by # NX-DERIVED incumbent index generated_at=<epoch> files=<n> head_truncated=<n> assets=<n> corpus_complete=<0|1> The HEADER of an organ is its leading comment block (the // lines before the first code line); its words, its basename parts and its column-0 func names are one bag. A header longer than the read window is COUNTED (head_truncated), never silently cut. A bag word is kept to 12 bytes for display; no key or match reads past 8. THE MATCH: the contract terms are the rung's title, symbol and note tokenised to lowercase runs of letters and digits at least min_tok long, deduplicated by their MATCH PREFIX (rerank and reranker are one term, beat and beats are one term); an all-digit term is DROPPED and counted (a number is a measurement, never a capability word: measured 2026-09-14, the 321 in "321 permille" matched three throwaway test organs at a rare-token weight). A term matches a bag word when their leading bytes agree -- the first morph_long bytes for a term at least that long, else the WHOLE term (mine~miner is the prefix rule nx_capsearch measured on its gold set at 4 bytes; here the 4-byte key only narrows the posting chain, because measured on 2026-09-14 the 4-byte cut made dense match density and wired match wire). Each matched term weighs idf_scale / (idf_base + df), df being the number of organs carrying it (the weighting nx_capsearch ships), and a term carried by more than df_max_permil of the organs is DROPPED as non-discriminating and COUNTED, so no stop-word list is hand-written: the corpus decides which words say nothing. An organ's score is the sum over its distinct matched terms, and a term that also hits the organ's own NAME parts adds its idf a second time: the name is the organ's own declaration of what it is, a second piece of evidence weighed like the first (the rule nx_capsearch's known-good tooltop applies, a stem hit on the name counted beside a hit in the title). MEASURED 2026-09-14 on the live tree (20,820 organs): ranking by a name TIER first put an organ named for two process words (wired, exceed) second for R0 at a tiny weight, so the name hit is weighed, never sorted on. The rung's own organ is excluded. THE LIST IS THE ANSWER, NEVER A THRESHOLD: the top topn organs print with their name hits, score and matched terms, then the data assets those headers name plus assets whose own name matches a term, then the rejection lines those headers carry. PRIOR-REJECTIONS is its own axis: beyond the top organs, every organ whose NAME carries a contract term and whose header records a rejection is listed (capped by rej_orgs, overflow counted), because a rejection on an organ named for the contract's own word is the record answering the contract -- that is how R0

dependencies 1 imports · 3 importers

nx_syscalls.nx nx_incumbent_lib.nx nx_compare_rank.nx nx_incumbent_gate.nx nx_incumbents.nx

imports: nx_syscalls.nx

imported by: nx_compare_rank.nxnx_incumbent_gate.nxnx_incumbents.nx

structs

none

consts

50const INC_I64: i64 = 8
51const INC_NL: i64 = 10
52const INC_CR: i64 = 13
53const INC_TAB: i64 = 9
54const INC_PIPE: i64 = 124
55const INC_SPACE: i64 = 32
56const INC_SLASH: i64 = 47
57const INC_SEMI: i64 = 59
58const INC_EQ: i64 = 61
59const INC_HASHCH: i64 = 35
60const INC_DOT: i64 = 46
61const INC_COLON: i64 = 58
62const INC_LPAREN: i64 = 40
63const INC_RPAREN: i64 = 41
64const INC_COMMA: i64 = 44
65const INC_DQUOTE: i64 = 34
66const INC_SQUOTE: i64 = 39
67const INC_RBRACK: i64 = 93
68const INC_GT: i64 = 62
69const INC_MINUS: i64 = 45
70const INC_A: i64 = 97
71const INC_Z: i64 = 122
72const INC_UA: i64 = 65
73const INC_UZ: i64 = 90
74const INC_D0: i64 = 48
75const INC_D9: i64 = 57
76const INC_CH_N: i64 = 110
77const INC_CH_X: i64 = 120
78const INC_CASE_DELTA: i64 = 32
79const INC_KEY_BYTES: i64 = 8 // a key packs up to 8 leading bytes into one i64; no match reads past 8
80const INC_WORD_KEEP: i64 = 12 // a bag word or a term is kept to 12 bytes for display
81const INC_BYTE_BITS: i64 = 8
82const INC_HASH_MUL: i64 = 1099511628211 // an odd multiplier for the packed key (the FNV-1a prime)
83const INC_HASH_SHIFT: i64 = 29
84const INC_NAME_CAP: i64 = 256
85const INC_PATH_CAP: i64 = 1024
86const INC_NUM_CAP: i64 = 32
87const INC_DIRBUF: i64 = 65536 // the getdents window nx_presubmit_lib uses (PS_DIRBUF)
88const INC_SETCAP: i64 = 4096 // per-file word set slots (a header carries hundreds of words, never thousands)
89const INC_HASH_MIN: i64 = 1024
90const INC_CONF_A: *u8 = "knowledge/incumbent.conf"
91const INC_CONF_B: *u8 = "../knowledge/incumbent.conf"
92const INC_REJ_A: *u8 = "knowledge/incumbent_reject.conf"
93const INC_REJ_B: *u8 = "../knowledge/incumbent_reject.conf"
94const INC_INDEX_A: *u8 = "knowledge/status/incumbent_index.txt"
95const INC_INDEX_B: *u8 = "../knowledge/status/incumbent_index.txt"
96const INC_TMP_SUFFIX: *u8 = ".tmp"
97const INC_ROOT_RT_A: *u8 = "buildroot/runtime"
98const INC_ROOT_HDL_A: *u8 = "buildroot/runtime/_hdl_build"
99const INC_ASSET_A: *u8 = "knowledge/index"
100const INC_ROOT_RT_B: *u8 = "runtime"
101const INC_ROOT_HDL_B: *u8 = "runtime/_hdl_build"
102const INC_ASSET_B: *u8 = "../knowledge/index"
103const INC_HEAD_MARK: *u8 = "# NX-DERIVED incumbent index generated_at="
104const INC_ORG_TAG: *u8 = "org|"
105const INC_ASSET_TAG: *u8 = "asset|"
106const INC_KNOW: *u8 = "knowledge/"
107const INC_FUNC: *u8 = "func "
108const INC_FUNC_LEN: i64 = 5
109const INC_REJ_SEP: *u8 = ";; "
110const INC_ORG_FIELDS: i64 = 6
111const INC_ASSET_FIELDS: i64 = 3
112const INC_ROW_SLACK: i64 = 1024 // per row beyond the header window: name, root, separators, asset paths
114const INC_D_HEAD_BYTES: i64 = 8192
115const INC_D_MORPH_LONG: i64 = 6
116const INC_D_MORPH_SHORT: i64 = 4
117const INC_D_MIN_TOK: i64 = 3
118const INC_D_TOPN: i64 = 8
119const INC_D_DF_MAX_PERMIL: i64 = 250
120const INC_D_IDF_SCALE: i64 = 1000000
121const INC_D_IDF_BASE: i64 = 3
122const INC_D_REJ_PER_ORG: i64 = 2
123const INC_D_REJ_LINE_CAP: i64 = 160
124const INC_D_INDEX_MAX_AGE_S: i64 = 172800
125const INC_D_MAX_TERMS: i64 = 62
126const INC_D_REJ_ORGS: i64 = 8
127const INC_PERMIL: i64 = 1000
129const INC_C_HEAD_BYTES: i64 = 0
130const INC_C_MORPH_LONG: i64 = 1
131const INC_C_MORPH_SHORT: i64 = 2
132const INC_C_MIN_TOK: i64 = 3
133const INC_C_TOPN: i64 = 4
134const INC_C_DF_MAX_PERMIL: i64 = 5
135const INC_C_IDF_SCALE: i64 = 6
136const INC_C_IDF_BASE: i64 = 7
137const INC_C_REJ_PER_ORG: i64 = 8
138const INC_C_REJ_LINE_CAP: i64 = 9
139const INC_C_INDEX_MAX_AGE_S: i64 = 10
140const INC_C_MAX_TERMS: i64 = 11
141const INC_C_SRC: i64 = 12 // 1 conf file read, 0 defaults
142const INC_C_REJ_ORGS: i64 = 13 // organs listed under PRIOR-REJECTIONS beyond the top organs
143const INC_C_N: i64 = 14
145const INC_G_BUF: i64 = 0
146const INC_G_N: i64 = 1
147const INC_G_ROWS: i64 = 2
148const INC_G_R_NAME: i64 = 3
149const INC_G_R_ROOT: i64 = 4
150const INC_G_R_WORDS: i64 = 5
151const INC_G_R_ASSETS: i64 = 6
152const INC_G_R_REJ: i64 = 7
153const INC_G_ASSETS: i64 = 8
154const INC_G_A_NAME: i64 = 9
155const INC_G_A_WORDS: i64 = 10
156const INC_G_HCAP: i64 = 11
157const INC_G_HKEY: i64 = 12
158const INC_G_HHEAD: i64 = 13
159const INC_G_PWORD: i64 = 14
160const INC_G_PROW: i64 = 15
161const INC_G_PNEXT: i64 = 16
162const INC_G_NPOST: i64 = 17
163const INC_G_GEN: i64 = 18
164const INC_G_FILES: i64 = 19
165const INC_G_TRUNC: i64 = 20
166const INC_G_COMPLETE: i64 = 21
167const INC_G_STATE: i64 = 22
168const INC_G_AGE: i64 = 23
169const INC_G_PATH: i64 = 24
170const INC_G_SEEN: i64 = 25 // per-row scratch stamp for df counting
171const INC_G_SCORE: i64 = 26
172const INC_G_MASK: i64 = 27
173const INC_G_TIER: i64 = 28 // per-row scratch: contract terms hitting the organ's name parts
174const INC_G_NIDF: i64 = 29 // per-row scratch: the idf of the terms hitting the organ's name parts
175const INC_G_N_SLOTS: i64 = 30
177const INC_S_FRESH: i64 = 0
178const INC_S_STALE: i64 = 1
179const INC_S_ABSENT: i64 = 2
180const INC_S_MALFORMED: i64 = 3
182const INC_R_N: i64 = 0
183const INC_R_ROW: i64 = 1
184const INC_R_SCORE: i64 = 2
185const INC_R_MASK: i64 = 3
186const INC_R_NTERMS: i64 = 4
187const INC_R_TERMS: i64 = 5
188const INC_R_TOFF: i64 = 6
189const INC_R_DROPPED: i64 = 7
190const INC_R_DROPMASK: i64 = 8
191const INC_R_OVER: i64 = 9
192const INC_R_MATCHED: i64 = 10
193const INC_R_TIER: i64 = 11
194const INC_R_NUMERIC: i64 = 12 // all-digit terms dropped
195const INC_R_TIDF: i64 = 13 // per-term idf weight (0 when dropped or unmatched)
196const INC_R_N_SLOTS: i64 = 14
198const INC_E_FILES: i64 = 0
199const INC_E_TRUNC: i64 = 1
200const INC_E_ASSETS: i64 = 2
201const INC_E_COMPLETE: i64 = 3
202const INC_E_GEN: i64 = 4
203const INC_E_BYTES: i64 = 5
204const INC_E_N: i64 = 6
206const INC_B_CONF: i64 = 0
207const INC_B_ENV: i64 = 1
208const INC_B_REJ: i64 = 2
209const INC_B_NREJ: i64 = 3
210const INC_B_SET: i64 = 4
211const INC_B_ROOT: i64 = 5
212const INC_B_NAME: i64 = 6
213const INC_B_WORD: i64 = 7
214const INC_B_POS: i64 = 8
215const INC_B_CAND: i64 = 9
216const INC_B_HEAD: i64 = 10
217const INC_B_N: i64 = 11
219const INC_V_ASTART: i64 = 0
220const INC_V_NA: i64 = 1
221const INC_V_N: i64 = 2
222const INC_NONE: i64 = 0 - 1
223const INC_CLOCK_WORDS: i64 = 2

functions

228func inc_slen(s: *u8) -> i64
233func inc_cat(d: *u8, o: i64, s: *u8) -> i64
241func inc_catb(d: *u8, o: i64, cap: i64, s: *u8) -> i64
248func inc_catn(d: *u8, o: i64, cap: i64, v: i64) -> i64
263func inc_streq(a: *u8, b: *u8) -> i64
269func inc_starts(s: *u8, pre: *u8) -> i64
275func inc_lend(buf: *u8, n: i64, p: i64) -> i64
282func inc_wend(buf: *u8, n: i64, p: i64) -> i64
289func inc_contains(s: *u8, n: i64, needle: *u8) -> i64
called by 2: g_hasinc_row_for calls 1: inc_slen
302func inc_is_alnum(b: i64) -> i64
called by 1: inc_next_word
308func inc_is_digit(b: i64) -> i64
called by 2: inc_atoiinc_match
313func inc_lower(b: i64) -> i64
called by 1: inc_next_word
318func inc_atoi(s: *u8, off: i64) -> i64
called by 1: inc_kv_int calls 1: inc_is_digit
329func inc_kv_int(s: *u8, key: *u8) -> i64
342func inc_now() -> i64
348func inc_ends_nx(nm: *u8, l: i64) -> i64
356func inc_organ_name(path: *u8, out: *u8) -> i64
called by 2: maininc_row_for calls 2: inc_sleninc_ends_nx
369func inc_listed(buf: *u8, from: i64, o: i64, name: *u8) -> i64
385func inc_cwd_is_nishihost() -> i64
called by 2: mainmain calls 2: sys_openat_rdsys_close
393func inc_conf_take(c: *i64, ln: *u8, key: *u8, slot: i64) -> i64
called by 1: inc_conf_load calls 1: inc_kv_int
399func inc_conf_load() -> *i64
451func inc_reject_load(count: *i64) -> *u8
476func inc_reject_nth(rej: *u8, k: i64) -> *u8
called by 1: inc_row_for
486func inc_next_word(s: *u8, n: i64, pos: *i64, out: *u8) -> i64
507func inc_key(w: *u8, take: i64) -> i64
514func inc_hash(k: i64, cap: i64) -> i64
522func inc_list_dir(dir: *u8, names: *u8, want: i64, srconly: i64) -> i64
556func inc_read_head(path: *u8, buf: *u8, cap: i64) -> i64
571func inc_set_add(set: *i64, cap: i64, w: *u8) -> i64
called by 1: inc_bag_emit calls 2: inc_keyinc_hash
585func inc_bag_emit(b: *i64, s: *u8, n: i64, out: *u8, o: i64, firstp: *i64) -> i64
605func inc_head_end(hb: *u8, got: i64, cap: i64, trunc: *i64) -> i64
called by 1: inc_row_for calls 1: inc_lend
626func inc_path_stop(b: i64) -> i64
called by 1: inc_row_for
641func inc_row_for(b: *i64, path: *u8, out: *u8, o: i64) -> i64
748func inc_asset_row(b: *i64, name: *u8, out: *u8, o: i64) -> i64
764func inc_publish(out_path: *u8, head: *u8, rows: *u8, rows_len: i64) -> i64
787func inc_fill_names(dir: *u8, cnt: i64, srconly: i64, env: *i64) -> *u8
793func inc_index_build(c: *i64, root_a: *u8, root_b: *u8, asset_dir: *u8, out_path: *u8) -> *i64
867func inc_split(ln: *u8, fld: *i64, maxf: i64) -> i64
called by 1: inc_load_path
877func inc_hput(g: *i64, key: i64, word: i64, row: i64) -> i64
called by 1: inc_load_path calls 1: inc_hash
900func inc_hfind(g: *i64, key: i64) -> i64
called by 1: inc_match calls 1: inc_hash
913func inc_state_name(s: i64) -> *u8
920func inc_load_path(c: *i64, path: *u8, now: i64) -> *i64
1040func inc_load(c: *i64) -> *i64
called by 2: mainmain calls 2: inc_nowinc_load_path
1050func inc_term_hits(c: *i64, term: *u8, tlen: i64, word: *u8) -> i64
1061func inc_name_hits(c: *i64, r: *i64, name: *u8, w: *u8, pos: *i64, out2: *i64) -> i64
1086func inc_match(g: *i64, c: *i64, title: *u8, sym: *u8, note: *u8, excl: *u8) -> *i64
1219func inc_asset_hits(c: *i64, r: *i64, ws: *u8) -> i64
1243func inc_render_assets(g: *i64, row: i64, out: *u8, o: i64, cap: i64, v: *i64) -> i64
1264func inc_render_rej(g: *i64, row: i64, out: *u8, o: i64, cap: i64, v: *i64) -> i64
called by 1: inc_render calls 1: inc_catb
1278func inc_rej_cand(g: *i64, r: *i64, row: i64) -> i64
called by 1: inc_render
1290func inc_render(g: *i64, c: *i64, r: *i64, rid: *u8, out: *u8, cap: i64) -> i64
1405func inc_envelope(g: *i64, out: *u8, cap: i64) -> i64