code wiki / _hdl_build / nx_self_heal_conductor.nx

nx_self_heal_conductor.nx source

↩ module page · 62 lines · 3489 B

1// nx_self_heal_conductor.nx -- the CONDUCTOR's autonomous self-heal BEAT. The Conductor 2// ORCHESTRATES the organs into one Warden-gated tick; it does NOT itself fix, verify, or 3// admit (RACI stays clean). One beat: 4// WARDEN gate the I/O -- candidate must be an additive CREATE; the original source 5// MUST be overwrite-DENIED (the protection we rely on) 6// ENGINEER detect+capture -- eng_compile_diag finds the failure + its diagnostic 7// DOCTOR diagnose+fix -- learns the token, writes the healed CANDIDATE (new file) 8// ENGINEER verify -- eng_compile re-verifies the candidate (separate organ) 9// COUNCIL admit -- cc_council ACTs only on the Engineer's verdict + Warden safety 10// The healed candidate is ALWAYS a new additive path; the protected .nx source is never 11// clobbered. This is the callable unit the live autonomous tick drives. license_tier: ORIGINAL 12 13import "nx_engineer_crash.nx" // ENGINEER (detect + capture + re-verify) 14import "nx_doctor_fix.nx" // DOCTOR (diagnose-from-artifact + apply) 15import "nx_warden_paths.nx" // WARDEN (additive-safe, protected-path) 16import "nx_crew_council.nx" // COUNCIL (3->2->1 govern) 17 18const COND_CLEAN: i64 = 100 // original already compiles -- nothing to heal 19const COND_UNFIXABLE: i64 = 101 // failed, but not a class the Doctor fixes -> give up 20 21// out[] sub-verdicts: [0]=needed_heal [1]=token_found [2]=verified 22// [3]=candidate_additive_safe [4]=source_overwrite_denied 23// returns COND_CLEAN / COND_UNFIXABLE / a council verdict (CC_ACT/CC_ESCALATE/CC_DENY). 24func cond_heal_beat(compiler: *u8, orig: *u8, candidate: *u8, out: *i64) -> i64 { 25 out[0] = 0; out[1] = 0; out[2] = 0; out[3] = 0; out[4] = 0 26 let tok: *u8 = sys_mmap(64) 27 28 // WARDEN: candidate write must be additive (CREATE), and overwriting the source DENIED. 29 if nx_warden_path_safe(WP_CREATE, candidate) == WP_SAFE { out[3] = 1 } 30 if nx_warden_path_safe(WP_OVERWRITE, orig) == WP_DENY { out[4] = 1 } 31 32 // ENGINEER detect (+ capture the diagnostic artifact) 33 let rc_bad: i64 = eng_compile_diag(compiler, orig, "/tmp/cond.s" as *u8, "/tmp/cond.err" as *u8) 34 if rc_bad >= 0 { return COND_CLEAN } // already compiles -> nothing to heal 35 out[0] = 1 36 37 // DOCTOR learn the offending token from the Engineer's diagnostic 38 let tlen: i64 = doc_offending_kw("/tmp/cond.err" as *u8, tok) 39 if tlen <= 0 { return COND_UNFIXABLE } // graceful give-up: not a class we fix 40 out[1] = 1 41 42 // DOCTOR heal into the additive CANDIDATE (never the protected original) 43 doc_heal_token(orig, candidate, tok) 44 45 // ENGINEER re-verify the candidate (separate organ -- the fixer does not bless its work) 46 let rc_heal: i64 = eng_compile(compiler, candidate, "/tmp/cond2.s" as *u8) 47 if rc_heal == 0 { out[2] = 1 } 48 49 // COUNCIL admit -- on the Engineer's verdict AND the Warden's additive safety, nothing else. 50 let a: *CrewAction = sys_mmap(64) as *CrewAction 51 let why: *i64 = sys_mmap(8) as *i64 52 var safe: i64 = 0 53 if out[3] == 1 { if out[4] == 1 { safe = 1 } } 54 cc_set(a, "admit Warden-gated self-heal candidate" as *u8, out[2], 1, 1, safe, 1) 55 return cc_council(a, why) 56} 57 58func cond_beat_name(v: i64) -> *u8 { 59 if v == COND_CLEAN { return "CLEAN (nothing to heal)" as *u8 } 60 if v == COND_UNFIXABLE { return "UNFIXABLE (Doctor gave up)" as *u8 } 61 return cc_verdict_name(v) 62}