code wiki / _hdl_build / nx_cap_register.nx
nx_cap_register.nx source
↩ module page · 37 lines · 2336 B
1// nx_cap_register.nx -- the LIBRARIAN registers a capability so the team (not Claude hand-editing) writes
2// the self-model registry (operator: "the librarian is gathering all this information and the nishi team
3// writing functionality is writing this"). A cap is written ONLY if (1) it passes the self-model LINT
4// (valid layer + status -> never the invisible-layer bug) AND (2) governance admitted it (Engineer+Council+
5// docs). The registry is the gathered source the self-model regenerates FROM. license_tier: ORIGINAL
6// Composes nx_self_model_lint + nx_ingest_governed.
7
8import "nx_self_model_lint.nx"
9import "nx_ingest_governed.nx"
10import "nx_syscalls.nx"
11
12// the Librarian's gate: refuse to register an invisible (bad-layer) or ungoverned capability.
13func cr_can_register(layer: i64, status: i64, nlayers: i64, governed_decision: i64) -> i64 {
14 if sml_check_cap(layer, status, nlayers) != SML_OK { return 0 } // lint gate -- blocks the invisible-cap bug
15 if governed_decision != IG_INGEST { return 0 } // governance gate -- blocks un-admitted caps
16 return 1
17}
18
19// why a registration was refused (for the Librarian's report).
20func cr_refusal_reason(layer: i64, status: i64, nlayers: i64, governed_decision: i64) -> i64 {
21 let lc: i64 = sml_check_cap(layer, status, nlayers)
22 if lc != SML_OK { return lc } // SML_BAD_LAYER / SML_BAD_STATUS
23 if governed_decision != IG_INGEST { return 4 } // 4 = not governed
24 return SML_OK
25}
26
27func cr_w(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 }
28func cr_wn(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48;k=1}; while m>0{t[k]=48+(m%10);m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(fd,bb,k); return 0 }
29
30// write one validated+governed CAPREG line to the registry (the gathered, regenerate-from source).
31func cr_write_entry(fd: i64, idx: i64, layer: i64, name: *u8, status: i64) -> i64 {
32 cr_w(fd, "CAPREG idx=" as *u8); cr_wn(fd, idx)
33 cr_w(fd, " layer=" as *u8); cr_wn(fd, layer)
34 cr_w(fd, " status=" as *u8); cr_wn(fd, status)
35 cr_w(fd, " name=" as *u8); cr_w(fd, name); cr_w(fd, "\n" as *u8)
36 return 1
37}