code wiki / _hdl_build / nx_trajscan_beat.nx
nx_trajscan_beat.nx source
↩ module page · 72 lines · 3119 B
1// nx_trajscan_beat.nx -- no-arg BEAT for the scheduler (quality-ruler R3 standing gauge, 2026-07-29):
2// scan the live actlog via nx_trajscan (composed through tr_run_capture -- zero detector logic
3// duplicated; the 7/7-gated organ stays the ONE definition) and APPEND the one-line envelope to the
4// trend evidence log. A beat with no evidence line is a claim -- this one writes its line every run,
5// including on failure (BEAT-FAIL lines are evidence too). Scheduler contract: the knowledge/store/clockjobs- plane (the ONE tickless clock; the sched/ registry was retired 2026-08-03, debt 1785792856)
6// fork+execs the elf with NO args; argv[1]=journal argv[2]=trendfile override the defaults for testing.
7// trend line: <epoch>\t<envelope-json-or-BEAT-FAIL>\n (O_APPEND, conflict-free)
8// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
9import "nx_sovjson_lib.nx"
10import "nx_syscalls.nx"
11import "nx_tool_run.nx"
12
13const TB_OUT: i64 = 16384
14const TB_LINE: i64 = 20480
15const TB_MODE: i64 = 420
16
17func tb_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
18func tb_werr(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(2, s, n); return 0 }
19func tb_append(path: *u8, buf: *u8, n: i64) -> i64 {
20 let fd: i64 = sys_openat_append(path, TB_MODE)
21 if fd < 0 { return 0 - 1 }
22 sys_write(fd, buf, n)
23 sys_fsync(fd)
24 sys_close(fd)
25 return 0
26}
27func main(argc: i64, argv: *i64) -> i64 {
28 var jp: *u8 = "knowledge/status/actlog.jrnl" as *u8
29 var tp: *u8 = "knowledge/status/trajscan_trend.jsonl" as *u8
30 if argc > 1 { jp = argv[1] as *u8 }
31 if argc > 2 { tp = argv[2] as *u8 }
32 let elf: *u8 = "/volume1/homes/elderwesto/nishihost/nx_trajscan.elf" as *u8
33 let av: *i64 = sys_mmap(40) as *i64
34 av[0] = elf as i64
35 av[1] = ("scan" as *u8) as i64
36 av[2] = jp as i64
37 av[3] = 0
38 let out: *u8 = sys_mmap(TB_OUT)
39 let ol: *i64 = sys_mmap(16) as *i64
40 let rc: i64 = tr_run_capture(elf, av, out, TB_OUT, ol)
41 let now: i64 = sys_now_realtime_sec()
42 let ln: *u8 = sys_mmap(TB_LINE)
43 var o: i64 = sj_catn(ln, 0, now)
44 ln[o] = 9 as u8
45 o = o + 1
46 var ok: i64 = 0
47 if rc == 0 { if ol[0] > 0 { ok = 1 } }
48 if ok == 1 {
49 var i: i64 = 0
50 while i < ol[0] { if out[i] != (10 as u8) { if o < TB_LINE - 2 { ln[o] = out[i]; o = o + 1 } } i = i + 1 }
51 } else {
52 o = sj_cat(ln, o, "BEAT-FAIL rc=" as *u8)
53 o = sj_catn(ln, o, rc)
54 o = sj_cat(ln, o, " outlen=" as *u8)
55 o = sj_catn(ln, o, ol[0])
56 }
57 ln[o] = 10 as u8
58 o = o + 1
59 if tb_append(tp, ln, o) != 0 { tb_werr("TRAJSCAN-BEAT FAIL cannot append trend file\n" as *u8); sys_exit(1); return 1 }
60 if ok == 1 {
61 tb_puts("TRAJSCAN-BEAT OK appended " as *u8)
62 let m: *u8 = sys_mmap(64)
63 var mo: i64 = sj_catn(m, 0, o)
64 m[mo] = 10 as u8
65 sys_write(1, m, mo + 1)
66 sys_exit(0)
67 return 0
68 }
69 tb_werr("TRAJSCAN-BEAT scan failed (BEAT-FAIL line appended as evidence)\n" as *u8)
70 sys_exit(1)
71 return 1
72}