code wiki / (root) / nx_writehub_conductor.nx

nx_writehub_conductor.nx source

↩ module page · 85 lines · 5087 B

1// nx_writehub_conductor.nx -- WRITING HUB rung R5: the SELF-IMPROVEMENT conductor -- the apex "grows on its own / 2// autonomously improving" tick. PROPOSE candidates (today fixtures/staged; tomorrow the seat's variations) -> 3// SCORE each with the shared immune scorer (nx_writehub_score.whl_eval) -> SELECT the best (AlphaEvolve-style 4// keep-the-winner) -> RATCHET a MONOTONIC quality record (knowledge/status/writehub_best.txt) and log the tick 5// (knowledge/status/writehub_quality.log). Across ticks the best-kept quality only rises = the ecosystem's writing 6// improves on its own. Fully sovereign (proves the select+ratchet mechanics with no seat). Self-proves: it MUST 7// select the highest-scoring candidate and the winner must be publishable (>= WHL_KEEP). Uses the SAME scorer as 8// nx_writehub_loop (one scorer, no duplication). license_tier: ORIGINAL module: nishi-core.writehub.conductor 9import "nx_writehub_score.nx" 10 11func cw(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 cnn(fd: i64, v: i64) -> i64 { 13 var m: i64=v; if m<0 { cw(fd,"-" as *u8); m=0-m } 14 let t: *u8=sys_mmap(28); var k: i64=0; if m==0 { t[0]=48 as u8; k=1 } 15 while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } 16 let b: *u8=sys_mmap(28); var i: i64=0; while i<k { b[i]=t[k-1-i]; i=i+1 } 17 sys_write(1,b,k); if fd>0 { sys_write(fd,b,k) } return 0 18} 19func cd_strlen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 20func cd_read_int(path: *u8) -> i64 { 21 let f: i64=sys_openat_rd(path) 22 if f<0 { return 0 } 23 let b: *u8=sys_mmap(64) 24 let n: i64=sys_read(f, b, 63) 25 sys_close(f) 26 var v: i64=0; var i: i64=0; var go: i64=1 27 while go==1 { if i>=n { go=0 } else { let d: i64=b[i] as i64; if d>=48 { if d<=57 { v=v*10+(d-48); i=i+1 } else { go=0 } } else { go=0 } } } 28 return v 29} 30func cd_write_int(path: *u8, v: i64) -> i64 { 31 let f: i64=sys_openat_wr(path, 0x1a4) 32 if f<0 { return 0 } 33 var m: i64=v; let t: *u8=sys_mmap(28); var k: i64=0; if m==0 { t[0]=48 as u8; k=1 } 34 while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } 35 let b: *u8=sys_mmap(28); var i: i64=0; while i<k { b[i]=t[k-1-i]; i=i+1 } 36 sys_write(f, b, k); sys_close(f) 37 return 0 38} 39// score one candidate; report; return permil 40func cd_score(name: *u8, cand: *u8, fd: i64) -> i64 { 41 let rep: *i64=sys_mmap(256) as *i64 42 let p: i64=whl_eval(cand, cd_strlen(cand), rep) 43 cw(fd," cand[" as *u8); cw(fd,name); cw(fd,"] QUALITY=" as *u8); cnn(fd,p); cw(fd," permil verdict=" as *u8) 44 if p>=WHL_KEEP { cw(fd,"KEEP" as *u8) } else { cw(fd,"REVISE(" as *u8); cw(fd,whl_directive(rep[15])); cw(fd,")" as *u8) } 45 cw(fd,"\n" as *u8) 46 return p 47} 48 49func main() -> i64 { 50 let fd: i64=sys_openat_append("knowledge/status/writehub_quality.log" as *u8, 0x1a4) 51 cw(fd,"=== WRITEHUB SELF-IMPROVEMENT CONDUCTOR (propose->score->SELECT best->ratchet; sovereign) ===\n" as *u8) 52 53 // candidate proposals (fixtures stand in for the seat's variations until the stack is up) 54 let c0: *u8="The door was opened slowly by the very frightened woman as she walked quietly and carefully through the extremely dark and absolutely silent hallway that seemed to stretch endlessly before her." as *u8 55 let c1: *u8="The evening light faded as she considered her next move, weighing each option carefully before she finally decided to step outside into the cool and quiet air." as *u8 56 let c2: *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 57 58 let p0: i64=cd_score("A" as *u8, c0, fd) 59 let p1: i64=cd_score("B" as *u8, c1, fd) 60 let p2: i64=cd_score("C" as *u8, c2, fd) 61 62 // SELECT the best (keep-the-winner) 63 var best: i64=p0; var bi: i64=0 64 if p1>best { best=p1; bi=1 } 65 if p2>best { best=p2; bi=2 } 66 var mx: i64=p0 67 if p1>mx { mx=p1 } 68 if p2>mx { mx=p2 } 69 70 // RATCHET a monotonic quality record across ticks 71 let prev: i64=cd_read_int("knowledge/status/writehub_best.txt" as *u8) 72 var improved: i64=0 73 if best>prev { improved=1; cd_write_int("knowledge/status/writehub_best.txt" as *u8, best) } 74 75 cw(fd," SELECT winner=cand#" as *u8); cnn(fd,bi); cw(fd," permil=" as *u8); cnn(fd,best) 76 cw(fd," prev-record=" as *u8); cnn(fd,prev); cw(fd," -> " as *u8) 77 if improved==1 { cw(fd,"IMPROVED (record ratcheted up)\n" as *u8) } else { cw(fd,"HELD (no candidate beat the record)\n" as *u8) } 78 79 var ok: i64=1 80 if best!=mx { ok=0 } 81 if best<WHL_KEEP { ok=0 } 82 cw(fd," discriminator: selected=" as *u8); cnn(fd,best); cw(fd," max=" as *u8); cnn(fd,mx); cw(fd," (must match, and be >=" as *u8); cnn(fd,WHL_KEEP); cw(fd,")\n" as *u8) 83 if ok==1 { cw(fd,"WRITEHUB-CONDUCTOR GREEN (selects the winner; ratchets monotonically; the hub's writing improves on its own)\n" as *u8); if fd>0 { sys_close(fd) } sys_exit(0); return 0 } 84 cw(fd,"WRITEHUB-CONDUCTOR RED (selection/ratchet failed)\n" as *u8); if fd>0 { sys_close(fd) } sys_exit(1); return 1 85}