nx_writehub_loop.nx source
↩ module page · 73 lines · 4284 B
1// nx_writehub_loop.nx -- WRITING HUB rung R2: the autonomous IMMUNE-SCORED keep/discard decider -- the
2// "grows on its own / autonomously improving" core. Uses the shared scorer lib nx_writehub_score (whl_eval:
3// nx_writecraft readability + nx_writestyle adverb/passive/weak/hard-sentence -> ONE composite quality permil),
4// then DECIDES: KEEP (>= WHL_KEEP) or REVISE -- naming the single WORST dimension as a directive the seat
5// (nx_writehub_seat) can act on next round. Fully sovereign (no seat needed to run). Self-proves with two
6// fixtures (a weak draft MUST revise, a clean draft MUST keep = the discriminator gate) and also scores a live
7// draft at knowledge/staging/writehub_draft.txt if present. license_tier: ORIGINAL module: nishi-core.writehub.loop
8import "nx_writehub_score.nx" // whl_eval + whl_directive + WHL_* consts (brings nx_writestyle + nx_syscalls)
9const K_MAGIC_2097152: i64 = 2097152
10
11func wp(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); if fd>0 { sys_write(fd,s,n) } return 0 }
12func wn(fd: i64, v: i64) -> i64 {
13 var m: i64=v
14 if m<0 { wp(fd, "-" as *u8); m=0-m }
15 let t: *u8=sys_mmap(28); var k: i64=0; if m==0 { t[0]=48 as u8; k=1 }
16 while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 }
17 let b: *u8=sys_mmap(28); var i: i64=0; while i<k { b[i]=t[k-1-i]; i=i+1 }
18 sys_write(1,b,k); if fd>0 { sys_write(fd,b,k) } return 0
19}
20func whl_strlen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
21
22func whl_report(label: *u8, rep: *i64, fd: i64) -> i64 {
23 wp(fd, " " as *u8); wp(fd, label)
24 wp(fd, " words=" as *u8); wn(fd, rep[0]); wp(fd, " sents=" as *u8); wn(fd, rep[1])
25 wp(fd, " fk_milli=" as *u8); wn(fd, rep[2])
26 wp(fd, " adv=" as *u8); wn(fd, rep[3]); wp(fd, " pass=" as *u8); wn(fd, rep[4]); wp(fd, " weak=" as *u8); wn(fd, rep[5])
27 wp(fd, " hard=" as *u8); wn(fd, rep[8]); wp(fd, " dia_milli=" as *u8); wn(fd, rep[6])
28 wp(fd, " -> QUALITY=" as *u8); wn(fd, rep[14]); wp(fd, " permil verdict=" as *u8)
29 if rep[14] >= WHL_KEEP { wp(fd, "KEEP" as *u8) } else { wp(fd, "REVISE" as *u8) }
30 wp(fd, " directive=[" as *u8); wp(fd, whl_directive(rep[15])); wp(fd, "]\n" as *u8)
31 return 0
32}
33
34func main() -> i64 {
35 let fd: i64 = sys_openat_append("knowledge/status/writehub_loop.log" as *u8, 0x1a4)
36 wp(fd, "=== WRITEHUB AUTONOMY LOOP (immune-scored keep/discard; shared scorer lib; sovereign, no seat needed) ===\n" as *u8)
37
38 let weak: *u8 = "The door was opened slowly by the very frightened woman, and she was clearly terrified as she walked quietly and carefully through the extremely dark and absolutely silent hallway that seemed to stretch endlessly before her trembling form." as *u8
39 let strong: *u8 = "She opened the door. The room stood empty. Rain struck the glass. He waited a long moment. Then he spoke her name." as *u8
40
41 let repW: *i64 = sys_mmap(256) as *i64
42 let repS: *i64 = sys_mmap(256) as *i64
43 let pw: i64 = whl_eval(weak, whl_strlen(weak), repW)
44 whl_report("WEAK-fixture " as *u8, repW, fd)
45 let ps: i64 = whl_eval(strong, whl_strlen(strong), repS)
46 whl_report("STRONG-fixture" as *u8, repS, fd)
47
48 let dfd: i64 = sys_openat_rd("knowledge/staging/writehub_draft.txt" as *u8)
49 if dfd >= 0 {
50 let db: *u8 = sys_mmap(K_MAGIC_2097152)
51 let dn: i64 = sys_read(dfd, db, K_MAGIC_2097152)
52 sys_close(dfd)
53 if dn > 0 {
54 let repL: *i64 = sys_mmap(256) as *i64
55 whl_eval(db, dn, repL)
56 whl_report("LIVE-draft " as *u8, repL, fd)
57 }
58 }
59
60 var ok: i64 = 1
61 if pw >= WHL_KEEP { ok = 0 }
62 if ps < WHL_KEEP { ok = 0 }
63 wp(fd, " discriminator: weak=" as *u8); wn(fd, pw); wp(fd, " (must REVISE <" as *u8); wn(fd, WHL_KEEP)
64 wp(fd, ") strong=" as *u8); wn(fd, ps); wp(fd, " (must KEEP >=" as *u8); wn(fd, WHL_KEEP); wp(fd, ")\n" as *u8)
65 if ok == 1 {
66 wp(fd, "WRITEHUB-LOOP GREEN (immune-scored keep/discard discriminates; revise-directive emitted; ready to wrap the seat)\n" as *u8)
67 if fd > 0 { sys_close(fd) }
68 sys_exit(0); return 0
69 }
70 wp(fd, "WRITEHUB-LOOP RED (discriminator failed -- tune the rubric)\n" as *u8)
71 if fd > 0 { sys_close(fd) }
72 sys_exit(1); return 1
73}