code wiki / _hdl_build / nx_receipts.nx

nx_receipts.nx source

↩ module page · 40 lines · 2361 B

1// nx_receipts.nx -- the teammate-facing RECEIPTS READER. Any teammate/workstream runs this to VALIDATE that 2// orchestration is healthy: it tallies the acceptance ledger (total + per-verdict) + tails the recent receipts + 3// gives a one-line VERDICT (HEALTHY iff zero REJECTED/FAILED). The "confirm acceptance + receipts" view. 4// Sovereign: nx_receipt. license_tier: ORIGINAL 5import "nx_syscalls.nx" 6import "nx_receipt.nx" 7const K_MAGIC_1048576: i64 = 1048576 8const K_MAGIC_3000: i64 = 3000 9 10func rp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 11func rnum(v: i64) -> i64 { 12 let bb: *u8 = sys_mmap(28); var m: i64=v; var k: i64=0 13 if m==0 { bb[0]=48 as u8; sys_write(1,bb,1); return 0 } 14 let t: *u8 = sys_mmap(28) 15 while m>0 { t[k]=((48+(m%10)) as u8); m=m/10; k=k+1 } 16 var i: i64=0; while i<k { bb[i]=t[k-1-i]; i=i+1 } 17 sys_write(1,bb,k); return 0 18} 19 20func main(argc: i64, argv: *i64) -> i64 { 21 rp("=== nishi orchestration receipts (acceptance ledger) ===\n" as *u8) 22 let buf: *u8 = sys_mmap(K_MAGIC_1048576) 23 let n: i64 = rcpt_read(RCPT_LEDGER, buf, K_MAGIC_1048576) 24 if n <= 0 { rp("(no receipts yet -- knowledge/receipts/orchestration.tsv empty or absent)\n" as *u8); sys_exit(0); return 0 } 25 let total: i64 = rcpt_count(buf, n) 26 let acc: i64 = rcpt_count_verdict(buf, n, "ACCEPTED" as *u8, 8) 27 let comp: i64 = rcpt_count_verdict(buf, n, "COMPLETED" as *u8, 9) 28 let iss: i64 = rcpt_count_verdict(buf, n, "ISSUED" as *u8, 6) 29 let rej: i64 = rcpt_count_verdict(buf, n, "REJECTED" as *u8, 8) 30 let fld: i64 = rcpt_count_verdict(buf, n, "FAILED" as *u8, 6) 31 rp("total=" as *u8); rnum(total); rp(" accepted=" as *u8); rnum(acc); rp(" completed=" as *u8); rnum(comp) 32 rp(" issued=" as *u8); rnum(iss); rp(" rejected=" as *u8); rnum(rej); rp(" failed=" as *u8); rnum(fld); rp("\n" as *u8) 33 rp("--- recent receipts (tail) ---\n" as *u8) 34 var st: i64 = 0; if n > K_MAGIC_3000 { st = n - K_MAGIC_3000 } 35 sys_write(1, (buf as i64 + st) as *u8, n - st) 36 rp("\nVERDICT: " as *u8) 37 if rej + fld == 0 { rp("orchestration HEALTHY (0 rejected/failed across " as *u8); rnum(total); rp(" receipts)\n" as *u8) } 38 else { rp("ATTENTION -- " as *u8); rnum(rej + fld); rp(" rejected/failed receipt(s); investigate above.\n" as *u8) } 39 sys_exit(0); return 0 40}