code wiki / (root) / nx_h264_diag.nx

nx_h264_diag.nx source

↩ module page · 70 lines · 3109 B

1// nx_h264_diag.nx -- Nishi Teacher DIAGNOSTIC ENGINE: parse a raw log/output against the machine-readable 2// issue taxonomy (knowledge/registry/nishi_issues.tsv) and, for every matched symptom keyword (field 0), 3// emit the structured guidance line (type / role / diagnosis / fix / prevention) so the dr/engineer/builder 4// roles can instantly recognise the ISSUE TYPE and route a self-heal. Turns our own logs into recognisers: 5// every fix we teach becomes a matcher over future output. Reusable function `nx_diag_run`. 6// genealogy_id: nishi_teacher_log_to_issue_taxonomy license_tier: ORIGINAL 7import "nx_syscalls.nx" 8 9// is reg[ns..ns+nl) present in log[0..loglen) ? 10func diag_substr(log: *u8, loglen: i64, reg: *u8, ns: i64, nl: i64) -> i64 { 11 if nl <= 0 { return 0 } 12 var i: i64 = 0 13 while i + nl <= loglen { 14 var j: i64 = 0 15 var okm: i64 = 1 16 while j < nl { if log[i + j] != reg[ns + j] { okm = 0; j = nl } else { j = j + 1 } } 17 if okm == 1 { return 1 } 18 i = i + 1 19 } 20 return 0 21} 22// scan each taxonomy row's keyword vs the log; emit matched rows to stdout (+fd). Returns # matched. 23func nx_diag_run(reg: *u8, reglen: i64, log: *u8, loglen: i64, fd: i64) -> i64 { 24 var matches: i64 = 0 25 var pos: i64 = 0 26 var lineno: i64 = 0 27 while pos < reglen { 28 let ls: i64 = pos 29 // find line end (at '\n' or buffer end) 30 var le: i64 = ls 31 var f: i64 = 0 32 while f == 0 { 33 if le >= reglen { f = 1 } else { 34 if reg[le] == (10 as u8) { f = 1 } else { le = le + 1 } 35 } 36 } 37 if lineno > 0 { if le > ls { 38 // keyword = field 0 = [ls .. first TAB) 39 var ke: i64 = ls 40 var ff: i64 = 0 41 while ff == 0 { 42 if ke >= le { ff = 1 } else { 43 if reg[ke] == (9 as u8) { ff = 1 } else { ke = ke + 1 } 44 } 45 } 46 let klen: i64 = ke - ls 47 if klen > 0 { if diag_substr(log, loglen, reg, ls, klen) == 1 { 48 sys_write(1, "ISSUE-MATCH: \x00" as *u8, 13); if fd > 0 { sys_write(fd, "ISSUE-MATCH: \x00" as *u8, 13) } 49 sys_write(1, (reg as i64 + ls) as *u8, le - ls); if fd > 0 { sys_write(fd, (reg as i64 + ls) as *u8, le - ls) } 50 sys_write(1, "\n\x00" as *u8, 1); if fd > 0 { sys_write(fd, "\n\x00" as *u8, 1) } 51 matches = matches + 1 52 } } 53 } } 54 lineno = lineno + 1 55 pos = le + 1 56 } 57 return matches 58} 59 60func main() -> i64 { 61 // demo: diagnose a real gate log against the taxonomy 62 let rzp: *i64 = sys_mmap(16) as *i64 63 let reg: *u8 = sys_read_file("knowledge/registry/nishi_issues.tsv\x00" as *u8, rzp) 64 if (reg as i64) == 0 { sys_write(1, "no issues.tsv\n\x00" as *u8, 13); return 1 } 65 let lzp: *i64 = sys_mmap(16) as *i64 66 let log: *u8 = sys_read_file("knowledge/status/h264_brecon.log\x00" as *u8, lzp) 67 if (log as i64) == 0 { sys_write(1, "no log\n\x00" as *u8, 7); return 0 } 68 let m: i64 = nx_diag_run(reg, rzp[0], log, lzp[0], 0) 69 return 0 70}