code wiki / (root) / nx_captain_moroni_compose_test.nx

nx_captain_moroni_compose_test.nx source

↩ module page · 119 lines · 5663 B

1// nx_captain_moroni_compose_test.nx -- doctrine bound end-to-end. 2// 3// Per [[feedback-captain-moroni-doctrine]]: substrate refuses 4// offensive operations STRUCTURALLY, never policy. This demo 5// exercises all 5 Phase M1-M4 primitives together to prove the 6// doctrine is enforced from intent declaration down through every 7// offensive-pattern operation. 8 9import "nx_syscalls.nx" 10import "nx_tier.nx" 11import "nx_intent.nx" 12import "nx_battery_safety.nx" 13import "nx_transponder_quiescence.nx" 14import "nx_drone_doctrine.nx" 15import "nx_scam_detector.nx" 16 17func main() -> i64 { 18 // ===== Step 1: declare Defensive intent for the family cell ==== 19 let family_intent: nx_int = NX_INTENT_DEFENSIVE 20 if nx_intent_is_valid(family_intent) != 1 { return 1 } 21 22 // ===== Step 2: Creative-intent cell attempts COMMAND_BATTERY ==== 23 // This is what an attacker would do: declare benign Creative 24 // intent then attempt thermal-runaway. Substrate refuses 25 // STRUCTURALLY (not policy). 26 let env: *NxBatterySafetyEnvelope = nx_battery_safety_envelope_new( 27 1, 2000, 5000, 60000, 3000, 4200) 28 let log: *NxBatteryCommandLog = nx_battery_command_log_new(8) 29 let bad_battery: nx_int = nx_battery_validate_command(env, 30 NX_INTENT_CREATIVE, NX_BC_CHARGE, 1000, 3700, log, 1000) 31 if bad_battery != NX_BS_REFUSED_BAD_INTENT { return 2 } 32 33 // ===== Step 3: Defensive intent + safe command -- OK =========== 34 let ok_battery: nx_int = nx_battery_validate_command(env, 35 NX_INTENT_DEFENSIVE, NX_BC_CHARGE, 1500, 3700, log, 2000) 36 if ok_battery != NX_BS_OK { return 3 } 37 38 // ===== Step 4: Defensive intent but over-rate -- still refused == 39 // Captain Moroni: Defensive intent doesn't bypass safety 40 // ceilings. The ceilings are the substrate's invariants. 41 let over_rate: nx_int = nx_battery_validate_command(env, 42 NX_INTENT_DEFENSIVE, NX_BC_CHARGE, 9999, 3700, log, 3000) 43 if over_rate != NX_BS_REFUSED_RATE_CEILING { return 4 } 44 45 // ===== Step 5: Thermal-runaway pattern detection ============== 46 nx_battery_validate_command(env, NX_INTENT_DEFENSIVE, 47 NX_BC_THERMAL_TARGET, 30000, 0, log, 4000) 48 nx_battery_validate_command(env, NX_INTENT_DEFENSIVE, 49 NX_BC_THERMAL_TARGET, 40000, 0, log, 4100) 50 nx_battery_validate_command(env, NX_INTENT_DEFENSIVE, 51 NX_BC_THERMAL_TARGET, 50000, 0, log, 4200) 52 let runaway: nx_int = nx_battery_validate_command(env, 53 NX_INTENT_DEFENSIVE, NX_BC_THERMAL_TARGET, 58000, 0, log, 4300) 54 if runaway != NX_BS_REFUSED_THERMAL_RUNAWAY { return 5 } 55 56 // ===== Step 6: Transponder in SANCTUARY mode -- silent activation 57 // attempt refused (even Defensive intent without operator 58 // emergency_override) 59 let decl: *NxTransponderDeclaration = nx_transponder_decl_new( 60 100, NX_QM_SANCTUARY, 5000) 61 if nx_transponder_check_activation(decl, NX_INTENT_DEFENSIVE, 62 NX_TX_TR_CELLULAR) != NX_TX_REFUSED_QUIESCENCE { return 6 } 63 64 // ===== Step 7: Operator authorizes emergency -- now Defensive 65 // intent CELLULAR allowed (real emergency, twin-key in V2) 66 nx_transponder_authorize_emergency(decl) 67 if nx_transponder_check_activation(decl, NX_INTENT_DEFENSIVE, 68 NX_TX_TR_CELLULAR) != NX_TX_ALLOWED { return 7 } 69 // But not WiFi -- emergency override is scoped to cellular 70 // distress only at this level 71 if nx_transponder_check_activation(decl, NX_INTENT_DEFENSIVE, 72 NX_TX_TR_WIFI) != NX_TX_REFUSED_QUIESCENCE { return 8 } 73 74 // ===== Step 8: Drone purpose constrained to defensive set ===== 75 // Attempting to instantiate a session with Creative intent 76 // is structurally refused at construction. 77 let bad_drone: *NxDroneSession = nx_drone_session_new(7, 78 NX_DP_DEFENSIVE_FAMILY, NX_INTENT_CREATIVE, 1, 6000) 79 if (bad_drone as i64) != 0 { return 9 } 80 81 // Defensive instantiation OK 82 let drone: *NxDroneSession = nx_drone_session_new(7, 83 NX_DP_SEARCH_LOST, NX_INTENT_DEFENSIVE, 1, 7000) 84 if (drone as i64) == 0 { return 10 } 85 86 // SEARCH_LOST may deploy rescue beacons 87 if nx_drone_invoke_op(drone, NX_DO_DEPLOY_RESCUE_BEACON) != NX_DR_OK { return 11 } 88 89 // But DEFENSIVE_FAMILY purpose CANNOT deploy rescue beacons 90 // (deploy-beacon is search-specific) 91 let drone_fam: *NxDroneSession = nx_drone_session_new(8, 92 NX_DP_DEFENSIVE_FAMILY, NX_INTENT_DEFENSIVE, 1, 8000) 93 if nx_drone_invoke_op(drone_fam, NX_DO_DEPLOY_RESCUE_BEACON) != 94 NX_DR_REFUSED_PURPOSE_OP_MISMATCH { return 12 } 95 96 // ===== Step 9: Scam detector catches IRS-impersonation ======= 97 // "act now" + "irs" + "gift card" = canonical IRS scam pattern 98 let scam: *u8 = (sys_mmap(64)) as *u8 99 scam[0] = 97 as u8; scam[1] = 99 as u8; scam[2] = 116 as u8; 100 scam[3] = 32 as u8; scam[4] = 110 as u8; scam[5] = 111 as u8; 101 scam[6] = 119 as u8; scam[7] = 32 as u8; 102 scam[8] = 105 as u8; scam[9] = 114 as u8; scam[10] = 115 as u8; 103 scam[11] = 32 as u8; 104 scam[12] = 103 as u8; scam[13] = 105 as u8; scam[14] = 102 as u8; 105 scam[15] = 116 as u8; scam[16] = 32 as u8; 106 scam[17] = 99 as u8; scam[18] = 97 as u8; scam[19] = 114 as u8; 107 scam[20] = 100 as u8; 108 let r: *NxScamScanResult = nx_scam_scan(scam, 21, 109 NX_INTENT_DEFENSIVE, 9000) 110 if r.verdict != NX_SC_CONFIRMED_PATTERN { return 13 } 111 112 // ===== Step 10: Captain Moroni discipline verified ============ 113 // We never attacked back. We refused offensive variants. We 114 // surfaced threats. Family is defended. 115 if drone.operation_count != 1 { return 14 } 116 if r.pattern_count < 3 { return 15 } 117 118 return 0 119}