code wiki / (root) / nx_substrate_review.nx

nx_substrate_review.nx source

↩ module page · 187 lines · 7471 B

1// nx_substrate_review.nx -- read-only review of the proposal queue. 2// 3// Reads specs/proposed_changes.jsonl via sys_read; counts proposals 4// by (kind, status); prints a human-readable summary. Never edits 5// the file, never approves anything -- approval is human-only per 6// proposal workflow. 7// 8// Per user directive (use our write/read): pure NishiLang sys_read 9// + sys_write; no shell tools. 10// 11// Usage: 12// compile + run -> stdout summary 13// To approve a proposal: edit specs/proposed_changes.jsonl by hand 14// (change "status":"pending" -> "status":"approved" on the chosen line). 15 16// nx_safety_envelope: 17// intended_use: AUTO_APPLIED -- primitive-specific tuning queued 18// sil_target: SIL1 19// evidence: [bulk_applied_2026-05-16, see-file-comment-for-detail] 20// verdict: NOT_YET_EVALUATED 21 22import "nx_syscalls.nx" 23import "nx_runtime.nx" 24import "nx_tier.nx" 25 26const STDOUT: i64 = 1 27 28// One-line substring check against a fixed needle. 29func has_substr(line: *u8, line_len: nx_size, needle: *u8) -> nx_int { 30 let nlen: nx_size = strlen(needle) 31 if nlen > line_len { return 0 } 32 var i: nx_idx = 0 33 let last: nx_idx = line_len - nlen 34 while i <= last { 35 var j: nx_idx = 0 36 var hit: nx_int = 1 37 while j < nlen { 38 if line[i + j] != needle[j] { hit = 0; j = nlen } 39 j = j + 1 40 } 41 if hit == 1 { return 1 } 42 i = i + 1 43 } 44 return 0 45} 46 47// Counters: pending/approved/rejected per kind. Six kinds tracked. 48struct ReviewCounts { 49 card_pending: nx_int, 50 card_approved: nx_int, 51 card_rejected: nx_int, 52 rework_pending: nx_int, 53 rework_approved: nx_int, 54 rework_rejected: nx_int, 55 ingest_pending: nx_int, 56 ingest_approved: nx_int, 57 ingest_rejected: nx_int, 58 explore_pending: nx_int, 59 explore_approved: nx_int, 60 explore_rejected: nx_int, 61 consolidate_pending: nx_int, 62 consolidate_approved: nx_int, 63 consolidate_rejected: nx_int, 64 delete_pending: nx_int, 65 delete_approved: nx_int, 66 delete_rejected: nx_int, 67} 68 69func review_one(line: *u8, line_len: nx_size, c: *ReviewCounts) -> i64 { 70 let is_card: nx_int = has_substr(line, line_len, "\"kind\":\"CARD\"" as *u8) 71 let is_rework: nx_int = has_substr(line, line_len, "\"kind\":\"REWORK\"" as *u8) 72 let is_ingest: nx_int = has_substr(line, line_len, "\"kind\":\"INGEST\"" as *u8) 73 let is_explore: nx_int = has_substr(line, line_len, "\"kind\":\"EXPLORE\"" as *u8) 74 let is_consol: nx_int = has_substr(line, line_len, "\"kind\":\"CONSOLIDATE_CANDIDATE\"" as *u8) 75 let is_delete: nx_int = has_substr(line, line_len, "\"kind\":\"DELETE\"" as *u8) 76 77 let is_pending: nx_int = has_substr(line, line_len, "\"status\":\"pending\"" as *u8) 78 let is_approved: nx_int = has_substr(line, line_len, "\"status\":\"approved\"" as *u8) 79 let is_rejected: nx_int = has_substr(line, line_len, "\"status\":\"rejected\"" as *u8) 80 81 if is_card == 1 { 82 if is_pending == 1 { c.card_pending = c.card_pending + 1 } 83 if is_approved == 1 { c.card_approved = c.card_approved + 1 } 84 if is_rejected == 1 { c.card_rejected = c.card_rejected + 1 } 85 } 86 if is_rework == 1 { 87 if is_pending == 1 { c.rework_pending = c.rework_pending + 1 } 88 if is_approved == 1 { c.rework_approved = c.rework_approved + 1 } 89 if is_rejected == 1 { c.rework_rejected = c.rework_rejected + 1 } 90 } 91 if is_ingest == 1 { 92 if is_pending == 1 { c.ingest_pending = c.ingest_pending + 1 } 93 if is_approved == 1 { c.ingest_approved = c.ingest_approved + 1 } 94 if is_rejected == 1 { c.ingest_rejected = c.ingest_rejected + 1 } 95 } 96 if is_explore == 1 { 97 if is_pending == 1 { c.explore_pending = c.explore_pending + 1 } 98 if is_approved == 1 { c.explore_approved = c.explore_approved + 1 } 99 if is_rejected == 1 { c.explore_rejected = c.explore_rejected + 1 } 100 } 101 if is_consol == 1 { 102 if is_pending == 1 { c.consolidate_pending = c.consolidate_pending + 1 } 103 if is_approved == 1 { c.consolidate_approved = c.consolidate_approved + 1 } 104 if is_rejected == 1 { c.consolidate_rejected = c.consolidate_rejected + 1 } 105 } 106 if is_delete == 1 { 107 if is_pending == 1 { c.delete_pending = c.delete_pending + 1 } 108 if is_approved == 1 { c.delete_approved = c.delete_approved + 1 } 109 if is_rejected == 1 { c.delete_rejected = c.delete_rejected + 1 } 110 } 111 return 0 112} 113 114func print_row(label: *u8, p: nx_int, a: nx_int, r: nx_int) -> i64 { 115 print(" " as *u8) 116 print(label) 117 print(" pending=" as *u8) 118 print_i64(p) 119 print(" approved=" as *u8) 120 print_i64(a) 121 print(" rejected=" as *u8) 122 print_i64(r) 123 println("" as *u8) 124 return 0 125} 126 127func main() -> i64 { 128 let path: *u8 = "nxc2/specs/proposed_changes.jsonl" as *u8 129 let out_len: *i64 = (sys_mmap(8)) as *i64 130 out_len[0] = 0 131 let buf: *u8 = sys_read_file(path, out_len) 132 if (buf as i64) == 0 { 133 let err: *u8 = "error: cannot read specs/proposed_changes.jsonl\n" as *u8 134 sys_write(STDOUT, err, strlen(err)) 135 return 1 136 } 137 let total: nx_size = out_len[0] 138 139 let c_raw: *u8 = sys_mmap(160) 140 let c: *ReviewCounts = c_raw as *ReviewCounts 141 142 var pos: nx_idx = 0 143 var n_lines: nx_int = 0 144 while pos < total { 145 var eol: nx_idx = pos 146 var done: nx_int = 0 147 while done == 0 { 148 if eol >= total { done = 1 } 149 if done == 0 { 150 if buf[eol] == 10 { done = 1 } 151 if done == 0 { eol = eol + 1 } 152 } 153 } 154 let llen: nx_size = eol - pos 155 if llen > 0 { 156 let lp: *u8 = ((buf as i64) + pos) as *u8 157 review_one(lp, llen, c) 158 n_lines = n_lines + 1 159 } 160 pos = eol + 1 161 } 162 163 println("===== Substrate Proposal Review =====" as *u8) 164 print("Total entries: " as *u8) 165 print_i64(n_lines) 166 println("" as *u8) 167 println("" as *u8) 168 println("By kind (pending / approved / rejected):" as *u8) 169 print_row("CARD " as *u8, c.card_pending, c.card_approved, c.card_rejected) 170 print_row("REWORK " as *u8, c.rework_pending, c.rework_approved, c.rework_rejected) 171 print_row("INGEST " as *u8, c.ingest_pending, c.ingest_approved, c.ingest_rejected) 172 print_row("EXPLORE " as *u8, c.explore_pending, c.explore_approved, c.explore_rejected) 173 print_row("CONSOLIDATE_CANDIDATE " as *u8, c.consolidate_pending, c.consolidate_approved, c.consolidate_rejected) 174 print_row("DELETE " as *u8, c.delete_pending, c.delete_approved, c.delete_rejected) 175 println("" as *u8) 176 177 let total_pending: nx_int = c.card_pending + c.rework_pending + c.ingest_pending + 178 c.explore_pending + c.consolidate_pending + c.delete_pending 179 print("Pending requiring human review: " as *u8) 180 print_i64(total_pending) 181 println("" as *u8) 182 println("" as *u8) 183 println("To approve: edit specs/proposed_changes.jsonl;" as *u8) 184 println("change \"status\":\"pending\" -> \"status\":\"approved\" on chosen lines." as *u8) 185 println("Per growing-equilibrium-no-deletion: DELETE proposals require explicit human approval." as *u8) 186 return 0 187}