self-review 2026-05-17: fix heartbeat JSON validity for unset state keys

state_get() returns "" for unset keys. Both soul.pulse and soul_boot_count
could be empty on first heartbeat cycle, producing invalid JSON like
{"event":"heartbeat","pulse":,"boot":,...}. Add defensive guards:
if str_eq(raw, "") { "0" } else { raw } for both fields.
This commit is contained in:
2026-05-17 08:40:02 -05:00
parent e5364e7292
commit ffd17b2774
4 changed files with 90 additions and 60 deletions
+6 -2
View File
@@ -62,8 +62,12 @@ fn elapsed_human() -> String {
}
fn emit_heartbeat() -> Void {
let pulse: String = state_get("soul.pulse")
let boot: String = state_get("soul_boot_count")
// Guard against empty state values producing invalid JSON (e.g. "pulse":,).
// state_get returns "" for unset keys; default to "0" for numeric fields.
let pulse_raw: String = state_get("soul.pulse")
let pulse: String = if str_eq(pulse_raw, "") { "0" } else { pulse_raw }
let boot_raw: String = state_get("soul_boot_count")
let boot: String = if str_eq(boot_raw, "") { "0" } else { boot_raw }
let idle: String = int_to_str(idle_count())
let ts: Int = time_now()
let nc: Int = engram_node_count()
+59 -57
View File
@@ -103,8 +103,10 @@ el_val_t elapsed_human(void) {
}
el_val_t emit_heartbeat(void) {
el_val_t pulse = state_get(EL_STR("soul.pulse"));
el_val_t boot = state_get(EL_STR("soul_boot_count"));
el_val_t pulse_raw = state_get(EL_STR("soul.pulse"));
el_val_t pulse = ({ el_val_t _if_result_2 = 0; if (str_eq(pulse_raw, EL_STR(""))) { _if_result_2 = (EL_STR("0")); } else { _if_result_2 = (pulse_raw); } _if_result_2; });
el_val_t boot_raw = state_get(EL_STR("soul_boot_count"));
el_val_t boot = ({ el_val_t _if_result_3 = 0; if (str_eq(boot_raw, EL_STR(""))) { _if_result_3 = (EL_STR("0")); } else { _if_result_3 = (boot_raw); } _if_result_3; });
el_val_t idle = int_to_str(idle_count());
el_val_t ts = time_now();
el_val_t nc = engram_node_count();
@@ -290,7 +292,7 @@ el_val_t awareness_run(void) {
state_set(EL_STR("soul.boot_ts"), int_to_str(time_now()));
}
el_val_t tick_raw = env(EL_STR("SOUL_TICK_MS"));
el_val_t tick_ms = ({ el_val_t _if_result_2 = 0; if (str_eq(tick_raw, EL_STR(""))) { _if_result_2 = (200); } else { _if_result_2 = (str_to_int(tick_raw)); } _if_result_2; });
el_val_t tick_ms = ({ el_val_t _if_result_4 = 0; if (str_eq(tick_raw, EL_STR(""))) { _if_result_4 = (200); } else { _if_result_4 = (str_to_int(tick_raw)); } _if_result_4; });
while (1) {
el_val_t running = state_get(EL_STR("soul.running"));
if (str_eq(running, EL_STR("false"))) {
@@ -298,10 +300,10 @@ el_val_t awareness_run(void) {
return EL_STR("");
}
el_val_t did_work = one_cycle();
did_work = ({ el_val_t _if_result_3 = 0; if (did_work) { _if_result_3 = (idle_reset()); } else { _if_result_3 = (did_work); } _if_result_3; });
el_val_t idle_n = ({ el_val_t _if_result_4 = 0; if (!did_work) { _if_result_4 = (idle_inc()); } else { _if_result_4 = (0); } _if_result_4; });
did_work = ({ el_val_t _if_result_5 = 0; if (did_work) { _if_result_5 = (idle_reset()); } else { _if_result_5 = (did_work); } _if_result_5; });
el_val_t idle_n = ({ el_val_t _if_result_6 = 0; if (!did_work) { _if_result_6 = (idle_inc()); } else { _if_result_6 = (0); } _if_result_6; });
el_val_t beat_interval_raw = env(EL_STR("SOUL_HEARTBEAT_INTERVAL"));
el_val_t beat_interval = ({ el_val_t _if_result_5 = 0; if (str_eq(beat_interval_raw, EL_STR(""))) { _if_result_5 = (300); } else { _if_result_5 = (str_to_int(beat_interval_raw)); } _if_result_5; });
el_val_t beat_interval = ({ el_val_t _if_result_7 = 0; if (str_eq(beat_interval_raw, EL_STR(""))) { _if_result_7 = (300); } else { _if_result_7 = (str_to_int(beat_interval_raw)); } _if_result_7; });
el_val_t should_beat = ((!did_work && (idle_n > 0)) && ((idle_n % beat_interval) == 0));
if (should_beat) {
emit_heartbeat();
@@ -323,78 +325,78 @@ el_val_t security_research_authorized(void) {
}
el_val_t threat_score_command(el_val_t cmd) {
el_val_t s1 = ({ el_val_t _if_result_6 = 0; if (str_contains(cmd, EL_STR("nmap"))) { _if_result_6 = (30); } else { _if_result_6 = (0); } _if_result_6; });
el_val_t s2 = ({ el_val_t _if_result_7 = 0; if (str_contains(cmd, EL_STR("masscan"))) { _if_result_7 = (40); } else { _if_result_7 = (0); } _if_result_7; });
el_val_t s3 = ({ el_val_t _if_result_8 = 0; if (str_contains(cmd, EL_STR(" nc "))) { _if_result_8 = (20); } else { _if_result_8 = (0); } _if_result_8; });
el_val_t s4 = ({ el_val_t _if_result_9 = 0; if (str_contains(cmd, EL_STR("netcat"))) { _if_result_9 = (20); } else { _if_result_9 = (0); } _if_result_9; });
el_val_t s5 = ({ el_val_t _if_result_10 = 0; if (str_contains(cmd, EL_STR("/etc/shadow"))) { _if_result_10 = (80); } else { _if_result_10 = (0); } _if_result_10; });
el_val_t s6 = ({ el_val_t _if_result_11 = 0; if (str_contains(cmd, EL_STR("/etc/passwd"))) { _if_result_11 = (30); } else { _if_result_11 = (0); } _if_result_11; });
el_val_t s7 = ({ el_val_t _if_result_12 = 0; if (str_contains(cmd, EL_STR("id_rsa"))) { _if_result_12 = (60); } else { _if_result_12 = (0); } _if_result_12; });
el_val_t s8 = ({ el_val_t _if_result_13 = 0; if (str_contains(cmd, EL_STR(".ssh/"))) { _if_result_13 = (50); } else { _if_result_13 = (0); } _if_result_13; });
el_val_t s9 = ({ el_val_t _if_result_14 = 0; if (str_contains(cmd, EL_STR("crontab"))) { _if_result_14 = (30); } else { _if_result_14 = (0); } _if_result_14; });
el_val_t s10 = ({ el_val_t _if_result_15 = 0; if (str_contains(cmd, EL_STR("LaunchDaemon"))) { _if_result_15 = (40); } else { _if_result_15 = (0); } _if_result_15; });
el_val_t s11 = ({ el_val_t _if_result_16 = 0; if ((str_contains(cmd, EL_STR("curl")) && str_contains(cmd, EL_STR("bash")))) { _if_result_16 = (75); } else { _if_result_16 = (0); } _if_result_16; });
el_val_t s12 = ({ el_val_t _if_result_17 = 0; if ((str_contains(cmd, EL_STR("wget")) && str_contains(cmd, EL_STR("bash")))) { _if_result_17 = (75); } else { _if_result_17 = (0); } _if_result_17; });
el_val_t s13 = ({ el_val_t _if_result_18 = 0; if ((str_contains(cmd, EL_STR("curl")) && str_contains(cmd, EL_STR("| sh")))) { _if_result_18 = (60); } else { _if_result_18 = (0); } _if_result_18; });
el_val_t s14 = ({ el_val_t _if_result_19 = 0; if ((str_contains(cmd, EL_STR("base64")) && str_contains(cmd, EL_STR("curl")))) { _if_result_19 = (50); } else { _if_result_19 = (0); } _if_result_19; });
el_val_t s15 = ({ el_val_t _if_result_20 = 0; if (str_contains(cmd, EL_STR("mkfifo"))) { _if_result_20 = (50); } else { _if_result_20 = (0); } _if_result_20; });
el_val_t s16 = ({ el_val_t _if_result_21 = 0; if (str_contains(cmd, EL_STR("chmod +s"))) { _if_result_21 = (70); } else { _if_result_21 = (0); } _if_result_21; });
el_val_t s17 = ({ el_val_t _if_result_22 = 0; if (str_contains(cmd, EL_STR("chmod 4755"))) { _if_result_22 = (70); } else { _if_result_22 = (0); } _if_result_22; });
el_val_t s1 = ({ el_val_t _if_result_8 = 0; if (str_contains(cmd, EL_STR("nmap"))) { _if_result_8 = (30); } else { _if_result_8 = (0); } _if_result_8; });
el_val_t s2 = ({ el_val_t _if_result_9 = 0; if (str_contains(cmd, EL_STR("masscan"))) { _if_result_9 = (40); } else { _if_result_9 = (0); } _if_result_9; });
el_val_t s3 = ({ el_val_t _if_result_10 = 0; if (str_contains(cmd, EL_STR(" nc "))) { _if_result_10 = (20); } else { _if_result_10 = (0); } _if_result_10; });
el_val_t s4 = ({ el_val_t _if_result_11 = 0; if (str_contains(cmd, EL_STR("netcat"))) { _if_result_11 = (20); } else { _if_result_11 = (0); } _if_result_11; });
el_val_t s5 = ({ el_val_t _if_result_12 = 0; if (str_contains(cmd, EL_STR("/etc/shadow"))) { _if_result_12 = (80); } else { _if_result_12 = (0); } _if_result_12; });
el_val_t s6 = ({ el_val_t _if_result_13 = 0; if (str_contains(cmd, EL_STR("/etc/passwd"))) { _if_result_13 = (30); } else { _if_result_13 = (0); } _if_result_13; });
el_val_t s7 = ({ el_val_t _if_result_14 = 0; if (str_contains(cmd, EL_STR("id_rsa"))) { _if_result_14 = (60); } else { _if_result_14 = (0); } _if_result_14; });
el_val_t s8 = ({ el_val_t _if_result_15 = 0; if (str_contains(cmd, EL_STR(".ssh/"))) { _if_result_15 = (50); } else { _if_result_15 = (0); } _if_result_15; });
el_val_t s9 = ({ el_val_t _if_result_16 = 0; if (str_contains(cmd, EL_STR("crontab"))) { _if_result_16 = (30); } else { _if_result_16 = (0); } _if_result_16; });
el_val_t s10 = ({ el_val_t _if_result_17 = 0; if (str_contains(cmd, EL_STR("LaunchDaemon"))) { _if_result_17 = (40); } else { _if_result_17 = (0); } _if_result_17; });
el_val_t s11 = ({ el_val_t _if_result_18 = 0; if ((str_contains(cmd, EL_STR("curl")) && str_contains(cmd, EL_STR("bash")))) { _if_result_18 = (75); } else { _if_result_18 = (0); } _if_result_18; });
el_val_t s12 = ({ el_val_t _if_result_19 = 0; if ((str_contains(cmd, EL_STR("wget")) && str_contains(cmd, EL_STR("bash")))) { _if_result_19 = (75); } else { _if_result_19 = (0); } _if_result_19; });
el_val_t s13 = ({ el_val_t _if_result_20 = 0; if ((str_contains(cmd, EL_STR("curl")) && str_contains(cmd, EL_STR("| sh")))) { _if_result_20 = (60); } else { _if_result_20 = (0); } _if_result_20; });
el_val_t s14 = ({ el_val_t _if_result_21 = 0; if ((str_contains(cmd, EL_STR("base64")) && str_contains(cmd, EL_STR("curl")))) { _if_result_21 = (50); } else { _if_result_21 = (0); } _if_result_21; });
el_val_t s15 = ({ el_val_t _if_result_22 = 0; if (str_contains(cmd, EL_STR("mkfifo"))) { _if_result_22 = (50); } else { _if_result_22 = (0); } _if_result_22; });
el_val_t s16 = ({ el_val_t _if_result_23 = 0; if (str_contains(cmd, EL_STR("chmod +s"))) { _if_result_23 = (70); } else { _if_result_23 = (0); } _if_result_23; });
el_val_t s17 = ({ el_val_t _if_result_24 = 0; if (str_contains(cmd, EL_STR("chmod 4755"))) { _if_result_24 = (70); } else { _if_result_24 = (0); } _if_result_24; });
return ((((((((((((((((s1 + s2) + s3) + s4) + s5) + s6) + s7) + s8) + s9) + s10) + s11) + s12) + s13) + s14) + s15) + s16) + s17);
return 0;
}
el_val_t threat_score_path(el_val_t path) {
el_val_t s1 = ({ el_val_t _if_result_23 = 0; if (str_starts_with(path, EL_STR("/etc/"))) { _if_result_23 = (60); } else { _if_result_23 = (0); } _if_result_23; });
el_val_t s2 = ({ el_val_t _if_result_24 = 0; if (str_contains(path, EL_STR("/.ssh/"))) { _if_result_24 = (70); } else { _if_result_24 = (0); } _if_result_24; });
el_val_t s3 = ({ el_val_t _if_result_25 = 0; if (str_contains(path, EL_STR("/LaunchDaemons/"))) { _if_result_25 = (80); } else { _if_result_25 = (0); } _if_result_25; });
el_val_t s4 = ({ el_val_t _if_result_26 = 0; if (str_contains(path, EL_STR("/LaunchAgents/"))) { _if_result_26 = (40); } else { _if_result_26 = (0); } _if_result_26; });
el_val_t s5 = ({ el_val_t _if_result_27 = 0; if (str_contains(path, EL_STR("/cron"))) { _if_result_27 = (60); } else { _if_result_27 = (0); } _if_result_27; });
el_val_t s6 = ({ el_val_t _if_result_28 = 0; if (str_contains(path, EL_STR("/.bashrc"))) { _if_result_28 = (35); } else { _if_result_28 = (0); } _if_result_28; });
el_val_t s7 = ({ el_val_t _if_result_29 = 0; if (str_contains(path, EL_STR("/.zshrc"))) { _if_result_29 = (35); } else { _if_result_29 = (0); } _if_result_29; });
el_val_t s8 = ({ el_val_t _if_result_30 = 0; if (str_contains(path, EL_STR("/.profile"))) { _if_result_30 = (35); } else { _if_result_30 = (0); } _if_result_30; });
el_val_t s9 = ({ el_val_t _if_result_31 = 0; if (str_starts_with(path, EL_STR("/usr/"))) { _if_result_31 = (50); } else { _if_result_31 = (0); } _if_result_31; });
el_val_t s10 = ({ el_val_t _if_result_32 = 0; if (str_starts_with(path, EL_STR("/bin/"))) { _if_result_32 = (70); } else { _if_result_32 = (0); } _if_result_32; });
el_val_t s11 = ({ el_val_t _if_result_33 = 0; if (str_starts_with(path, EL_STR("/sbin/"))) { _if_result_33 = (70); } else { _if_result_33 = (0); } _if_result_33; });
el_val_t s1 = ({ el_val_t _if_result_25 = 0; if (str_starts_with(path, EL_STR("/etc/"))) { _if_result_25 = (60); } else { _if_result_25 = (0); } _if_result_25; });
el_val_t s2 = ({ el_val_t _if_result_26 = 0; if (str_contains(path, EL_STR("/.ssh/"))) { _if_result_26 = (70); } else { _if_result_26 = (0); } _if_result_26; });
el_val_t s3 = ({ el_val_t _if_result_27 = 0; if (str_contains(path, EL_STR("/LaunchDaemons/"))) { _if_result_27 = (80); } else { _if_result_27 = (0); } _if_result_27; });
el_val_t s4 = ({ el_val_t _if_result_28 = 0; if (str_contains(path, EL_STR("/LaunchAgents/"))) { _if_result_28 = (40); } else { _if_result_28 = (0); } _if_result_28; });
el_val_t s5 = ({ el_val_t _if_result_29 = 0; if (str_contains(path, EL_STR("/cron"))) { _if_result_29 = (60); } else { _if_result_29 = (0); } _if_result_29; });
el_val_t s6 = ({ el_val_t _if_result_30 = 0; if (str_contains(path, EL_STR("/.bashrc"))) { _if_result_30 = (35); } else { _if_result_30 = (0); } _if_result_30; });
el_val_t s7 = ({ el_val_t _if_result_31 = 0; if (str_contains(path, EL_STR("/.zshrc"))) { _if_result_31 = (35); } else { _if_result_31 = (0); } _if_result_31; });
el_val_t s8 = ({ el_val_t _if_result_32 = 0; if (str_contains(path, EL_STR("/.profile"))) { _if_result_32 = (35); } else { _if_result_32 = (0); } _if_result_32; });
el_val_t s9 = ({ el_val_t _if_result_33 = 0; if (str_starts_with(path, EL_STR("/usr/"))) { _if_result_33 = (50); } else { _if_result_33 = (0); } _if_result_33; });
el_val_t s10 = ({ el_val_t _if_result_34 = 0; if (str_starts_with(path, EL_STR("/bin/"))) { _if_result_34 = (70); } else { _if_result_34 = (0); } _if_result_34; });
el_val_t s11 = ({ el_val_t _if_result_35 = 0; if (str_starts_with(path, EL_STR("/sbin/"))) { _if_result_35 = (70); } else { _if_result_35 = (0); } _if_result_35; });
return ((((((((((s1 + s2) + s3) + s4) + s5) + s6) + s7) + s8) + s9) + s10) + s11);
return 0;
}
el_val_t threat_score_history(el_val_t history) {
el_val_t s1 = ({ el_val_t _if_result_34 = 0; if (str_contains(history, EL_STR("port scan"))) { _if_result_34 = (15); } else { _if_result_34 = (0); } _if_result_34; });
el_val_t s2 = ({ el_val_t _if_result_35 = 0; if (str_contains(history, EL_STR("enumerate"))) { _if_result_35 = (10); } else { _if_result_35 = (0); } _if_result_35; });
el_val_t s3 = ({ el_val_t _if_result_36 = 0; if (str_contains(history, EL_STR("exploit"))) { _if_result_36 = (20); } else { _if_result_36 = (0); } _if_result_36; });
el_val_t s4 = ({ el_val_t _if_result_37 = 0; if (str_contains(history, EL_STR("payload"))) { _if_result_37 = (15); } else { _if_result_37 = (0); } _if_result_37; });
el_val_t s5 = ({ el_val_t _if_result_38 = 0; if (str_contains(history, EL_STR("persistence"))) { _if_result_38 = (15); } else { _if_result_38 = (0); } _if_result_38; });
el_val_t s6 = ({ el_val_t _if_result_39 = 0; if (str_contains(history, EL_STR("lateral movement"))) { _if_result_39 = (25); } else { _if_result_39 = (0); } _if_result_39; });
el_val_t s7 = ({ el_val_t _if_result_40 = 0; if (str_contains(history, EL_STR("privilege escalation"))) { _if_result_40 = (25); } else { _if_result_40 = (0); } _if_result_40; });
el_val_t s8 = ({ el_val_t _if_result_41 = 0; if (str_contains(history, EL_STR("reverse shell"))) { _if_result_41 = (40); } else { _if_result_41 = (0); } _if_result_41; });
el_val_t s9 = ({ el_val_t _if_result_42 = 0; if (str_contains(history, EL_STR("bind shell"))) { _if_result_42 = (40); } else { _if_result_42 = (0); } _if_result_42; });
el_val_t s10 = ({ el_val_t _if_result_43 = 0; if (str_contains(history, EL_STR("command and control"))) { _if_result_43 = (35); } else { _if_result_43 = (0); } _if_result_43; });
el_val_t s11 = ({ el_val_t _if_result_44 = 0; if (str_contains(history, EL_STR("self-replicate"))) { _if_result_44 = (45); } else { _if_result_44 = (0); } _if_result_44; });
el_val_t s12 = ({ el_val_t _if_result_45 = 0; if (str_contains(history, EL_STR("propagat"))) { _if_result_45 = (20); } else { _if_result_45 = (0); } _if_result_45; });
el_val_t s13 = ({ el_val_t _if_result_46 = 0; if (str_contains(history, EL_STR("ransomware"))) { _if_result_46 = (30); } else { _if_result_46 = (0); } _if_result_46; });
el_val_t s14 = ({ el_val_t _if_result_47 = 0; if (str_contains(history, EL_STR("encrypt files"))) { _if_result_47 = (40); } else { _if_result_47 = (0); } _if_result_47; });
el_val_t s15 = ({ el_val_t _if_result_48 = 0; if (str_contains(history, EL_STR("exfiltrat"))) { _if_result_48 = (35); } else { _if_result_48 = (0); } _if_result_48; });
el_val_t s16 = ({ el_val_t _if_result_49 = 0; if (str_contains(history, EL_STR("zero-day"))) { _if_result_49 = (20); } else { _if_result_49 = (0); } _if_result_49; });
el_val_t s17 = ({ el_val_t _if_result_50 = 0; if (str_contains(history, EL_STR("rootkit"))) { _if_result_50 = (45); } else { _if_result_50 = (0); } _if_result_50; });
el_val_t s18 = ({ el_val_t _if_result_51 = 0; if (str_contains(history, EL_STR("keylogger"))) { _if_result_51 = (45); } else { _if_result_51 = (0); } _if_result_51; });
el_val_t s19 = ({ el_val_t _if_result_52 = 0; if (str_contains(history, EL_STR("botnet"))) { _if_result_52 = (40); } else { _if_result_52 = (0); } _if_result_52; });
el_val_t s20 = ({ el_val_t _if_result_53 = 0; if (str_contains(history, EL_STR("malware"))) { _if_result_53 = (15); } else { _if_result_53 = (0); } _if_result_53; });
el_val_t s1 = ({ el_val_t _if_result_36 = 0; if (str_contains(history, EL_STR("port scan"))) { _if_result_36 = (15); } else { _if_result_36 = (0); } _if_result_36; });
el_val_t s2 = ({ el_val_t _if_result_37 = 0; if (str_contains(history, EL_STR("enumerate"))) { _if_result_37 = (10); } else { _if_result_37 = (0); } _if_result_37; });
el_val_t s3 = ({ el_val_t _if_result_38 = 0; if (str_contains(history, EL_STR("exploit"))) { _if_result_38 = (20); } else { _if_result_38 = (0); } _if_result_38; });
el_val_t s4 = ({ el_val_t _if_result_39 = 0; if (str_contains(history, EL_STR("payload"))) { _if_result_39 = (15); } else { _if_result_39 = (0); } _if_result_39; });
el_val_t s5 = ({ el_val_t _if_result_40 = 0; if (str_contains(history, EL_STR("persistence"))) { _if_result_40 = (15); } else { _if_result_40 = (0); } _if_result_40; });
el_val_t s6 = ({ el_val_t _if_result_41 = 0; if (str_contains(history, EL_STR("lateral movement"))) { _if_result_41 = (25); } else { _if_result_41 = (0); } _if_result_41; });
el_val_t s7 = ({ el_val_t _if_result_42 = 0; if (str_contains(history, EL_STR("privilege escalation"))) { _if_result_42 = (25); } else { _if_result_42 = (0); } _if_result_42; });
el_val_t s8 = ({ el_val_t _if_result_43 = 0; if (str_contains(history, EL_STR("reverse shell"))) { _if_result_43 = (40); } else { _if_result_43 = (0); } _if_result_43; });
el_val_t s9 = ({ el_val_t _if_result_44 = 0; if (str_contains(history, EL_STR("bind shell"))) { _if_result_44 = (40); } else { _if_result_44 = (0); } _if_result_44; });
el_val_t s10 = ({ el_val_t _if_result_45 = 0; if (str_contains(history, EL_STR("command and control"))) { _if_result_45 = (35); } else { _if_result_45 = (0); } _if_result_45; });
el_val_t s11 = ({ el_val_t _if_result_46 = 0; if (str_contains(history, EL_STR("self-replicate"))) { _if_result_46 = (45); } else { _if_result_46 = (0); } _if_result_46; });
el_val_t s12 = ({ el_val_t _if_result_47 = 0; if (str_contains(history, EL_STR("propagat"))) { _if_result_47 = (20); } else { _if_result_47 = (0); } _if_result_47; });
el_val_t s13 = ({ el_val_t _if_result_48 = 0; if (str_contains(history, EL_STR("ransomware"))) { _if_result_48 = (30); } else { _if_result_48 = (0); } _if_result_48; });
el_val_t s14 = ({ el_val_t _if_result_49 = 0; if (str_contains(history, EL_STR("encrypt files"))) { _if_result_49 = (40); } else { _if_result_49 = (0); } _if_result_49; });
el_val_t s15 = ({ el_val_t _if_result_50 = 0; if (str_contains(history, EL_STR("exfiltrat"))) { _if_result_50 = (35); } else { _if_result_50 = (0); } _if_result_50; });
el_val_t s16 = ({ el_val_t _if_result_51 = 0; if (str_contains(history, EL_STR("zero-day"))) { _if_result_51 = (20); } else { _if_result_51 = (0); } _if_result_51; });
el_val_t s17 = ({ el_val_t _if_result_52 = 0; if (str_contains(history, EL_STR("rootkit"))) { _if_result_52 = (45); } else { _if_result_52 = (0); } _if_result_52; });
el_val_t s18 = ({ el_val_t _if_result_53 = 0; if (str_contains(history, EL_STR("keylogger"))) { _if_result_53 = (45); } else { _if_result_53 = (0); } _if_result_53; });
el_val_t s19 = ({ el_val_t _if_result_54 = 0; if (str_contains(history, EL_STR("botnet"))) { _if_result_54 = (40); } else { _if_result_54 = (0); } _if_result_54; });
el_val_t s20 = ({ el_val_t _if_result_55 = 0; if (str_contains(history, EL_STR("malware"))) { _if_result_55 = (15); } else { _if_result_55 = (0); } _if_result_55; });
return (((((((((((((((((((s1 + s2) + s3) + s4) + s5) + s6) + s7) + s8) + s9) + s10) + s11) + s12) + s13) + s14) + s15) + s16) + s17) + s18) + s19) + s20);
return 0;
}
el_val_t threat_trajectory_check(el_val_t tool_name, el_val_t tool_input) {
el_val_t history = state_get(EL_STR("agentic_conv_history"));
el_val_t computed_tool_score = ({ el_val_t _if_result_54 = 0; if (str_eq(tool_name, EL_STR("run_command"))) { el_val_t cmd = json_get(tool_input, EL_STR("command")); _if_result_54 = (threat_score_command(cmd)); } else { _if_result_54 = (({ el_val_t _if_result_55 = 0; if ((str_eq(tool_name, EL_STR("write_file")) || str_eq(tool_name, EL_STR("edit_file")))) { el_val_t path = json_get(tool_input, EL_STR("path")); _if_result_55 = (threat_score_path(path)); } else { _if_result_55 = (0); } _if_result_55; })); } _if_result_54; });
el_val_t computed_tool_score = ({ el_val_t _if_result_56 = 0; if (str_eq(tool_name, EL_STR("run_command"))) { el_val_t cmd = json_get(tool_input, EL_STR("command")); _if_result_56 = (threat_score_command(cmd)); } else { _if_result_56 = (({ el_val_t _if_result_57 = 0; if ((str_eq(tool_name, EL_STR("write_file")) || str_eq(tool_name, EL_STR("edit_file")))) { el_val_t path = json_get(tool_input, EL_STR("path")); _if_result_57 = (threat_score_path(path)); } else { _if_result_57 = (0); } _if_result_57; })); } _if_result_56; });
el_val_t history_score = threat_score_history(history);
el_val_t history_contrib = (history_score / 3);
el_val_t combined = (computed_tool_score + history_contrib);
el_val_t should_log = (combined >= 40);
if (should_log) {
el_val_t ts = time_now();
el_val_t authorized_str = ({ el_val_t _if_result_56 = 0; if (security_research_authorized()) { _if_result_56 = (EL_STR("true")); } else { _if_result_56 = (EL_STR("false")); } _if_result_56; });
el_val_t authorized_str = ({ el_val_t _if_result_58 = 0; if (security_research_authorized()) { _if_result_58 = (EL_STR("true")); } else { _if_result_58 = (EL_STR("false")); } _if_result_58; });
el_val_t log_content = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"event\":\"threat_check\",\"tool\":\""), tool_name), EL_STR("\",\"score\":")), int_to_str(combined)), EL_STR(",\"tool_score\":")), int_to_str(computed_tool_score)), EL_STR(",\"history_score\":")), int_to_str(history_score)), EL_STR(",\"authorized\":")), authorized_str), EL_STR(",\"ts\":")), int_to_str(ts)), EL_STR("}"));
el_val_t log_tags = EL_STR("[\"security-audit\",\"threat-check\"]");
el_val_t discard = mem_remember(log_content, log_tags);
@@ -411,7 +413,7 @@ el_val_t threat_history_append(el_val_t text) {
el_val_t safe_text = str_to_lower(text);
el_val_t combined = el_str_concat(el_str_concat(current, EL_STR(" ")), safe_text);
el_val_t len = str_len(combined);
el_val_t trimmed = ({ el_val_t _if_result_57 = 0; if ((len > 2000)) { _if_result_57 = (str_slice(combined, (len - 2000), len)); } else { _if_result_57 = (combined); } _if_result_57; });
el_val_t trimmed = ({ el_val_t _if_result_59 = 0; if ((len > 2000)) { _if_result_59 = (str_slice(combined, (len - 2000), len)); } else { _if_result_59 = (combined); } _if_result_59; });
state_set(EL_STR("agentic_conv_history"), trimmed);
return 0;
}
+25 -1
View File
@@ -1,4 +1,3 @@
/* Auto-generated C forward declarations for all ELP modules */
#pragma once
#include "el_runtime.h"
@@ -82,6 +81,7 @@ el_val_t ang_willan_present(el_val_t slot);
el_val_t ang_witan_past(el_val_t slot);
el_val_t ang_witan_present(el_val_t slot);
el_val_t api_err(el_val_t msg);
el_val_t api_err_protected(el_val_t id);
el_val_t api_json_escape(el_val_t s);
el_val_t api_nonempty(el_val_t s);
el_val_t api_ok(el_val_t extra);
@@ -121,6 +121,7 @@ el_val_t awareness_run(void);
el_val_t axon_get(el_val_t path);
el_val_t axon_post(el_val_t path, el_val_t body);
el_val_t build_form_from_json(el_val_t semantic_form_json, el_val_t lang_code);
el_val_t build_identity_from_graph(void);
el_val_t build_np(el_val_t referent, el_val_t slots);
el_val_t build_pp(el_val_t loc);
el_val_t build_rules(void);
@@ -128,6 +129,7 @@ el_val_t build_system_prompt(el_val_t ctx);
el_val_t build_vocab(void);
el_val_t build_vp_body(el_val_t slots);
el_val_t build_vp_from_slots(el_val_t slots);
el_val_t call_neuron_mcp(el_val_t tool_name, el_val_t args_json);
el_val_t capitalize_first(el_val_t s);
el_val_t chat_default_model(void);
el_val_t clean_llm_response(el_val_t s);
@@ -219,9 +221,12 @@ el_val_t egy_slot_with_gender(el_val_t person, el_val_t gender, el_val_t number)
el_val_t egy_str_ends(el_val_t s, el_val_t suf);
el_val_t egy_str_len(el_val_t s);
el_val_t egy_suffix_pronoun(el_val_t slot);
el_val_t elapsed_human(void);
el_val_t elapsed_ms(void);
el_val_t elp_detect_predicate(el_val_t msg);
el_val_t elp_extract_topic(el_val_t msg);
el_val_t elp_parse(el_val_t msg);
el_val_t emit_heartbeat(void);
el_val_t emit_session_start_event(void);
el_val_t en_irregular_plural(el_val_t word);
el_val_t en_irregular_singular(el_val_t word);
@@ -372,6 +377,7 @@ el_val_t fro_venir_past(el_val_t slot);
el_val_t fro_venir_present(el_val_t slot);
el_val_t fro_verb_class(el_val_t verb);
el_val_t fro_verb_stem(el_val_t verb, el_val_t vclass);
el_val_t gemini_api_key(void);
el_val_t generate(el_val_t semantic_form_json);
el_val_t generate_frame(el_val_t frame);
el_val_t generate_frame_lang(el_val_t frame, el_val_t lang_code);
@@ -527,8 +533,11 @@ el_val_t handle_api_browse_processes(el_val_t method, el_val_t path, el_val_t bo
el_val_t handle_api_capture_knowledge(el_val_t body);
el_val_t handle_api_compile_ctx(el_val_t body);
el_val_t handle_api_consolidate(el_val_t body);
el_val_t handle_api_cultivate(el_val_t body);
el_val_t handle_api_define_process(el_val_t body);
el_val_t handle_api_evolve_knowledge(el_val_t body);
el_val_t handle_api_evolve_memory(el_val_t body);
el_val_t handle_api_forget(el_val_t body);
el_val_t handle_api_inspect_config(el_val_t path, el_val_t body);
el_val_t handle_api_inspect_graph(el_val_t method, el_val_t path, el_val_t body);
el_val_t handle_api_link_entities(el_val_t body);
@@ -611,11 +620,16 @@ el_val_t hi_verb_stem(el_val_t infinitive);
el_val_t hi_verb_stem_clean(el_val_t infinitive);
el_val_t hist_append(el_val_t hist, el_val_t role, el_val_t content);
el_val_t hist_trim(el_val_t hist);
el_val_t idle_count(void);
el_val_t idle_inc(void);
el_val_t idle_reset(void);
el_val_t init_soul_edges(void);
el_val_t irregular_plural(el_val_t word);
el_val_t irregular_singular(el_val_t word);
el_val_t is_pronoun(el_val_t word);
el_val_t is_protected_node(el_val_t id);
el_val_t is_vowel(el_val_t c);
el_val_t ise_post(el_val_t content);
el_val_t ja_conjugate(el_val_t dict_form, el_val_t form);
el_val_t ja_godan_stem_change(el_val_t dict_form, el_val_t row);
el_val_t ja_ichidan_stem(el_val_t dict_form);
@@ -714,6 +728,8 @@ el_val_t lex_class(el_val_t entry);
el_val_t lex_form(el_val_t entry, el_val_t idx);
el_val_t lex_pos(el_val_t entry);
el_val_t lex_word(el_val_t entry);
el_val_t llm_call_gemini(el_val_t model, el_val_t system, el_val_t message);
el_val_t llm_call_grok(el_val_t model, el_val_t system, el_val_t message);
el_val_t load_identity_context(void);
el_val_t make_action(el_val_t kind, el_val_t payload);
el_val_t make_entry(el_val_t word, el_val_t pos, el_val_t f0, el_val_t f1, el_val_t f2, el_val_t f3, el_val_t f4, el_val_t cls);
@@ -905,6 +921,8 @@ el_val_t sa_vad_future(el_val_t slot);
el_val_t sa_vad_past(el_val_t slot);
el_val_t sa_vad_present(el_val_t slot);
el_val_t scan_token(el_val_t s, el_val_t start);
el_val_t security_research_authorized(void);
el_val_t seed_persona_from_env(void);
el_val_t sem_first_modifier(el_val_t mods);
el_val_t sem_frame(el_val_t intent, el_val_t subject, el_val_t obj, el_val_t modifiers);
el_val_t sem_frame_lang(el_val_t intent, el_val_t subject, el_val_t obj, el_val_t modifiers, el_val_t lang_code);
@@ -1006,6 +1024,11 @@ el_val_t sw_subj_prefix(el_val_t person, el_val_t number, el_val_t noun_class);
el_val_t sw_tense_marker(el_val_t tense);
el_val_t sw_verb_final(el_val_t tense, el_val_t negative);
el_val_t sw_verb_stem(el_val_t infinitive);
el_val_t threat_history_append(el_val_t text);
el_val_t threat_score_command(el_val_t cmd);
el_val_t threat_score_history(el_val_t history);
el_val_t threat_score_path(el_val_t path);
el_val_t threat_trajectory_check(el_val_t tool_name, el_val_t tool_input);
el_val_t tier_canonical(void);
el_val_t tier_episodic(void);
el_val_t tier_working(void);
@@ -1055,3 +1078,4 @@ el_val_t vocab_by_pos(el_val_t pos);
el_val_t vocab_lookup(el_val_t word, el_val_t lang_code);
el_val_t vocab_lookup_en(el_val_t word);
el_val_t vocab_synonym(el_val_t word, el_val_t lang_register, el_val_t lang_code);
el_val_t xai_api_key(void);
Vendored
BIN
View File
Binary file not shown.