nx_register.nx source
↩ module page · 61 lines · 2638 B
1// nx_register.nx -- WRITING arc, rung W-ING-3 (X-WRITE-ING-002): the REGISTER
2// CLASSIFIER + SFW/EXPLICIT ROUTING SEAM with GOVERNANCE. This is the seam from
3// the 2026-06-12 fiction-ingestion spec: the tutor (Claude) builds the
4// content-agnostic mechanism; the operator's local-LLM lane runs the explicit
5// register THROUGH it.
6//
7// MECHANISM ONLY (no explicit content authored here): a register is scored by an
8// intensity LEXICON that is pure DATA (rule 25) -- the caller supplies terms +
9// per-term weights. The SFW lane and the operator's explicit lane each extend the
10// lexicon WITHOUT touching this organ. The gate proves the math with benign
11// proxy terms (calm/heated/graphic).
12//
13// GOVERNANCE is non-bypassable by construction: content that scores at/above the
14// explicit threshold may route to the explicit lane ONLY if age + consent + locale
15// all pass; otherwise it is REFUSED. (Anti-exploitation X-ETH-001, consent/
16// provenance, locale-law + age-verification -- all DATA inputs to rg_decision.)
17//
18// rg_score(t, a, b, terms, weights, nterms) -> sum(count(term)*weight) = intensity
19// rg_decision(score, threshold, age_ok, consent_ok, locale_ok) ->
20// RG_ROUTE_SFW(0) : below threshold -> tutor/team SFW lane
21// RG_ROUTE_EXPLICIT_LANE(1): at/above threshold AND governance OK -> local lane
22// RG_ROUTE_REFUSE(2) : at/above threshold AND governance NOT satisfied
23//
24// Pure integer, NO syscalls. Reuses nx_ingest's whole-word counter (DRY).
25//
26// license_tier: ORIGINAL
27// module: nishi-core.write.register
28// depends: nishi-core.write.ingest
29// capability: WRITE_REGISTER_ROUTING
30import "nx_ingest.nx"
31import "nx_ingest_scene.nx" // ig_* scene/entity extractor
32
33const RG_ROUTE_SFW: i64 = 0
34const RG_ROUTE_EXPLICIT_LANE: i64 = 1
35const RG_ROUTE_REFUSE: i64 = 2
36
37// intensity score = sum over lexicon of (whole-word count * weight)
38func rg_score(t: *u8, a: i64, b: i64, terms: *u8, weights: *i64, nterms: i64) -> i64 {
39 var s: i64 = 0
40 var k: i64 = 0
41 while k < nterms {
42 let off: i64 = ig_name_off(terms, k)
43 let cnt: i64 = ig_count_name_in(t, a, b, terms, off)
44 s = s + cnt * weights[k]
45 k = k + 1
46 }
47 return s
48}
49
50// route decision with non-bypassable governance gate
51func rg_decision(score: i64, threshold: i64, age_ok: i64, consent_ok: i64, locale_ok: i64) -> i64 {
52 if score < threshold { return RG_ROUTE_SFW }
53 if age_ok == 1 {
54 if consent_ok == 1 {
55 if locale_ok == 1 {
56 return RG_ROUTE_EXPLICIT_LANE
57 }
58 }
59 }
60 return RG_ROUTE_REFUSE
61}