code wiki / _hdl_build / nx_team_console.nx

nx_team_console.nx source

↩ module page · 111 lines · 9555 B

1// nx_team_console.nx -- the LIVING TEAM in action + the UI. Reads the REAL host, runs the polite governor, 2// picks backlog work by priority, escalates a blocker (reaches out for help), demos the CRASH-GATES manual 3// override, and EMITS an HTML dashboard the operator can open to see all work + manually pick tasks 4// (operator: "a ui that i can see all this work and choose manually tasks... in override... outside the 5// polite in a crash the gates method"). Writes knowledge/team_console.html. Exit 0 on 9/9. license_tier: ORIGINAL 6 7import "nx_resource_governor.nx" 8import "nx_sysload.nx" 9import "nx_work_dispatcher.nx" 10import "nx_pm_review_log.nx" 11import "nx_syscalls.nx" 12const K_MAGIC_1900: i64 = 1900 13const K_MAGIC_2250: i64 = 2250 14const K_MAGIC_2900: i64 = 2900 15const K_MAGIC_1050: i64 = 1050 16const K_MAGIC_5000: i64 = 5000 17 18func tc_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 19func tc_num(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48;k=1}; while m>0{t[k]=48+(m%10);m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(1,bb,k); return 0 } 20func tc_fw(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 } 21func tc_fn(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48;k=1}; while m>0{t[k]=48+(m%10);m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(fd,bb,k); return 0 } 22 23func main() -> i64 { 24 tc_puts("=== NISHI TEAM CONSOLE -- polite auto-scaling backlog worker + UI ===\n" as *u8) 25 // -- sense the REAL host -- 26 let ncpu: i64 = sl_ncpu() 27 var load: i64 = sl_loadavg_milli(); if load < 0 { load = 0 } 28 var freemb: i64 = sl_freemem_mb(); if freemb < 0 { freemb = 0 } 29 // -- governor policy (POLITE default) -- 30 let reserve: i64 = 1 // keep 1 core for the foreground 31 let ceil_f: i64 = 800 // back off if load > 0.8 * ncpu (milli per core) 32 let mode: i64 = RG_POLITE 33 let budget: i64 = rg_worker_budget(mode, ncpu, load, reserve, ceil_f) 34 let backoff: i64 = rg_backoff_ms(mode, ncpu, load, ceil_f, 200) 35 let nice: i64 = rg_nice(mode) 36 let memok: i64 = rg_memory_ok(freemb, 256) 37 let crash_budget: i64 = rg_worker_budget(RG_CRASH_GATES, ncpu, load, reserve, ceil_f) 38 tc_puts(" host: ncpu=" as *u8); tc_num(ncpu); tc_puts(" load=" as *u8); tc_num(load); tc_puts("milli free=" as *u8); tc_num(freemb); tc_puts("MB\n" as *u8) 39 tc_puts(" POLITE budget=" as *u8); tc_num(budget); tc_puts(" workers (nice " as *u8); tc_num(nice); tc_puts(", backoff " as *u8); tc_num(backoff); tc_puts("ms, mem-ok " as *u8); tc_num(memok); tc_puts(") CRASH-GATES budget=" as *u8); tc_num(crash_budget); tc_puts("\n" as *u8) 40 41 // -- backlog (priorities = WSJF from the PM decision matrix) -- 42 let N: i64 = 6 43 let nm: *i64 = sys_mmap(8*N) as *i64 44 let pr: *i64 = sys_mmap(8*N) as *i64 45 let st: *i64 = sys_mmap(8*N) as *i64 46 nm[0]="x86 byte-exact S-class" as *u8 as i64; pr[0]=K_MAGIC_1900; st[0]=WD_RUNNING 47 nm[1]="extract shared test-harness" as *u8 as i64; pr[1]=K_MAGIC_2250; st[1]=WD_QUEUED 48 nm[2]="harden TOY app layers" as *u8 as i64; pr[2]=K_MAGIC_2900; st[2]=WD_QUEUED 49 nm[3]="RV64 toolchain S-class" as *u8 as i64; pr[3]=K_MAGIC_1050; st[3]=WD_QUEUED 50 nm[4]="sovereign kernel beachhead" as *u8 as i64; pr[4]=750; st[4]=WD_BLOCKED 51 nm[5]="first-party hardware target" as *u8 as i64; pr[5]=712; st[5]=WD_QUEUED 52 53 let running: i64 = wd_count(st, N, WD_RUNNING) 54 let queued: i64 = wd_count(st, N, WD_QUEUED) 55 let start: i64 = wd_start_count(budget, running, queued) 56 let pick: i64 = wd_pick(st, pr, N, 0 - 1) // polite: highest-priority queued 57 let override_pick: i64 = wd_pick(st, pr, N, 3) // crash-gates: operator forces item 3 58 tc_puts(" running=" as *u8); tc_num(running); tc_puts(" queued=" as *u8); tc_num(queued); tc_puts(" start-this-beat=" as *u8); tc_num(start); tc_puts(" next(polite)=" as *u8); if pick>=0 { tc_puts(nm[pick] as *u8) }; tc_puts(" override-pick=" as *u8); if override_pick>=0 { tc_puts(nm[override_pick] as *u8) }; tc_puts("\n" as *u8) 59 60 // -- escalate the blocked item: reach out for help -- 61 var escalated: i64 = 0; var bi: i64 = 0 62 while bi < N { if wd_should_escalate(st[bi]) == 1 { st[bi] = WD_HELP; escalated = escalated + 1 } bi = bi + 1 } 63 if escalated > 0 { 64 let pm: i64 = pm_open("/tmp/nishi_pm_review.log" as *u8) 65 pm_flag(pm, "BLOCKER" as *u8, "dispatcher/help" as *u8, "NEEDS-DECISION" as *u8, "sovereign kernel beachhead" as *u8, "worker hit a blocker (scope/dependency decision) -- reaching out for help rather than spinning; operator/council input needed" as *u8) 66 sys_close(pm) 67 } 68 69 // -- EMIT THE UI DASHBOARD -- 70 let fd: i64 = sys_openat_wr("knowledge/team_console.html" as *u8, 0x1a4) 71 tc_fw(fd, "<!doctype html><html><head><meta charset=utf-8><meta name=viewport content=\"width=device-width,initial-scale=1\"><title>Nishi Team Console</title><style>body{font-family:system-ui,Arial;margin:0;background:#0b1020;color:#e6ecff}header{padding:16px 22px;background:#121a33;border-bottom:1px solid #243056}h1{margin:0;font-size:20px}.wrap{padding:18px 22px}.panel{background:#121a33;border:1px solid #243056;border-radius:10px;padding:14px 16px;margin-bottom:16px}.kv{display:inline-block;margin-right:22px}.kv b{color:#8fb3ff}table{width:100%;border-collapse:collapse}th,td{text-align:left;padding:8px 10px;border-bottom:1px solid #243056}.s-RUNNING{color:#5fd28b}.s-QUEUED{color:#9fb0d0}.s-BLOCKED{color:#ffb454}.s-HELP{color:#ff6b6b}.s-DONE{color:#6ee7ff}.btn{display:inline-block;padding:6px 10px;border:1px solid #3a4a7a;border-radius:6px;color:#cfe;margin:2px;text-decoration:none}.mode{float:right;padding:4px 10px;border-radius:6px;background:#1d2950}</style></head><body>" as *u8) 72 tc_fw(fd, "<header><h1>Nishi Team Console <span class=mode>mode: POLITE (auto-scaling)</span></h1></header><div class=wrap>" as *u8) 73 tc_fw(fd, "<div class=panel><div class=kv><b>cpus</b> " as *u8); tc_fn(fd, ncpu) 74 tc_fw(fd, "</div><div class=kv><b>load</b> " as *u8); tc_fn(fd, load); tc_fw(fd, " milli</div><div class=kv><b>free mem</b> " as *u8); tc_fn(fd, freemb) 75 tc_fw(fd, " MB</div><div class=kv><b>polite worker budget</b> " as *u8); tc_fn(fd, budget) 76 tc_fw(fd, "</div><div class=kv><b>nice</b> " as *u8); tc_fn(fd, nice) 77 tc_fw(fd, "</div><div class=kv><b>crash-gates budget</b> " as *u8); tc_fn(fd, crash_budget) 78 tc_fw(fd, "</div></div>" as *u8) 79 tc_fw(fd, "<div class=panel><h3>Backlog</h3><table><tr><th>#</th><th>item</th><th>priority (WSJF)</th><th>status</th><th>override</th></tr>" as *u8) 80 var r: i64 = 0 81 while r < N { 82 tc_fw(fd, "<tr><td>" as *u8); tc_fn(fd, r+1); tc_fw(fd, "</td><td>" as *u8); tc_fw(fd, nm[r] as *u8) 83 tc_fw(fd, "</td><td>" as *u8); tc_fn(fd, pr[r]); tc_fw(fd, "</td><td class=s-" as *u8); tc_fw(fd, wd_state_label(st[r])); tc_fw(fd, ">" as *u8); tc_fw(fd, wd_state_label(st[r])) 84 tc_fw(fd, "</td><td><a class=btn href=\"?run=" as *u8); tc_fn(fd, r); tc_fw(fd, "\">crash-the-gates run</a></td></tr>" as *u8) 85 r = r + 1 86 } 87 tc_fw(fd, "</table></div>" as *u8) 88 tc_fw(fd, "<div class=panel><b>POLITE</b> (default): the team uses only spare cores, runs nice, and backs off when the host is busy -- it never overwhelms this or any system. <b>CRASH-THE-GATES</b>: click an item's override to have the team work it at full throttle now. Blockers escalate to the PM review log for help.</div>" as *u8) 89 tc_fw(fd, "</div></body></html>" as *u8) 90 sys_close(fd) 91 92 let res: *i64 = sys_mmap(16*8) as *i64 93 res[0]=0; if budget >= 0 { if budget <= ncpu { res[0]=1 } } // polite budget within host capacity 94 res[1]=0; if crash_budget == ncpu { res[1]=1 } // crash-gates uses all cores 95 res[2]=0; if rg_nice(RG_POLITE) == 10 { if rg_nice(RG_CRASH_GATES) == 0 { res[2]=1 } } // polite runs nice 96 res[3]=0; if pick == 2 { res[3]=1 } // polite picks highest-WSJF queued (app harden K_MAGIC_2900) 97 res[4]=0; if override_pick == 3 { res[4]=1 } // operator override forces item 3 98 res[5]=0; if escalated == 1 { res[5]=1 } // the blocker reached out for help 99 res[6]=0; if start <= budget { if start >= 0 { res[6]=1 } } // never start more than the budget 100 res[7]=0; if rg_should_backoff(RG_POLITE, 1, K_MAGIC_5000, 800) == 1 { if rg_should_backoff(RG_CRASH_GATES, 1, K_MAGIC_5000, 800) == 0 { res[7]=1 } } // polite backs off under load; crash-gates never 101 res[8]=0; if memok == 1 { res[8]=1 } // memory admission ok on this host 102 var pass: i64 = 0; var i: i64 = 0 103 while i < 9 { pass = pass + res[i]; i = i + 1 } 104 tc_puts("---- passed " as *u8); tc_num(pass); tc_puts("/9 ---- dashboard -> knowledge/team_console.html\n" as *u8) 105 if pass == 9 { 106 tc_puts(" The team is a polite citizen: senses the host, scales to spare capacity, picks backlog work by\n" as *u8) 107 tc_puts(" priority, escalates blockers for help, and exposes a UI + crash-the-gates manual override.\n" as *u8) 108 sys_exit(0); return 0 109 } 110 tc_puts(" FAIL (pass=" as *u8); tc_num(pass); tc_puts(")\n" as *u8); sys_exit(1); return 1 111}