code wiki / _hdl_build / nx_nishi_deploy.nx

nx_nishi_deploy.nx source

↩ module page · 143 lines · 7586 B

1// nx_nishi_deploy.nx -- SOVEREIGN deploy organ (operator 2026-06-23: "no sh, use the nishi ecosystem, 2// 100% true nishi capabilities"). Replaces the bash deploy scripts: reads a manifest of repo-relative 3// files (knowledge/deploy/manifest.txt) + a commit message (knowledge/deploy/msg.txt), then does a 4// PLUMBING commit (write-tree -> commit-tree -> update-ref, which avoids the /mnt/c index-refresh hang 5// AND the pre-commit-hook stall) + push to Gitea -- entirely as NishiLang orchestration. git is the 6// flagged BORROWED ORACLE (named replacement = the sovereign pack/push lane, per nx_ark_push); the 7// orchestration + verdict are fully sovereign. SHAs are captured by redirecting the child's stdout to a 8// file (no pipe int32 fiddling) + reading it back. license_tier: ORIGINAL 9import "nx_syscalls.nx" 10 11const C_GIT: *u8 = "/usr/bin/git" 12const C_REPO: *u8 = "/mnt/c/Users/elder/nishi-core" 13const C_BRANCH: *u8 = "agents/invention-engine" 14const C_REF: *u8 = "refs/heads/agents/invention-engine" 15const C_MANIFEST: *u8 = "knowledge/deploy/manifest.txt" 16const C_MSGFILE: *u8 = "knowledge/deploy/msg.txt" 17const F_TREE: *u8 = "/tmp/nxd_tree" 18const F_HEAD: *u8 = "/tmp/nxd_head" 19const F_COMMIT: *u8 = "/tmp/nxd_commit" 20const C_LOCK: *u8 = "/mnt/c/Users/elder/nishi-core/.git/index.lock" 21const AT_FDCWD: i64 = 0 - 100 22const MODE: i64 = 420 23 24func dw(s: *u8) -> i64 { var n: i64=0; while s[n]!=0 as u8 { n=n+1 } sys_write(1,s,n); return 0 } 25func dn(v: i64) -> i64 { if v==0 { sys_write(1,"0" as *u8,1); return 0 } let bb: *u8=sys_mmap(28); var m: i64=v; var k: i64=0; let t: *u8=sys_mmap(28); while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var z: i64=0; while z<k{bb[z]=t[k-1-z];z=z+1} sys_write(1,bb,k); return 0 } 26 27// child env: git needs PATH + HOME; GIT_TERMINAL_PROMPT=0 = never block on a prompt. 28func mk_env() -> *i64 { 29 let e: *i64 = sys_mmap(64) as *i64 30 e[0] = "PATH=/usr/bin:/bin:/usr/local/bin" as i64 31 e[1] = "HOME=/home/elderwesto" as i64 32 e[2] = "GIT_TERMINAL_PROMPT=0" as i64 33 e[3] = 0 34 return e 35} 36// run argv, stdin<-/dev/null, stdout+stderr muted; returns WEXITSTATUS. 37func run(argv: *i64) -> i64 { 38 let pid: i64 = sys_fork() 39 if pid == 0 { 40 let dnr: i64 = sys_openat_rd("/dev/null" as *u8); if dnr>=0 { sys_dup3(dnr,0,0) } 41 let dnw: i64 = sys_openat_wr("/dev/null" as *u8, MODE); if dnw>=0 { sys_dup3(dnw,1,0); sys_dup3(dnw,2,0) } 42 sys_execve(argv[0] as *u8, argv, mk_env()) 43 sys_exit(127) 44 } 45 let st: *i64 = sys_mmap(16) as *i64 46 sys_wait4(pid, st, 0) 47 return (st[0] >> 8) & 0xff 48} 49// run argv with stdout -> outfile (capture); stderr muted; stdin /dev/null. returns WEXITSTATUS. 50func run_to_file(argv: *i64, outfile: *u8) -> i64 { 51 let pid: i64 = sys_fork() 52 if pid == 0 { 53 let dnr: i64 = sys_openat_rd("/dev/null" as *u8); if dnr>=0 { sys_dup3(dnr,0,0) } 54 let of: i64 = sys_openat_wr(outfile, MODE); if of>=0 { sys_dup3(of,1,0) } 55 let dnw: i64 = sys_openat_wr("/dev/null" as *u8, MODE); if dnw>=0 { sys_dup3(dnw,2,0) } 56 sys_execve(argv[0] as *u8, argv, mk_env()) 57 sys_exit(127) 58 } 59 let st: *i64 = sys_mmap(16) as *i64 60 sys_wait4(pid, st, 0) 61 return (st[0] >> 8) & 0xff 62} 63// read a captured sha file, NUL-terminate at the first newline/space -> usable as an argv string. 64func read_sha(path: *u8) -> *u8 { 65 let lb: *i64 = sys_mmap(8) as *i64 66 let b: *u8 = sys_read_file(path, lb) 67 if (b as i64) == 0 { return 0 as *u8 } 68 let n: i64 = lb[0] 69 if n == 0 { return 0 as *u8 } 70 var i: i64 = 0 71 while i < n { let c: i64 = b[i] as i64; if c == 10 { b[i]=0 as u8; i=n } else { if c == 32 { b[i]=0 as u8; i=n } else { i=i+1 } } } 72 return b 73} 74 75func main() -> i64 { 76 dw("=== nx_nishi_deploy -- sovereign plumbing commit + push (no .sh; git = flagged borrowed oracle) ===\n") 77 // clear any stale .git/index.lock (a killed prior git leaves one, which blocks add/write-tree) 78 __syscall(263, AT_FDCWD, C_LOCK, 0, 0, 0, 0) 79 // 1. read the manifest, NUL-terminate each line, collect path pointers into the git-add argv. 80 let lb: *i64 = sys_mmap(8) as *i64 81 let man: *u8 = sys_read_file(C_MANIFEST, lb) 82 if (man as i64) == 0 { dw(" FATAL: no knowledge/deploy/manifest.txt\n"); sys_exit(1); return 1 } 83 let mn: i64 = lb[0] 84 let argv: *i64 = sys_mmap(8 * 256) as *i64 85 let a1: *u8 = "-C" as *u8; let a3: *u8 = "add" as *u8 86 argv[0]=C_GIT as i64; argv[1]=a1 as i64; argv[2]=C_REPO as i64; argv[3]=a3 as i64 87 var cnt: i64 = 4 88 var i: i64 = 0; var ls: i64 = 0; var inl: i64 = 0 89 while i < mn { 90 let c: i64 = man[i] as i64 91 if c == 10 { man[i]=0 as u8; if inl==1 { argv[cnt]=(man as i64 + ls); cnt=cnt+1; inl=0 } } else { if inl==0 { ls=i; inl=1 } } 92 i = i + 1 93 } 94 if inl==1 { argv[cnt]=(man as i64 + ls); cnt=cnt+1 } 95 argv[cnt]=0 96 dw(" manifest: "); dn(cnt-4); dw(" files -> git add\n") 97 let add_rc: i64 = run(argv) 98 if add_rc != 0 { dw(" WARN: git add returned nonzero (some paths may be unchanged)\n") } 99 100 // 2. write-tree -> tree sha 101 let wt: *i64 = sys_mmap(64) as *i64 102 wt[0]=C_GIT as i64; wt[1]=a1 as i64; wt[2]=C_REPO as i64; wt[3]=("write-tree" as *u8) as i64; wt[4]=0 103 run_to_file(wt, F_TREE) 104 let tree: *u8 = read_sha(F_TREE) 105 if (tree as i64)==0 { dw(" FATAL: write-tree produced no sha\n"); sys_exit(1); return 1 } 106 dw(" tree="); dw(tree); dw("\n") 107 108 // 3. rev-parse HEAD -> parent sha 109 let rp: *i64 = sys_mmap(64) as *i64 110 rp[0]=C_GIT as i64; rp[1]=a1 as i64; rp[2]=C_REPO as i64; rp[3]=("rev-parse" as *u8) as i64; rp[4]=("HEAD" as *u8) as i64; rp[5]=0 111 run_to_file(rp, F_HEAD) 112 let head: *u8 = read_sha(F_HEAD) 113 if (head as i64)==0 { dw(" FATAL: rev-parse HEAD produced no sha\n"); sys_exit(1); return 1 } 114 115 // 4. read the commit message 116 let msg: *u8 = sys_read_file(C_MSGFILE, lb) 117 if (msg as i64)==0 { dw(" FATAL: no knowledge/deploy/msg.txt\n"); sys_exit(1); return 1 } 118 let msgn: i64 = lb[0] 119 var mi: i64 = msgn; while mi>0 { if msg[mi-1]==10 as u8 { msg[mi-1]=0 as u8; mi=mi-1 } else { mi=0 } } // trim trailing newlines (NUL them) 120 121 // 5. commit-tree -m <msg> <tree> -p <head> -> commit sha 122 let ct: *i64 = sys_mmap(64) as *i64 123 ct[0]=C_GIT as i64; ct[1]=a1 as i64; ct[2]=C_REPO as i64; ct[3]=("commit-tree" as *u8) as i64 124 ct[4]=("-m" as *u8) as i64; ct[5]=msg as i64; ct[6]=tree as i64; ct[7]=("-p" as *u8) as i64; ct[8]=head as i64; ct[9]=0 125 run_to_file(ct, F_COMMIT) 126 let commit: *u8 = read_sha(F_COMMIT) 127 if (commit as i64)==0 { dw(" FATAL: commit-tree produced no sha\n"); sys_exit(1); return 1 } 128 dw(" commit="); dw(commit); dw("\n") 129 130 // 6. update-ref (advance the branch to the new commit) 131 let ur: *i64 = sys_mmap(64) as *i64 132 ur[0]=C_GIT as i64; ur[1]=a1 as i64; ur[2]=C_REPO as i64; ur[3]=("update-ref" as *u8) as i64; ur[4]=C_REF as i64; ur[5]=commit as i64; ur[6]=0 133 let ur_rc: i64 = run(ur) 134 if ur_rc != 0 { dw(" FATAL: update-ref failed\n"); sys_exit(1); return 1 } 135 136 // 7. push to Gitea 137 let pu: *i64 = sys_mmap(64) as *i64 138 pu[0]=C_GIT as i64; pu[1]=a1 as i64; pu[2]=C_REPO as i64; pu[3]=("push" as *u8) as i64; pu[4]=("-q" as *u8) as i64; pu[5]=("origin" as *u8) as i64; pu[6]=C_BRANCH as i64; pu[7]=0 139 let push_rc: i64 = run(pu) 140 dw(" git push rc="); dn(push_rc); dw("\n") 141 if push_rc == 0 { dw("VERDICT: GREEN (sovereign deploy: committed + pushed to the team, no .sh)\n"); sys_exit(0); return 0 } 142 dw("VERDICT: RED (push failed -- commit is local-only)\n"); sys_exit(1); return 1 143}