nx_char_verify.nx source
↩ module page · 119 lines · 6354 B
1// nx_char_verify.nx -- sovereign recursive grep over the Elder AI platform tree to VERIFY the real character
2// appearance (operator: "Elara is a blonde, doublecheck"). Reuses the nx_explore getdents64 walk pattern, but
3// rooted at the platform tree and scanning readable/db files (not just .nx) for the character's hair/appearance.
4// Prints path + each matching line so the REAL DNA is read, not assumed. Root + queries baked (nx_sov_build_run
5// does not forward args). Zero egress, sovereign. license_tier: ORIGINAL expect_exit: 0
6import "nx_syscalls.nx"
7const CV_MAGIC_65536: i64 = 65536
8const CV_MAGIC_2048: i64 = 2048
9
10const CV_ROOT: *u8 = "/mnt/c/Users/elder/elder-ai-platform" as *u8
11const CV_FBUF: i64 = 4194304
12const CV_MAXDEPTH: i64 = 16
13const CV_MAXLINES: i64 = 8 // print at most this many matching lines per file
14
15func cv_strlen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
16func cv_puts(s: *u8) -> i64 { sys_write(1, s, cv_strlen(s)); return 0 }
17func cv_find(buf: *u8, lo: i64, hi: i64, pat: *u8, pl: i64) -> i64 {
18 if pl==0 { return 0 }
19 var i: i64=lo
20 while i+pl<=hi { var j: i64=0; while j<pl { if buf[i+j]!=pat[j]{j=pl+1} else {j=j+1} } if j==pl {return 1} i=i+1 }
21 return 0
22}
23func cv_is_dot(name: *u8) -> i64 { if name[0]==(46 as u8){ if name[1]==(0 as u8){return 1} if name[1]==(46 as u8){ if name[2]==(0 as u8){return 1} } } return 0 }
24func cv_join(dirpath: *u8, name: *u8, out: *u8) -> i64 { var p: i64=0; var a: i64=0; while dirpath[a]!=(0 as u8){out[p]=dirpath[a];p=p+1;a=a+1} out[p]=47 as u8; p=p+1; var b: i64=0; while name[b]!=(0 as u8){out[p]=name[b];p=p+1;b=b+1} out[p]=0 as u8; return 0 }
25// suffix test
26func cv_ends(name: *u8, suf: *u8) -> i64 { let n: i64=cv_strlen(name); let s: i64=cv_strlen(suf); if n<s {return 0} var i: i64=0; while i<s { if name[n-s+i]!=suf[i]{return 0} i=i+1 } return 1 }
27// skip obviously-binary / huge model files
28func cv_skip(name: *u8) -> i64 {
29 if cv_ends(name,".png" as *u8)==1 {return 1} if cv_ends(name,".jpg" as *u8)==1 {return 1} if cv_ends(name,".jpeg" as *u8)==1 {return 1}
30 if cv_ends(name,".gguf" as *u8)==1 {return 1} if cv_ends(name,".safetensors" as *u8)==1 {return 1} if cv_ends(name,".bin" as *u8)==1 {return 1}
31 if cv_ends(name,".zip" as *u8)==1 {return 1} if cv_ends(name,".elf" as *u8)==1 {return 1} if cv_ends(name,".exe" as *u8)==1 {return 1}
32 if cv_ends(name,".dll" as *u8)==1 {return 1} if cv_ends(name,".so" as *u8)==1 {return 1} if cv_ends(name,".pyc" as *u8)==1 {return 1}
33 if cv_ends(name,".webp" as *u8)==1 {return 1} if cv_ends(name,".mp4" as *u8)==1 {return 1} if cv_ends(name,".pack" as *u8)==1 {return 1}
34 return 0
35}
36
37// scan one file: print up to CV_MAXLINES lines containing q1 OR q2. returns total matches.
38func cv_scan(path: *u8, q1: *u8, l1: i64, q2: *u8, l2: i64, fbuf: *u8) -> i64 {
39 let fd: i64 = sys_openat_rd(path)
40 if fd < 0 { return 0 }
41 let n: i64 = sys_read(fd, fbuf, CV_FBUF)
42 sys_close(fd)
43 if n <= 0 { return 0 }
44 var count: i64 = 0
45 var printed: i64 = 0
46 var ls: i64 = 0
47 var i: i64 = 0
48 while i <= n {
49 var eol: i64 = 0
50 if i == n { eol = 1 } else { if fbuf[i]==(10 as u8) { eol = 1 } }
51 if eol == 1 {
52 var hit: i64 = 0
53 if cv_find(fbuf, ls, i, q1, l1)==1 { hit=1 }
54 if hit==0 { if cv_find(fbuf, ls, i, q2, l2)==1 { hit=1 } }
55 if hit==1 {
56 count = count + 1
57 if printed < CV_MAXLINES {
58 // trim leading ws, cap length to keep output readable
59 var a: i64 = ls; var stop: i64=0
60 while stop==0 { if a>=i {stop=1} else { let c: i64=fbuf[a] as i64; if c==32 {a=a+1} else { if c==9 {a=a+1} else {stop=1} } } }
61 var len: i64 = i - a
62 if len > 300 { len = 300 }
63 cv_puts(" | " as *u8); sys_write(1, (fbuf as i64 + a) as *u8, len); cv_puts("\n" as *u8)
64 printed = printed + 1
65 }
66 }
67 ls = i + 1
68 }
69 i = i + 1
70 }
71 if count > 0 { cv_puts(" FILE: " as *u8); cv_puts(path); cv_puts("\n" as *u8) }
72 return count
73}
74
75func cv_walk(dirpath: *u8, q1: *u8, l1: i64, q2: *u8, l2: i64, fbuf: *u8, depth: i64) -> i64 {
76 if depth > CV_MAXDEPTH { return 0 }
77 let dfd: i64 = sys_openat_rd(dirpath)
78 if dfd < 0 { return 0 }
79 let dbuf: *u8 = sys_mmap(CV_MAGIC_65536)
80 var files: i64 = 0
81 var go: i64 = 1
82 while go == 1 {
83 let nread: i64 = sys_getdents64(dfd, dbuf, CV_MAGIC_65536)
84 if nread <= 0 { go = 0 } else {
85 var off: i64 = 0
86 while off < nread {
87 let rec: *u8 = (dbuf as i64 + off) as *u8
88 let reclen: i64 = dirent_reclen(rec)
89 let dtype: i64 = dirent_type(rec)
90 let name: *u8 = dirent_name(rec)
91 if cv_is_dot(name) == 0 {
92 if dtype == DT_DIR {
93 let cp: *u8 = sys_mmap(CV_MAGIC_2048); cv_join(dirpath, name, cp)
94 files = files + cv_walk(cp, q1, l1, q2, l2, fbuf, depth + 1)
95 } else { if dtype == DT_REG { if cv_skip(name)==0 {
96 let cp: *u8 = sys_mmap(CV_MAGIC_2048); cv_join(dirpath, name, cp)
97 if cv_scan(cp, q1, l1, q2, l2, fbuf) > 0 { files = files + 1 }
98 } } }
99 }
100 if reclen <= 0 { off = nread } else { off = off + reclen }
101 }
102 }
103 }
104 sys_close(dfd)
105 return files
106}
107
108func main() -> i64 {
109 cv_puts("=== nx_char_verify: sovereign grep for the REAL Elara appearance (root=elder-ai-platform) ===\n" as *u8)
110 let fbuf: *u8 = sys_mmap(CV_FBUF + 16)
111 let q1: *u8 = "blond" as *u8 // her real hair
112 let q2: *u8 = "Elara" as *u8 // her definition
113 cv_puts("scanning for 'blond' OR 'Elara' in readable/db files...\n" as *u8)
114 let f: i64 = cv_walk(CV_ROOT, q1, cv_strlen(q1), q2, cv_strlen(q2), fbuf, 0)
115 cv_puts("files with matches = " as *u8)
116 let d: *u8=sys_mmap(24); var m: i64=f; var k: i64=0; if m==0{d[0]=48 as u8;k=1} while m>0{d[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=k-1; while i>=0{ let o: *u8=sys_mmap(1); o[0]=d[i]; sys_write(1,o,1); i=i-1 }
117 cv_puts("\n" as *u8)
118 sys_exit(0); return 0
119}