nx_ui_map.nx source
↩ module page · 118 lines · 6361 B
1// nx_ui_map.nx -- sovereign map of the OLD Elder AI frontend, so the sovereign rebuild can match/exceed its
2// parity (operator: "you havent matched our old elder ai frontend, i just see a basic gen ui + a fox sample").
3// Reuses the getdents64 walk; roots at the platform tree; for FRONTEND files (.html/.jsx/.tsx/.vue/.svelte/.htm)
4// prints path + size + the feature-marker lines (<title>, routes, Elara/chat/gallery/scene/character) so the
5// old experience is READ, not guessed. Root/markers baked (nx_sov_build_run doesn't forward args). Sovereign.
6// license_tier: ORIGINAL expect_exit: 0
7import "nx_syscalls.nx"
8import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc)
9const UM_MAGIC_65536: i64 = 65536
10const UM_MAGIC_2048: i64 = 2048
11
12const UM_ROOT: *u8 = "/mnt/c/Users/elder/elder-ai-platform" as *u8
13const UM_FBUF: i64 = 2097152
14const UM_MAXDEPTH: i64 = 14
15const UM_MAXLINES: i64 = 6
16
17func um_strlen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
18func um_puts(s: *u8) -> i64 { sys_write(1, s, um_strlen(s)); return 0 }
19// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer
20// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the
21// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls).
22// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign.
23func um_putn(v: i64) -> i64 { nxi_out(v); return 0 }
24func um_find(buf: *u8, lo: i64, hi: i64, pat: *u8, pl: i64) -> i64 { if pl==0 {return 0} var i: i64=lo; 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 } return 0 }
25func um_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 }
26func um_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 }
27func um_ends(name: *u8, suf: *u8) -> i64 { let n: i64=um_strlen(name); let s: i64=um_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 }
28// frontend file? + skip node_modules-style bloat by depth cap
29func um_is_frontend(name: *u8) -> i64 {
30 if um_ends(name,".html" as *u8)==1 {return 1} if um_ends(name,".htm" as *u8)==1 {return 1}
31 if um_ends(name,".jsx" as *u8)==1 {return 1} if um_ends(name,".tsx" as *u8)==1 {return 1}
32 if um_ends(name,".vue" as *u8)==1 {return 1} if um_ends(name,".svelte" as *u8)==1 {return 1}
33 return 0
34}
35func um_skip_dir(name: *u8) -> i64 {
36 if um_ends(name,"node_modules" as *u8)==1 {return 1}
37 if um_ends(name,".git" as *u8)==1 {return 1}
38 if um_ends(name,"dist" as *u8)==1 {return 1}
39 if um_ends(name,"__pycache__" as *u8)==1 {return 1}
40 return 0
41}
42
43// scan a frontend file: print path+size, then up to UM_MAXLINES feature-marker lines
44func um_scan(path: *u8, fbuf: *u8) -> i64 {
45 let fd: i64 = sys_openat_rd(path)
46 if fd < 0 { return 0 }
47 let n: i64 = sys_read(fd, fbuf, UM_FBUF)
48 sys_close(fd)
49 if n <= 0 { return 0 }
50 um_puts("FILE: " as *u8); um_puts(path); um_puts(" (" as *u8); um_putn(n); um_puts("B)\n" as *u8)
51 var printed: i64 = 0
52 var ls: i64 = 0
53 var i: i64 = 0
54 while i <= n {
55 var eol: i64=0; if i==n {eol=1} else { if fbuf[i]==(10 as u8){eol=1} }
56 if eol==1 {
57 var hit: i64 = 0
58 if um_find(fbuf,ls,i,"<title" as *u8,6)==1 {hit=1}
59 if hit==0 { if um_find(fbuf,ls,i,"Elara" as *u8,5)==1 {hit=1} }
60 if hit==0 { if um_find(fbuf,ls,i,"<Route" as *u8,6)==1 {hit=1} }
61 if hit==0 { if um_find(fbuf,ls,i,"companion" as *u8,9)==1 {hit=1} }
62 if hit==0 { if um_find(fbuf,ls,i,"gallery" as *u8,7)==1 {hit=1} }
63 if hit==0 { if um_find(fbuf,ls,i,"Chat" as *u8,4)==1 {hit=1} }
64 if hit==0 { if um_find(fbuf,ls,i,"scene" as *u8,5)==1 {hit=1} }
65 if hit==0 { if um_find(fbuf,ls,i,"outfit" as *u8,6)==1 {hit=1} }
66 if hit==1 { if printed<UM_MAXLINES {
67 var a: i64=ls; var stop: i64=0; 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} } } }
68 var len: i64=i-a; if len>180 {len=180}
69 um_puts(" | " as *u8); sys_write(1,(fbuf as i64+a) as *u8,len); um_puts("\n" as *u8)
70 printed=printed+1
71 } }
72 ls=i+1
73 }
74 i=i+1
75 }
76 return 1
77}
78
79func um_walk(dirpath: *u8, fbuf: *u8, depth: i64) -> i64 {
80 if depth > UM_MAXDEPTH { return 0 }
81 let dfd: i64 = sys_openat_rd(dirpath)
82 if dfd < 0 { return 0 }
83 let dbuf: *u8 = sys_mmap(UM_MAGIC_65536)
84 var files: i64 = 0
85 var go: i64 = 1
86 while go == 1 {
87 let nread: i64 = sys_getdents64(dfd, dbuf, UM_MAGIC_65536)
88 if nread <= 0 { go = 0 } else {
89 var off: i64 = 0
90 while off < nread {
91 let rec: *u8 = (dbuf as i64 + off) as *u8
92 let reclen: i64 = dirent_reclen(rec)
93 let dtype: i64 = dirent_type(rec)
94 let name: *u8 = dirent_name(rec)
95 if um_is_dot(name) == 0 {
96 if dtype == DT_DIR { if um_skip_dir(name)==0 {
97 let cp: *u8 = sys_mmap(UM_MAGIC_2048); um_join(dirpath, name, cp)
98 files = files + um_walk(cp, fbuf, depth + 1)
99 } } else { if dtype == DT_REG { if um_is_frontend(name)==1 {
100 let cp: *u8 = sys_mmap(UM_MAGIC_2048); um_join(dirpath, name, cp)
101 files = files + um_scan(cp, fbuf)
102 } } }
103 }
104 if reclen <= 0 { off = nread } else { off = off + reclen }
105 }
106 }
107 }
108 sys_close(dfd)
109 return files
110}
111
112func main() -> i64 {
113 um_puts("=== nx_ui_map: sovereign map of the OLD Elder AI frontend (root=elder-ai-platform) ===\n" as *u8)
114 let fbuf: *u8 = sys_mmap(UM_FBUF + 16)
115 let f: i64 = um_walk(UM_ROOT, fbuf, 0)
116 um_puts("=== frontend files mapped = " as *u8); um_putn(f); um_puts(" ===\n" as *u8)
117 sys_exit(0); return 0
118}