self-review 2026-07-30: auto_term stopword filter, real idle_ms, bounded beginSession

- awareness.el: curiosity auto_term was the raw first word of a WM
  label with no term-quality scoring — observed seeds included What,
  Colon, Prose, Context. Replaced the 7-word genre blocklist whack-a-
  mole with a delimited stopword membership test (function words +
  document-structure words); topical terms pass untouched. Verified
  live: seeds now ReasonEdit, Reasoning-model, Self-review.
- routes.el + awareness.el: idle counter only reset on rare inbox
  synthesis-requests, so idle==pulse always (zero information).
  handle_request now stamps soul.last_activity_ts on every inbound
  HTTP request; heartbeat emits idle_ms = ms since last request
  (-1 until first request of a boot).
- neuron-api.el: beginSession concatenated a depth-2 spread plus the
  unbounded self-hub neighbor dump — multi-MB response, doubled by
  wrapper re-escaping, socket died on every call. Now depth-1 and
  the hub dump dropped (identity loading has its own tool). Verified:
  beginSession returns instead of closing the socket.
This commit is contained in:
2026-07-30 08:45:21 -05:00
parent 627eb534a2
commit b0f4d6c493
7 changed files with 158 additions and 100 deletions
+28 -1
View File
@@ -125,6 +125,13 @@ fn emit_heartbeat() -> Void {
let boot: String = if str_eq(boot_raw, "") { "0" } else { boot_raw } let boot: String = if str_eq(boot_raw, "") { "0" } else { boot_raw }
let idle: String = int_to_str(idle_count()) let idle: String = int_to_str(idle_count())
let ts: Int = time_now() let ts: Int = time_now()
// idle_ms (2026-07-30 self-review): wall-clock ms since the last inbound
// HTTP request (stamped in routes.el handle_request). This is the real
// "time since anyone talked to me" signal; the legacy tick-based idle
// field above only counts ticks since the last inbox synthesis-request
// and in practice always equals pulse. -1 = no request seen this boot.
let last_act_raw: String = state_get("soul.last_activity_ts")
let idle_ms: Int = if str_eq(last_act_raw, "") { 0 - 1 } else { ts - str_to_int(last_act_raw) }
let nc: Int = engram_node_count() let nc: Int = engram_node_count()
let ec: Int = engram_edge_count() let ec: Int = engram_edge_count()
let wmc: Int = engram_wm_count() let wmc: Int = engram_wm_count()
@@ -250,7 +257,14 @@ fn emit_heartbeat() -> Void {
let act_bt: String = if str_eq(act_bt_raw, "") { "-1" } else { act_bt_raw } let act_bt: String = if str_eq(act_bt_raw, "") { "-1" } else { act_bt_raw }
let act_brk_raw: String = json_get(act_stats, "embed_breaker_open") let act_brk_raw: String = json_get(act_stats, "embed_breaker_open")
let act_brk: String = if str_eq(act_brk_raw, "") { "-1" } else { act_brk_raw } let act_brk: String = if str_eq(act_brk_raw, "") { "-1" } else { act_brk_raw }
let payload: String = "{\"event\":\"heartbeat\",\"pulse\":" + pulse + ",\"tick\":" + pulse + ",\"boot\":" + boot + ",\"idle\":" + idle + ",\"node_count\":" + int_to_str(nc) + ",\"edge_count\":" + int_to_str(ec) + ",\"node_delta\":" + int_to_str(node_delta) + ",\"edge_delta\":" + int_to_str(edge_delta) + ",\"wm_active\":" + int_to_str(wmc) + ",\"wm_delta\":" + int_to_str(wm_delta) + ",\"wm_saturated\":" + int_to_str(wm_sat) + ",\"wm_top0_streak\":" + int_to_str(t0streak) + ",\"wm_churn\":" + int_to_str(wm_churn) + ",\"wm_top0_wm\":" + wm_top0_wm + ",\"sync_added_total\":" + sat_str + ",\"sync_age_ms\":" + int_to_str(sync_age) + ",\"wm_avg_weight\":" + wm_avg_str + ",\"wm_top\":" + wm_top + ",\"ts\":" + int_to_str(ts) + ",\"uptime_ms\":" + int_to_str(up_ms) + ",\"uptime\":\"" + up_human + "\",\"embed_ok\":" + int_to_str(emb_ok) + ",\"embed_backfilled\":" + bf_done + ",\"embed_count\":" + bf_total + ",\"wm_evicted\":" + act_evict + ",\"breakthroughs\":" + act_bt + ",\"embed_breaker_open\":" + act_brk + ",\"ise_fail\":" + fail_str + "}" // ctx_cos (2026-07-29 self-review): cos(query, context centroid) at the
// last activate call — the drift gauge for the new context-centroid
// scoring. ~1.0 aligned; low at domain-rotation boundaries is healthy;
// -2.0 pinned for hours means the centroid never initializes (embedder
// down) and semantic continuity is silently absent.
let ctx_cos_raw: String = json_get(act_stats, "ctx_cos")
let ctx_cos: String = if str_eq(ctx_cos_raw, "") { "-2" } else { ctx_cos_raw }
let payload: String = "{\"event\":\"heartbeat\",\"pulse\":" + pulse + ",\"tick\":" + pulse + ",\"boot\":" + boot + ",\"idle\":" + idle + ",\"idle_ms\":" + int_to_str(idle_ms) + ",\"node_count\":" + int_to_str(nc) + ",\"edge_count\":" + int_to_str(ec) + ",\"node_delta\":" + int_to_str(node_delta) + ",\"edge_delta\":" + int_to_str(edge_delta) + ",\"wm_active\":" + int_to_str(wmc) + ",\"wm_delta\":" + int_to_str(wm_delta) + ",\"wm_saturated\":" + int_to_str(wm_sat) + ",\"wm_top0_streak\":" + int_to_str(t0streak) + ",\"wm_churn\":" + int_to_str(wm_churn) + ",\"wm_top0_wm\":" + wm_top0_wm + ",\"sync_added_total\":" + sat_str + ",\"sync_age_ms\":" + int_to_str(sync_age) + ",\"wm_avg_weight\":" + wm_avg_str + ",\"wm_top\":" + wm_top + ",\"ts\":" + int_to_str(ts) + ",\"uptime_ms\":" + int_to_str(up_ms) + ",\"uptime\":\"" + up_human + "\",\"embed_ok\":" + int_to_str(emb_ok) + ",\"embed_backfilled\":" + bf_done + ",\"embed_count\":" + bf_total + ",\"wm_evicted\":" + act_evict + ",\"breakthroughs\":" + act_bt + ",\"embed_breaker_open\":" + act_brk + ",\"ctx_cos\":" + ctx_cos + ",\"ise_fail\":" + fail_str + "}"
ise_post(payload) ise_post(payload)
} }
@@ -321,6 +335,19 @@ fn auto_term_try_slot(slot_type: String, slot_lbl: String) -> Void {
if str_eq(term, "Paper") { state_set("_ats_gw", "1") } if str_eq(term, "Paper") { state_set("_ats_gw", "1") }
if str_eq(term, "Knowledge") { state_set("_ats_gw", "1") } if str_eq(term, "Knowledge") { state_set("_ats_gw", "1") }
if str_eq(term, "Value") { state_set("_ats_gw", "1") } if str_eq(term, "Value") { state_set("_ats_gw", "1") }
// STOPWORD FILTER (2026-07-30 self-review): the genre
// blocklist above was whack-a-mole — observed live seeds
// included "What", "Colon", "Prose", "Context", "Self",
// "Closing", "Global", "Universal": English function words
// and document-structure words that pass the >3-char guard
// but carry no topical signal (a first-word extractor has no
// term-quality scoring). Single delimited membership test
// against a curated list of function words + title/structure
// words; topical technical terms (MemQ, AsymGRPO, Mobius,
// engram_goal_bias) pass untouched. Both Title-case and
// lowercase variants listed for the most common offenders.
let stopw: String = "|What|When|Where|Which|Whose|While|This|That|These|Those|There|Their|Then|Than|With|Without|From|Into|Onto|Over|Under|About|Between|Among|Across|Some|Most|More|Less|Very|Each|Every|Both|Also|Only|Just|Does|Will|Would|Could|Should|Might|Must|Have|Been|Being|Toward|Towards|Using|Based|Upon|Here|Your|Ours|They|Them|what|this|that|with|from|context|Context|Prose|Colon|Self|Test|Testing|Closing|Global|Universal|Persona|Semantic|Spreading|Temporal|Numeric|Register|Identifying|Introduction|Overview|Summary|Section|General|Notes|Note|"
if str_contains(stopw, "|" + term + "|") { state_set("_ats_gw", "1") }
// QUOTED-TITLE GUARD (2026-07-25 self-review): labels that // QUOTED-TITLE GUARD (2026-07-25 self-review): labels that
// open with a quote ('"The Algorithmic Caricature" ...') // open with a quote ('"The Algorithmic Caricature" ...')
// defeat the >3-char stopword guard — the extracted term // defeat the >3-char stopword guard — the extracted term
Generated Vendored
+96 -88
View File
@@ -133,6 +133,8 @@ el_val_t emit_heartbeat(void) {
el_val_t boot = ({ el_val_t _if_result_4 = 0; if (str_eq(boot_raw, EL_STR(""))) { _if_result_4 = (EL_STR("0")); } else { _if_result_4 = (boot_raw); } _if_result_4; }); el_val_t boot = ({ el_val_t _if_result_4 = 0; if (str_eq(boot_raw, EL_STR(""))) { _if_result_4 = (EL_STR("0")); } else { _if_result_4 = (boot_raw); } _if_result_4; });
el_val_t idle = int_to_str(idle_count()); el_val_t idle = int_to_str(idle_count());
el_val_t ts = time_now(); el_val_t ts = time_now();
el_val_t last_act_raw = state_get(EL_STR("soul.last_activity_ts"));
el_val_t idle_ms = ({ el_val_t _if_result_5 = 0; if (str_eq(last_act_raw, EL_STR(""))) { _if_result_5 = ((0 - 1)); } else { _if_result_5 = ((ts - str_to_int(last_act_raw))); } _if_result_5; });
el_val_t nc = engram_node_count(); el_val_t nc = engram_node_count();
el_val_t ec = engram_edge_count(); el_val_t ec = engram_edge_count();
el_val_t wmc = engram_wm_count(); el_val_t wmc = engram_wm_count();
@@ -143,38 +145,38 @@ el_val_t emit_heartbeat(void) {
el_val_t up_human = elapsed_human(); el_val_t up_human = elapsed_human();
el_val_t emb_ok = embed_ok(); el_val_t emb_ok = embed_ok();
el_val_t fail_raw = state_get(EL_STR("soul.ise_fail_count")); el_val_t fail_raw = state_get(EL_STR("soul.ise_fail_count"));
el_val_t fail_str = ({ el_val_t _if_result_5 = 0; if (str_eq(fail_raw, EL_STR(""))) { _if_result_5 = (EL_STR("0")); } else { _if_result_5 = (fail_raw); } _if_result_5; }); el_val_t fail_str = ({ el_val_t _if_result_6 = 0; if (str_eq(fail_raw, EL_STR(""))) { _if_result_6 = (EL_STR("0")); } else { _if_result_6 = (fail_raw); } _if_result_6; });
el_val_t sat_raw = state_get(EL_STR("soul.sync_added_total")); el_val_t sat_raw = state_get(EL_STR("soul.sync_added_total"));
el_val_t sat_str = ({ el_val_t _if_result_6 = 0; if (str_eq(sat_raw, EL_STR(""))) { _if_result_6 = (EL_STR("0")); } else { _if_result_6 = (sat_raw); } _if_result_6; }); el_val_t sat_str = ({ el_val_t _if_result_7 = 0; if (str_eq(sat_raw, EL_STR(""))) { _if_result_7 = (EL_STR("0")); } else { _if_result_7 = (sat_raw); } _if_result_7; });
el_val_t prev_wm_raw = state_get(EL_STR("soul.prev_wm_active")); el_val_t prev_wm_raw = state_get(EL_STR("soul.prev_wm_active"));
el_val_t prev_wm = ({ el_val_t _if_result_7 = 0; if (str_eq(prev_wm_raw, EL_STR(""))) { _if_result_7 = (0); } else { _if_result_7 = (str_to_int(prev_wm_raw)); } _if_result_7; }); el_val_t prev_wm = ({ el_val_t _if_result_8 = 0; if (str_eq(prev_wm_raw, EL_STR(""))) { _if_result_8 = (0); } else { _if_result_8 = (str_to_int(prev_wm_raw)); } _if_result_8; });
el_val_t wm_delta = (wmc - prev_wm); el_val_t wm_delta = (wmc - prev_wm);
state_set(EL_STR("soul.prev_wm_active"), int_to_str(wmc)); state_set(EL_STR("soul.prev_wm_active"), int_to_str(wmc));
el_val_t prev_nc_raw = state_get(EL_STR("soul.prev_node_count")); el_val_t prev_nc_raw = state_get(EL_STR("soul.prev_node_count"));
el_val_t prev_nc = ({ el_val_t _if_result_8 = 0; if (str_eq(prev_nc_raw, EL_STR(""))) { _if_result_8 = (nc); } else { _if_result_8 = (str_to_int(prev_nc_raw)); } _if_result_8; }); el_val_t prev_nc = ({ el_val_t _if_result_9 = 0; if (str_eq(prev_nc_raw, EL_STR(""))) { _if_result_9 = (nc); } else { _if_result_9 = (str_to_int(prev_nc_raw)); } _if_result_9; });
el_val_t node_delta = (nc - prev_nc); el_val_t node_delta = (nc - prev_nc);
state_set(EL_STR("soul.prev_node_count"), int_to_str(nc)); state_set(EL_STR("soul.prev_node_count"), int_to_str(nc));
el_val_t prev_ec_raw = state_get(EL_STR("soul.prev_edge_count")); el_val_t prev_ec_raw = state_get(EL_STR("soul.prev_edge_count"));
el_val_t prev_ec = ({ el_val_t _if_result_9 = 0; if (str_eq(prev_ec_raw, EL_STR(""))) { _if_result_9 = (ec); } else { _if_result_9 = (str_to_int(prev_ec_raw)); } _if_result_9; }); el_val_t prev_ec = ({ el_val_t _if_result_10 = 0; if (str_eq(prev_ec_raw, EL_STR(""))) { _if_result_10 = (ec); } else { _if_result_10 = (str_to_int(prev_ec_raw)); } _if_result_10; });
el_val_t edge_delta = (ec - prev_ec); el_val_t edge_delta = (ec - prev_ec);
state_set(EL_STR("soul.prev_edge_count"), int_to_str(ec)); state_set(EL_STR("soul.prev_edge_count"), int_to_str(ec));
el_val_t sync_ok_raw = state_get(EL_STR("soul.last_sync_ok_ts")); el_val_t sync_ok_raw = state_get(EL_STR("soul.last_sync_ok_ts"));
el_val_t sync_age = ({ el_val_t _if_result_10 = 0; if (str_eq(sync_ok_raw, EL_STR(""))) { _if_result_10 = ((0 - 1)); } else { _if_result_10 = ((ts - str_to_int(sync_ok_raw))); } _if_result_10; }); el_val_t sync_age = ({ el_val_t _if_result_11 = 0; if (str_eq(sync_ok_raw, EL_STR(""))) { _if_result_11 = ((0 - 1)); } else { _if_result_11 = ((ts - str_to_int(sync_ok_raw))); } _if_result_11; });
el_val_t hb_env_url = env(EL_STR("SOUL_ISE_URL")); el_val_t hb_env_url = env(EL_STR("SOUL_ISE_URL"));
el_val_t hb_state_url = ({ el_val_t _if_result_11 = 0; if (str_eq(hb_env_url, EL_STR(""))) { _if_result_11 = (state_get(EL_STR("soul_engram_url"))); } else { _if_result_11 = (hb_env_url); } _if_result_11; }); el_val_t hb_state_url = ({ el_val_t _if_result_12 = 0; if (str_eq(hb_env_url, EL_STR(""))) { _if_result_12 = (state_get(EL_STR("soul_engram_url"))); } else { _if_result_12 = (hb_env_url); } _if_result_12; });
el_val_t hb_engram_url = ({ el_val_t _if_result_12 = 0; if (str_eq(hb_state_url, EL_STR(""))) { _if_result_12 = (EL_STR("http://localhost:8742")); } else { _if_result_12 = (hb_state_url); } _if_result_12; }); el_val_t hb_engram_url = ({ el_val_t _if_result_13 = 0; if (str_eq(hb_state_url, EL_STR(""))) { _if_result_13 = (EL_STR("http://localhost:8742")); } else { _if_result_13 = (hb_state_url); } _if_result_13; });
el_val_t bf_resp = http_get(el_str_concat(hb_engram_url, EL_STR("/api/embed-backfill?n=32"))); el_val_t bf_resp = http_get(el_str_concat(hb_engram_url, EL_STR("/api/embed-backfill?n=32")));
el_val_t bf_done_raw = json_get(bf_resp, EL_STR("embedded")); el_val_t bf_done_raw = json_get(bf_resp, EL_STR("embedded"));
el_val_t bf_done = ({ el_val_t _if_result_13 = 0; if (str_eq(bf_done_raw, EL_STR(""))) { _if_result_13 = (EL_STR("-1")); } else { _if_result_13 = (bf_done_raw); } _if_result_13; }); el_val_t bf_done = ({ el_val_t _if_result_14 = 0; if (str_eq(bf_done_raw, EL_STR(""))) { _if_result_14 = (EL_STR("-1")); } else { _if_result_14 = (bf_done_raw); } _if_result_14; });
el_val_t bf_total_raw = json_get(bf_resp, EL_STR("embedded_count")); el_val_t bf_total_raw = json_get(bf_resp, EL_STR("embedded_count"));
el_val_t bf_total = ({ el_val_t _if_result_14 = 0; if (str_eq(bf_total_raw, EL_STR(""))) { _if_result_14 = (EL_STR("-1")); } else { _if_result_14 = (bf_total_raw); } _if_result_14; }); el_val_t bf_total = ({ el_val_t _if_result_15 = 0; if (str_eq(bf_total_raw, EL_STR(""))) { _if_result_15 = (EL_STR("-1")); } else { _if_result_15 = (bf_total_raw); } _if_result_15; });
el_val_t wm_sat = ({ el_val_t _if_result_15 = 0; if ((wmc >= 24)) { _if_result_15 = (1); } else { _if_result_15 = (0); } _if_result_15; }); el_val_t wm_sat = ({ el_val_t _if_result_16 = 0; if ((wmc >= 24)) { _if_result_16 = (1); } else { _if_result_16 = (0); } _if_result_16; });
el_val_t wm_top0 = json_array_get(wm_top, 0); el_val_t wm_top0 = json_array_get(wm_top, 0);
el_val_t wm_top0_id = json_get(wm_top0, EL_STR("id")); el_val_t wm_top0_id = json_get(wm_top0, EL_STR("id"));
el_val_t prev_top0 = state_get(EL_STR("soul.prev_wm_top0")); el_val_t prev_top0 = state_get(EL_STR("soul.prev_wm_top0"));
el_val_t t0streak_raw = state_get(EL_STR("soul.wm_top0_streak")); el_val_t t0streak_raw = state_get(EL_STR("soul.wm_top0_streak"));
el_val_t t0streak_prev = ({ el_val_t _if_result_16 = 0; if (str_eq(t0streak_raw, EL_STR(""))) { _if_result_16 = (0); } else { _if_result_16 = (str_to_int(t0streak_raw)); } _if_result_16; }); el_val_t t0streak_prev = ({ el_val_t _if_result_17 = 0; if (str_eq(t0streak_raw, EL_STR(""))) { _if_result_17 = (0); } else { _if_result_17 = (str_to_int(t0streak_raw)); } _if_result_17; });
el_val_t t0streak = ({ el_val_t _if_result_17 = 0; if (str_eq(wm_top0_id, EL_STR(""))) { _if_result_17 = (0); } else { _if_result_17 = (({ el_val_t _if_result_18 = 0; if (str_eq(wm_top0_id, prev_top0)) { _if_result_18 = ((t0streak_prev + 1)); } else { _if_result_18 = (1); } _if_result_18; })); } _if_result_17; }); el_val_t t0streak = ({ el_val_t _if_result_18 = 0; if (str_eq(wm_top0_id, EL_STR(""))) { _if_result_18 = (0); } else { _if_result_18 = (({ el_val_t _if_result_19 = 0; if (str_eq(wm_top0_id, prev_top0)) { _if_result_19 = ((t0streak_prev + 1)); } else { _if_result_19 = (1); } _if_result_19; })); } _if_result_18; });
state_set(EL_STR("soul.prev_wm_top0"), wm_top0_id); state_set(EL_STR("soul.prev_wm_top0"), wm_top0_id);
state_set(EL_STR("soul.wm_top0_streak"), int_to_str(t0streak)); state_set(EL_STR("soul.wm_top0_streak"), int_to_str(t0streak));
el_val_t ch_id1 = json_get(json_array_get(wm_top, 1), EL_STR("id")); el_val_t ch_id1 = json_get(json_array_get(wm_top, 1), EL_STR("id"));
@@ -182,23 +184,25 @@ el_val_t emit_heartbeat(void) {
el_val_t ch_id3 = json_get(json_array_get(wm_top, 3), EL_STR("id")); el_val_t ch_id3 = json_get(json_array_get(wm_top, 3), EL_STR("id"));
el_val_t ch_id4 = json_get(json_array_get(wm_top, 4), EL_STR("id")); el_val_t ch_id4 = json_get(json_array_get(wm_top, 4), EL_STR("id"));
el_val_t prev_top5 = state_get(EL_STR("soul.prev_wm_top5")); el_val_t prev_top5 = state_get(EL_STR("soul.prev_wm_top5"));
el_val_t ch0 = ({ el_val_t _if_result_19 = 0; if (str_eq(wm_top0_id, EL_STR(""))) { _if_result_19 = (0); } else { _if_result_19 = (({ el_val_t _if_result_20 = 0; if (str_contains(prev_top5, wm_top0_id)) { _if_result_20 = (0); } else { _if_result_20 = (1); } _if_result_20; })); } _if_result_19; }); el_val_t ch0 = ({ el_val_t _if_result_20 = 0; if (str_eq(wm_top0_id, EL_STR(""))) { _if_result_20 = (0); } else { _if_result_20 = (({ el_val_t _if_result_21 = 0; if (str_contains(prev_top5, wm_top0_id)) { _if_result_21 = (0); } else { _if_result_21 = (1); } _if_result_21; })); } _if_result_20; });
el_val_t ch1 = ({ el_val_t _if_result_21 = 0; if (str_eq(ch_id1, EL_STR(""))) { _if_result_21 = (0); } else { _if_result_21 = (({ el_val_t _if_result_22 = 0; if (str_contains(prev_top5, ch_id1)) { _if_result_22 = (0); } else { _if_result_22 = (1); } _if_result_22; })); } _if_result_21; }); el_val_t ch1 = ({ el_val_t _if_result_22 = 0; if (str_eq(ch_id1, EL_STR(""))) { _if_result_22 = (0); } else { _if_result_22 = (({ el_val_t _if_result_23 = 0; if (str_contains(prev_top5, ch_id1)) { _if_result_23 = (0); } else { _if_result_23 = (1); } _if_result_23; })); } _if_result_22; });
el_val_t ch2 = ({ el_val_t _if_result_23 = 0; if (str_eq(ch_id2, EL_STR(""))) { _if_result_23 = (0); } else { _if_result_23 = (({ el_val_t _if_result_24 = 0; if (str_contains(prev_top5, ch_id2)) { _if_result_24 = (0); } else { _if_result_24 = (1); } _if_result_24; })); } _if_result_23; }); el_val_t ch2 = ({ el_val_t _if_result_24 = 0; if (str_eq(ch_id2, EL_STR(""))) { _if_result_24 = (0); } else { _if_result_24 = (({ el_val_t _if_result_25 = 0; if (str_contains(prev_top5, ch_id2)) { _if_result_25 = (0); } else { _if_result_25 = (1); } _if_result_25; })); } _if_result_24; });
el_val_t ch3 = ({ el_val_t _if_result_25 = 0; if (str_eq(ch_id3, EL_STR(""))) { _if_result_25 = (0); } else { _if_result_25 = (({ el_val_t _if_result_26 = 0; if (str_contains(prev_top5, ch_id3)) { _if_result_26 = (0); } else { _if_result_26 = (1); } _if_result_26; })); } _if_result_25; }); el_val_t ch3 = ({ el_val_t _if_result_26 = 0; if (str_eq(ch_id3, EL_STR(""))) { _if_result_26 = (0); } else { _if_result_26 = (({ el_val_t _if_result_27 = 0; if (str_contains(prev_top5, ch_id3)) { _if_result_27 = (0); } else { _if_result_27 = (1); } _if_result_27; })); } _if_result_26; });
el_val_t ch4 = ({ el_val_t _if_result_27 = 0; if (str_eq(ch_id4, EL_STR(""))) { _if_result_27 = (0); } else { _if_result_27 = (({ el_val_t _if_result_28 = 0; if (str_contains(prev_top5, ch_id4)) { _if_result_28 = (0); } else { _if_result_28 = (1); } _if_result_28; })); } _if_result_27; }); el_val_t ch4 = ({ el_val_t _if_result_28 = 0; if (str_eq(ch_id4, EL_STR(""))) { _if_result_28 = (0); } else { _if_result_28 = (({ el_val_t _if_result_29 = 0; if (str_contains(prev_top5, ch_id4)) { _if_result_29 = (0); } else { _if_result_29 = (1); } _if_result_29; })); } _if_result_28; });
el_val_t wm_churn = ((((ch0 + ch1) + ch2) + ch3) + ch4); el_val_t wm_churn = ((((ch0 + ch1) + ch2) + ch3) + ch4);
state_set(EL_STR("soul.prev_wm_top5"), el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(wm_top0_id, EL_STR("|")), ch_id1), EL_STR("|")), ch_id2), EL_STR("|")), ch_id3), EL_STR("|")), ch_id4)); state_set(EL_STR("soul.prev_wm_top5"), el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(wm_top0_id, EL_STR("|")), ch_id1), EL_STR("|")), ch_id2), EL_STR("|")), ch_id3), EL_STR("|")), ch_id4));
el_val_t wm_top0_wm_raw = json_get(wm_top0, EL_STR("wm")); el_val_t wm_top0_wm_raw = json_get(wm_top0, EL_STR("wm"));
el_val_t wm_top0_wm = ({ el_val_t _if_result_29 = 0; if (str_eq(wm_top0_wm_raw, EL_STR(""))) { _if_result_29 = (EL_STR("0")); } else { _if_result_29 = (wm_top0_wm_raw); } _if_result_29; }); el_val_t wm_top0_wm = ({ el_val_t _if_result_30 = 0; if (str_eq(wm_top0_wm_raw, EL_STR(""))) { _if_result_30 = (EL_STR("0")); } else { _if_result_30 = (wm_top0_wm_raw); } _if_result_30; });
el_val_t act_stats = engram_act_stats_json(); el_val_t act_stats = engram_act_stats_json();
el_val_t act_evict_raw = json_get(act_stats, EL_STR("wm_evicted")); el_val_t act_evict_raw = json_get(act_stats, EL_STR("wm_evicted"));
el_val_t act_evict = ({ el_val_t _if_result_30 = 0; if (str_eq(act_evict_raw, EL_STR(""))) { _if_result_30 = (EL_STR("-1")); } else { _if_result_30 = (act_evict_raw); } _if_result_30; }); el_val_t act_evict = ({ el_val_t _if_result_31 = 0; if (str_eq(act_evict_raw, EL_STR(""))) { _if_result_31 = (EL_STR("-1")); } else { _if_result_31 = (act_evict_raw); } _if_result_31; });
el_val_t act_bt_raw = json_get(act_stats, EL_STR("breakthroughs")); el_val_t act_bt_raw = json_get(act_stats, EL_STR("breakthroughs"));
el_val_t act_bt = ({ el_val_t _if_result_31 = 0; if (str_eq(act_bt_raw, EL_STR(""))) { _if_result_31 = (EL_STR("-1")); } else { _if_result_31 = (act_bt_raw); } _if_result_31; }); el_val_t act_bt = ({ el_val_t _if_result_32 = 0; if (str_eq(act_bt_raw, EL_STR(""))) { _if_result_32 = (EL_STR("-1")); } else { _if_result_32 = (act_bt_raw); } _if_result_32; });
el_val_t act_brk_raw = json_get(act_stats, EL_STR("embed_breaker_open")); el_val_t act_brk_raw = json_get(act_stats, EL_STR("embed_breaker_open"));
el_val_t act_brk = ({ el_val_t _if_result_32 = 0; if (str_eq(act_brk_raw, EL_STR(""))) { _if_result_32 = (EL_STR("-1")); } else { _if_result_32 = (act_brk_raw); } _if_result_32; }); el_val_t act_brk = ({ el_val_t _if_result_33 = 0; if (str_eq(act_brk_raw, EL_STR(""))) { _if_result_33 = (EL_STR("-1")); } else { _if_result_33 = (act_brk_raw); } _if_result_33; });
el_val_t payload = 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_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_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_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_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\":\"heartbeat\",\"pulse\":"), pulse), EL_STR(",\"tick\":")), pulse), EL_STR(",\"boot\":")), boot), EL_STR(",\"idle\":")), idle), EL_STR(",\"node_count\":")), int_to_str(nc)), EL_STR(",\"edge_count\":")), int_to_str(ec)), EL_STR(",\"node_delta\":")), int_to_str(node_delta)), EL_STR(",\"edge_delta\":")), int_to_str(edge_delta)), EL_STR(",\"wm_active\":")), int_to_str(wmc)), EL_STR(",\"wm_delta\":")), int_to_str(wm_delta)), EL_STR(",\"wm_saturated\":")), int_to_str(wm_sat)), EL_STR(",\"wm_top0_streak\":")), int_to_str(t0streak)), EL_STR(",\"wm_churn\":")), int_to_str(wm_churn)), EL_STR(",\"wm_top0_wm\":")), wm_top0_wm), EL_STR(",\"sync_added_total\":")), sat_str), EL_STR(",\"sync_age_ms\":")), int_to_str(sync_age)), EL_STR(",\"wm_avg_weight\":")), wm_avg_str), EL_STR(",\"wm_top\":")), wm_top), EL_STR(",\"ts\":")), int_to_str(ts)), EL_STR(",\"uptime_ms\":")), int_to_str(up_ms)), EL_STR(",\"uptime\":\"")), up_human), EL_STR("\",\"embed_ok\":")), int_to_str(emb_ok)), EL_STR(",\"embed_backfilled\":")), bf_done), EL_STR(",\"embed_count\":")), bf_total), EL_STR(",\"wm_evicted\":")), act_evict), EL_STR(",\"breakthroughs\":")), act_bt), EL_STR(",\"embed_breaker_open\":")), act_brk), EL_STR(",\"ise_fail\":")), fail_str), EL_STR("}")); el_val_t ctx_cos_raw = json_get(act_stats, EL_STR("ctx_cos"));
el_val_t ctx_cos = ({ el_val_t _if_result_34 = 0; if (str_eq(ctx_cos_raw, EL_STR(""))) { _if_result_34 = (EL_STR("-2")); } else { _if_result_34 = (ctx_cos_raw); } _if_result_34; });
el_val_t payload = 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_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_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_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_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\":\"heartbeat\",\"pulse\":"), pulse), EL_STR(",\"tick\":")), pulse), EL_STR(",\"boot\":")), boot), EL_STR(",\"idle\":")), idle), EL_STR(",\"idle_ms\":")), int_to_str(idle_ms)), EL_STR(",\"node_count\":")), int_to_str(nc)), EL_STR(",\"edge_count\":")), int_to_str(ec)), EL_STR(",\"node_delta\":")), int_to_str(node_delta)), EL_STR(",\"edge_delta\":")), int_to_str(edge_delta)), EL_STR(",\"wm_active\":")), int_to_str(wmc)), EL_STR(",\"wm_delta\":")), int_to_str(wm_delta)), EL_STR(",\"wm_saturated\":")), int_to_str(wm_sat)), EL_STR(",\"wm_top0_streak\":")), int_to_str(t0streak)), EL_STR(",\"wm_churn\":")), int_to_str(wm_churn)), EL_STR(",\"wm_top0_wm\":")), wm_top0_wm), EL_STR(",\"sync_added_total\":")), sat_str), EL_STR(",\"sync_age_ms\":")), int_to_str(sync_age)), EL_STR(",\"wm_avg_weight\":")), wm_avg_str), EL_STR(",\"wm_top\":")), wm_top), EL_STR(",\"ts\":")), int_to_str(ts)), EL_STR(",\"uptime_ms\":")), int_to_str(up_ms)), EL_STR(",\"uptime\":\"")), up_human), EL_STR("\",\"embed_ok\":")), int_to_str(emb_ok)), EL_STR(",\"embed_backfilled\":")), bf_done), EL_STR(",\"embed_count\":")), bf_total), EL_STR(",\"wm_evicted\":")), act_evict), EL_STR(",\"breakthroughs\":")), act_bt), EL_STR(",\"embed_breaker_open\":")), act_brk), EL_STR(",\"ctx_cos\":")), ctx_cos), EL_STR(",\"ise_fail\":")), fail_str), EL_STR("}"));
ise_post(payload); ise_post(payload);
return 0; return 0;
} }
@@ -249,6 +253,10 @@ el_val_t auto_term_try_slot(el_val_t slot_type, el_val_t slot_lbl) {
if (str_eq(term, EL_STR("Value"))) { if (str_eq(term, EL_STR("Value"))) {
state_set(EL_STR("_ats_gw"), EL_STR("1")); state_set(EL_STR("_ats_gw"), EL_STR("1"));
} }
el_val_t stopw = EL_STR("|What|When|Where|Which|Whose|While|This|That|These|Those|There|Their|Then|Than|With|Without|From|Into|Onto|Over|Under|About|Between|Among|Across|Some|Most|More|Less|Very|Each|Every|Both|Also|Only|Just|Does|Will|Would|Could|Should|Might|Must|Have|Been|Being|Toward|Towards|Using|Based|Upon|Here|Your|Ours|They|Them|what|this|that|with|from|context|Context|Prose|Colon|Self|Test|Testing|Closing|Global|Universal|Persona|Semantic|Spreading|Temporal|Numeric|Register|Identifying|Introduction|Overview|Summary|Section|General|Notes|Note|");
if (str_contains(stopw, el_str_concat(el_str_concat(EL_STR("|"), term), EL_STR("|")))) {
state_set(EL_STR("_ats_gw"), EL_STR("1"));
}
if (str_contains(term, EL_STR("\""))) { if (str_contains(term, EL_STR("\""))) {
state_set(EL_STR("_ats_gw"), EL_STR("1")); state_set(EL_STR("_ats_gw"), EL_STR("1"));
} }
@@ -340,14 +348,14 @@ el_val_t proactive_curiosity(void) {
auto_term_try_slot(json_get(wm10_n1, EL_STR("node_type")), json_get(wm10_n1, EL_STR("label"))); auto_term_try_slot(json_get(wm10_n1, EL_STR("node_type")), json_get(wm10_n1, EL_STR("label")));
auto_term_try_slot(json_get(wm10_n0, EL_STR("node_type")), json_get(wm10_n0, EL_STR("label"))); auto_term_try_slot(json_get(wm10_n0, EL_STR("node_type")), json_get(wm10_n0, EL_STR("label")));
el_val_t auto_term = state_get(EL_STR("cseed_auto")); el_val_t auto_term = state_get(EL_STR("cseed_auto"));
el_val_t results_auto = ({ el_val_t _if_result_33 = 0; if (str_eq(auto_term, EL_STR(""))) { _if_result_33 = (EL_STR("[]")); } else { _if_result_33 = (engram_activate_json(auto_term, 1)); } _if_result_33; }); el_val_t results_auto = ({ el_val_t _if_result_35 = 0; if (str_eq(auto_term, EL_STR(""))) { _if_result_35 = (EL_STR("[]")); } else { _if_result_35 = (engram_activate_json(auto_term, 1)); } _if_result_35; });
el_val_t found_auto = json_array_len(results_auto); el_val_t found_auto = json_array_len(results_auto);
el_val_t total_found = (found + found_auto); el_val_t total_found = (found + found_auto);
el_val_t safe_auto = str_replace(auto_term, EL_STR("\""), EL_STR("'")); el_val_t safe_auto = str_replace(auto_term, EL_STR("\""), EL_STR("'"));
el_val_t prev_auto = state_get(EL_STR("soul.prev_auto_term")); el_val_t prev_auto = state_get(EL_STR("soul.prev_auto_term"));
el_val_t atstreak_raw = state_get(EL_STR("soul.auto_term_streak")); el_val_t atstreak_raw = state_get(EL_STR("soul.auto_term_streak"));
el_val_t atstreak_prev = ({ el_val_t _if_result_34 = 0; if (str_eq(atstreak_raw, EL_STR(""))) { _if_result_34 = (0); } else { _if_result_34 = (str_to_int(atstreak_raw)); } _if_result_34; }); el_val_t atstreak_prev = ({ el_val_t _if_result_36 = 0; if (str_eq(atstreak_raw, EL_STR(""))) { _if_result_36 = (0); } else { _if_result_36 = (str_to_int(atstreak_raw)); } _if_result_36; });
el_val_t atstreak = ({ el_val_t _if_result_35 = 0; if (str_eq(auto_term, prev_auto)) { _if_result_35 = ((atstreak_prev + 1)); } else { _if_result_35 = (1); } _if_result_35; }); el_val_t atstreak = ({ el_val_t _if_result_37 = 0; if (str_eq(auto_term, prev_auto)) { _if_result_37 = ((atstreak_prev + 1)); } else { _if_result_37 = (1); } _if_result_37; });
state_set(EL_STR("soul.prev_auto_term"), auto_term); state_set(EL_STR("soul.prev_auto_term"), auto_term);
state_set(EL_STR("soul.auto_term_streak"), int_to_str(atstreak)); state_set(EL_STR("soul.auto_term_streak"), int_to_str(atstreak));
if (!str_eq(auto_term, EL_STR(""))) { if (!str_eq(auto_term, EL_STR(""))) {
@@ -541,16 +549,16 @@ el_val_t awareness_run(void) {
state_set(EL_STR("soul.boot_ts"), int_to_str(time_now())); 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_raw = env(EL_STR("SOUL_TICK_MS"));
el_val_t tick_ms = ({ el_val_t _if_result_36 = 0; if (str_eq(tick_raw, EL_STR(""))) { _if_result_36 = (200); } else { _if_result_36 = (str_to_int(tick_raw)); } _if_result_36; }); el_val_t tick_ms = ({ el_val_t _if_result_38 = 0; if (str_eq(tick_raw, EL_STR(""))) { _if_result_38 = (200); } else { _if_result_38 = (str_to_int(tick_raw)); } _if_result_38; });
el_val_t beat_ms_raw = env(EL_STR("SOUL_HEARTBEAT_MS")); el_val_t beat_ms_raw = env(EL_STR("SOUL_HEARTBEAT_MS"));
el_val_t beat_ms = ({ el_val_t _if_result_37 = 0; if (str_eq(beat_ms_raw, EL_STR(""))) { _if_result_37 = (60000); } else { _if_result_37 = (str_to_int(beat_ms_raw)); } _if_result_37; }); el_val_t beat_ms = ({ el_val_t _if_result_39 = 0; if (str_eq(beat_ms_raw, EL_STR(""))) { _if_result_39 = (60000); } else { _if_result_39 = (str_to_int(beat_ms_raw)); } _if_result_39; });
el_val_t scan_ms = (beat_ms / 2); el_val_t scan_ms = (beat_ms / 2);
while (1) { while (1) {
el_val_t tick_mark = el_arena_push(); el_val_t tick_mark = el_arena_push();
el_val_t running = state_get(EL_STR("soul.running")); el_val_t running = state_get(EL_STR("soul.running"));
if (str_eq(running, EL_STR("false"))) { if (str_eq(running, EL_STR("false"))) {
el_val_t sd_boot_raw = state_get(EL_STR("soul_boot_count")); el_val_t sd_boot_raw = state_get(EL_STR("soul_boot_count"));
el_val_t sd_boot = ({ el_val_t _if_result_38 = 0; if (str_eq(sd_boot_raw, EL_STR(""))) { _if_result_38 = (EL_STR("0")); } else { _if_result_38 = (sd_boot_raw); } _if_result_38; }); el_val_t sd_boot = ({ el_val_t _if_result_40 = 0; if (str_eq(sd_boot_raw, EL_STR(""))) { _if_result_40 = (EL_STR("0")); } else { _if_result_40 = (sd_boot_raw); } _if_result_40; });
ise_post(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\":\"shutdown\",\"boot\":"), sd_boot), EL_STR(",\"pulse\":")), int_to_str(pulse_count())), EL_STR(",\"uptime_ms\":")), int_to_str(elapsed_ms())), EL_STR(",\"ts\":")), int_to_str(time_now())), EL_STR("}"))); ise_post(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\":\"shutdown\",\"boot\":"), sd_boot), EL_STR(",\"pulse\":")), int_to_str(pulse_count())), EL_STR(",\"uptime_ms\":")), int_to_str(elapsed_ms())), EL_STR(",\"ts\":")), int_to_str(time_now())), EL_STR("}")));
println(EL_STR("[awareness] exiting")); println(EL_STR("[awareness] exiting"));
el_arena_pop(tick_mark); el_arena_pop(tick_mark);
@@ -566,7 +574,7 @@ el_val_t awareness_run(void) {
} }
el_val_t now_ts = time_now(); el_val_t now_ts = time_now();
el_val_t last_beat_str = state_get(EL_STR("soul.last_beat_ts")); el_val_t last_beat_str = state_get(EL_STR("soul.last_beat_ts"));
el_val_t last_beat_ts = ({ el_val_t _if_result_39 = 0; if (str_eq(last_beat_str, EL_STR(""))) { _if_result_39 = (0); } else { _if_result_39 = (str_to_int(last_beat_str)); } _if_result_39; }); el_val_t last_beat_ts = ({ el_val_t _if_result_41 = 0; if (str_eq(last_beat_str, EL_STR(""))) { _if_result_41 = (0); } else { _if_result_41 = (str_to_int(last_beat_str)); } _if_result_41; });
el_val_t beat_elapsed = (now_ts - last_beat_ts); el_val_t beat_elapsed = (now_ts - last_beat_ts);
el_val_t should_beat = (beat_elapsed >= beat_ms); el_val_t should_beat = (beat_elapsed >= beat_ms);
if (should_beat) { if (should_beat) {
@@ -578,7 +586,7 @@ el_val_t awareness_run(void) {
} }
} }
el_val_t last_scan_str = state_get(EL_STR("soul.last_scan_ts")); el_val_t last_scan_str = state_get(EL_STR("soul.last_scan_ts"));
el_val_t last_scan_ts = ({ el_val_t _if_result_40 = 0; if (str_eq(last_scan_str, EL_STR(""))) { _if_result_40 = (0); } else { _if_result_40 = (str_to_int(last_scan_str)); } _if_result_40; }); el_val_t last_scan_ts = ({ el_val_t _if_result_42 = 0; if (str_eq(last_scan_str, EL_STR(""))) { _if_result_42 = (0); } else { _if_result_42 = (str_to_int(last_scan_str)); } _if_result_42; });
el_val_t scan_elapsed = (now_ts - last_scan_ts); el_val_t scan_elapsed = (now_ts - last_scan_ts);
el_val_t should_scan = (!did_work && (scan_elapsed >= scan_ms)); el_val_t should_scan = (!did_work && (scan_elapsed >= scan_ms));
if (should_scan) { if (should_scan) {
@@ -586,15 +594,15 @@ el_val_t awareness_run(void) {
state_set(EL_STR("soul.last_scan_ts"), int_to_str(now_ts)); state_set(EL_STR("soul.last_scan_ts"), int_to_str(now_ts));
} }
el_val_t refresh_ms_raw = env(EL_STR("SOUL_REFRESH_MS")); el_val_t refresh_ms_raw = env(EL_STR("SOUL_REFRESH_MS"));
el_val_t refresh_ms = ({ el_val_t _if_result_41 = 0; if (str_eq(refresh_ms_raw, EL_STR(""))) { _if_result_41 = (600000); } else { _if_result_41 = (str_to_int(refresh_ms_raw)); } _if_result_41; }); el_val_t refresh_ms = ({ el_val_t _if_result_43 = 0; if (str_eq(refresh_ms_raw, EL_STR(""))) { _if_result_43 = (600000); } else { _if_result_43 = (str_to_int(refresh_ms_raw)); } _if_result_43; });
el_val_t last_refresh_str = state_get(EL_STR("soul.last_refresh_ts")); el_val_t last_refresh_str = state_get(EL_STR("soul.last_refresh_ts"));
el_val_t last_refresh_ts = ({ el_val_t _if_result_42 = 0; if (str_eq(last_refresh_str, EL_STR(""))) { _if_result_42 = (0); } else { _if_result_42 = (str_to_int(last_refresh_str)); } _if_result_42; }); el_val_t last_refresh_ts = ({ el_val_t _if_result_44 = 0; if (str_eq(last_refresh_str, EL_STR(""))) { _if_result_44 = (0); } else { _if_result_44 = (str_to_int(last_refresh_str)); } _if_result_44; });
el_val_t refresh_elapsed = (now_ts - last_refresh_ts); el_val_t refresh_elapsed = (now_ts - last_refresh_ts);
el_val_t should_refresh = (refresh_elapsed >= refresh_ms); el_val_t should_refresh = (refresh_elapsed >= refresh_ms);
if (should_refresh) { if (should_refresh) {
el_val_t sync_env_url = env(EL_STR("SOUL_ISE_URL")); el_val_t sync_env_url = env(EL_STR("SOUL_ISE_URL"));
el_val_t sync_state_url = ({ el_val_t _if_result_43 = 0; if (str_eq(sync_env_url, EL_STR(""))) { _if_result_43 = (state_get(EL_STR("soul_engram_url"))); } else { _if_result_43 = (sync_env_url); } _if_result_43; }); el_val_t sync_state_url = ({ el_val_t _if_result_45 = 0; if (str_eq(sync_env_url, EL_STR(""))) { _if_result_45 = (state_get(EL_STR("soul_engram_url"))); } else { _if_result_45 = (sync_env_url); } _if_result_45; });
el_val_t engram_url = ({ el_val_t _if_result_44 = 0; if (str_eq(sync_state_url, EL_STR(""))) { _if_result_44 = (EL_STR("http://localhost:8742")); } else { _if_result_44 = (sync_state_url); } _if_result_44; }); el_val_t engram_url = ({ el_val_t _if_result_46 = 0; if (str_eq(sync_state_url, EL_STR(""))) { _if_result_46 = (EL_STR("http://localhost:8742")); } else { _if_result_46 = (sync_state_url); } _if_result_46; });
if (!str_eq(engram_url, EL_STR(""))) { if (!str_eq(engram_url, EL_STR(""))) {
el_val_t sync_json = http_get(el_str_concat(engram_url, EL_STR("/api/sync"))); el_val_t sync_json = http_get(el_str_concat(engram_url, EL_STR("/api/sync")));
el_val_t sync_ok = (!str_eq(sync_json, EL_STR("")) && !str_eq(sync_json, EL_STR("{}"))); el_val_t sync_ok = (!str_eq(sync_json, EL_STR("")) && !str_eq(sync_json, EL_STR("{}")));
@@ -607,10 +615,10 @@ el_val_t awareness_run(void) {
fs_write(tmp, sync_json); fs_write(tmp, sync_json);
el_val_t added = engram_load_merge(tmp); el_val_t added = engram_load_merge(tmp);
el_val_t ret_raw = env(EL_STR("ENGRAM_ISE_RETENTION_MS")); el_val_t ret_raw = env(EL_STR("ENGRAM_ISE_RETENTION_MS"));
el_val_t ret_ms = ({ el_val_t _if_result_45 = 0; if (str_eq(ret_raw, EL_STR(""))) { _if_result_45 = (172800000); } else { _if_result_45 = (str_to_int(ret_raw)); } _if_result_45; }); el_val_t ret_ms = ({ el_val_t _if_result_47 = 0; if (str_eq(ret_raw, EL_STR(""))) { _if_result_47 = (172800000); } else { _if_result_47 = (str_to_int(ret_raw)); } _if_result_47; });
el_val_t pruned_sync = engram_prune_telemetry(ret_ms); el_val_t pruned_sync = engram_prune_telemetry(ret_ms);
el_val_t sat_raw = state_get(EL_STR("soul.sync_added_total")); el_val_t sat_raw = state_get(EL_STR("soul.sync_added_total"));
el_val_t sat_n = ({ el_val_t _if_result_46 = 0; if (str_eq(sat_raw, EL_STR(""))) { _if_result_46 = (0); } else { _if_result_46 = (str_to_int(sat_raw)); } _if_result_46; }); el_val_t sat_n = ({ el_val_t _if_result_48 = 0; if (str_eq(sat_raw, EL_STR(""))) { _if_result_48 = (0); } else { _if_result_48 = (str_to_int(sat_raw)); } _if_result_48; });
state_set(EL_STR("soul.sync_added_total"), int_to_str((sat_n + added))); state_set(EL_STR("soul.sync_added_total"), int_to_str((sat_n + added)));
el_val_t ts2 = time_now(); el_val_t ts2 = time_now();
state_set(EL_STR("soul.last_sync_ok_ts"), int_to_str(ts2)); state_set(EL_STR("soul.last_sync_ok_ts"), int_to_str(ts2));
@@ -636,78 +644,78 @@ el_val_t security_research_authorized(void) {
} }
el_val_t threat_score_command(el_val_t cmd) { el_val_t threat_score_command(el_val_t cmd) {
el_val_t s1 = ({ el_val_t _if_result_47 = 0; if (str_contains(cmd, EL_STR("nmap"))) { _if_result_47 = (30); } else { _if_result_47 = (0); } _if_result_47; }); el_val_t s1 = ({ el_val_t _if_result_49 = 0; if (str_contains(cmd, EL_STR("nmap"))) { _if_result_49 = (30); } else { _if_result_49 = (0); } _if_result_49; });
el_val_t s2 = ({ el_val_t _if_result_48 = 0; if (str_contains(cmd, EL_STR("masscan"))) { _if_result_48 = (40); } else { _if_result_48 = (0); } _if_result_48; }); el_val_t s2 = ({ el_val_t _if_result_50 = 0; if (str_contains(cmd, EL_STR("masscan"))) { _if_result_50 = (40); } else { _if_result_50 = (0); } _if_result_50; });
el_val_t s3 = ({ el_val_t _if_result_49 = 0; if (str_contains(cmd, EL_STR(" nc "))) { _if_result_49 = (20); } else { _if_result_49 = (0); } _if_result_49; }); el_val_t s3 = ({ el_val_t _if_result_51 = 0; if (str_contains(cmd, EL_STR(" nc "))) { _if_result_51 = (20); } else { _if_result_51 = (0); } _if_result_51; });
el_val_t s4 = ({ el_val_t _if_result_50 = 0; if (str_contains(cmd, EL_STR("netcat"))) { _if_result_50 = (20); } else { _if_result_50 = (0); } _if_result_50; }); el_val_t s4 = ({ el_val_t _if_result_52 = 0; if (str_contains(cmd, EL_STR("netcat"))) { _if_result_52 = (20); } else { _if_result_52 = (0); } _if_result_52; });
el_val_t s5 = ({ el_val_t _if_result_51 = 0; if (str_contains(cmd, EL_STR("/etc/shadow"))) { _if_result_51 = (80); } else { _if_result_51 = (0); } _if_result_51; }); el_val_t s5 = ({ el_val_t _if_result_53 = 0; if (str_contains(cmd, EL_STR("/etc/shadow"))) { _if_result_53 = (80); } else { _if_result_53 = (0); } _if_result_53; });
el_val_t s6 = ({ el_val_t _if_result_52 = 0; if (str_contains(cmd, EL_STR("/etc/passwd"))) { _if_result_52 = (30); } else { _if_result_52 = (0); } _if_result_52; }); el_val_t s6 = ({ el_val_t _if_result_54 = 0; if (str_contains(cmd, EL_STR("/etc/passwd"))) { _if_result_54 = (30); } else { _if_result_54 = (0); } _if_result_54; });
el_val_t s7 = ({ el_val_t _if_result_53 = 0; if (str_contains(cmd, EL_STR("id_rsa"))) { _if_result_53 = (60); } else { _if_result_53 = (0); } _if_result_53; }); el_val_t s7 = ({ el_val_t _if_result_55 = 0; if (str_contains(cmd, EL_STR("id_rsa"))) { _if_result_55 = (60); } else { _if_result_55 = (0); } _if_result_55; });
el_val_t s8 = ({ el_val_t _if_result_54 = 0; if (str_contains(cmd, EL_STR(".ssh/"))) { _if_result_54 = (50); } else { _if_result_54 = (0); } _if_result_54; }); el_val_t s8 = ({ el_val_t _if_result_56 = 0; if (str_contains(cmd, EL_STR(".ssh/"))) { _if_result_56 = (50); } else { _if_result_56 = (0); } _if_result_56; });
el_val_t s9 = ({ el_val_t _if_result_55 = 0; if (str_contains(cmd, EL_STR("crontab"))) { _if_result_55 = (30); } else { _if_result_55 = (0); } _if_result_55; }); el_val_t s9 = ({ el_val_t _if_result_57 = 0; if (str_contains(cmd, EL_STR("crontab"))) { _if_result_57 = (30); } else { _if_result_57 = (0); } _if_result_57; });
el_val_t s10 = ({ el_val_t _if_result_56 = 0; if (str_contains(cmd, EL_STR("LaunchDaemon"))) { _if_result_56 = (40); } else { _if_result_56 = (0); } _if_result_56; }); el_val_t s10 = ({ el_val_t _if_result_58 = 0; if (str_contains(cmd, EL_STR("LaunchDaemon"))) { _if_result_58 = (40); } else { _if_result_58 = (0); } _if_result_58; });
el_val_t s11 = ({ el_val_t _if_result_57 = 0; if ((str_contains(cmd, EL_STR("curl")) && str_contains(cmd, EL_STR("bash")))) { _if_result_57 = (75); } else { _if_result_57 = (0); } _if_result_57; }); el_val_t s11 = ({ el_val_t _if_result_59 = 0; if ((str_contains(cmd, EL_STR("curl")) && str_contains(cmd, EL_STR("bash")))) { _if_result_59 = (75); } else { _if_result_59 = (0); } _if_result_59; });
el_val_t s12 = ({ el_val_t _if_result_58 = 0; if ((str_contains(cmd, EL_STR("wget")) && str_contains(cmd, EL_STR("bash")))) { _if_result_58 = (75); } else { _if_result_58 = (0); } _if_result_58; }); el_val_t s12 = ({ el_val_t _if_result_60 = 0; if ((str_contains(cmd, EL_STR("wget")) && str_contains(cmd, EL_STR("bash")))) { _if_result_60 = (75); } else { _if_result_60 = (0); } _if_result_60; });
el_val_t s13 = ({ el_val_t _if_result_59 = 0; if ((str_contains(cmd, EL_STR("curl")) && str_contains(cmd, EL_STR("| sh")))) { _if_result_59 = (60); } else { _if_result_59 = (0); } _if_result_59; }); el_val_t s13 = ({ el_val_t _if_result_61 = 0; if ((str_contains(cmd, EL_STR("curl")) && str_contains(cmd, EL_STR("| sh")))) { _if_result_61 = (60); } else { _if_result_61 = (0); } _if_result_61; });
el_val_t s14 = ({ el_val_t _if_result_60 = 0; if ((str_contains(cmd, EL_STR("base64")) && str_contains(cmd, EL_STR("curl")))) { _if_result_60 = (50); } else { _if_result_60 = (0); } _if_result_60; }); el_val_t s14 = ({ el_val_t _if_result_62 = 0; if ((str_contains(cmd, EL_STR("base64")) && str_contains(cmd, EL_STR("curl")))) { _if_result_62 = (50); } else { _if_result_62 = (0); } _if_result_62; });
el_val_t s15 = ({ el_val_t _if_result_61 = 0; if (str_contains(cmd, EL_STR("mkfifo"))) { _if_result_61 = (50); } else { _if_result_61 = (0); } _if_result_61; }); el_val_t s15 = ({ el_val_t _if_result_63 = 0; if (str_contains(cmd, EL_STR("mkfifo"))) { _if_result_63 = (50); } else { _if_result_63 = (0); } _if_result_63; });
el_val_t s16 = ({ el_val_t _if_result_62 = 0; if (str_contains(cmd, EL_STR("chmod +s"))) { _if_result_62 = (70); } else { _if_result_62 = (0); } _if_result_62; }); el_val_t s16 = ({ el_val_t _if_result_64 = 0; if (str_contains(cmd, EL_STR("chmod +s"))) { _if_result_64 = (70); } else { _if_result_64 = (0); } _if_result_64; });
el_val_t s17 = ({ el_val_t _if_result_63 = 0; if (str_contains(cmd, EL_STR("chmod 4755"))) { _if_result_63 = (70); } else { _if_result_63 = (0); } _if_result_63; }); el_val_t s17 = ({ el_val_t _if_result_65 = 0; if (str_contains(cmd, EL_STR("chmod 4755"))) { _if_result_65 = (70); } else { _if_result_65 = (0); } _if_result_65; });
return ((((((((((((((((s1 + s2) + s3) + s4) + s5) + s6) + s7) + s8) + s9) + s10) + s11) + s12) + s13) + s14) + s15) + s16) + s17); return ((((((((((((((((s1 + s2) + s3) + s4) + s5) + s6) + s7) + s8) + s9) + s10) + s11) + s12) + s13) + s14) + s15) + s16) + s17);
return 0; return 0;
} }
el_val_t threat_score_path(el_val_t path) { el_val_t threat_score_path(el_val_t path) {
el_val_t s1 = ({ el_val_t _if_result_64 = 0; if (str_starts_with(path, EL_STR("/etc/"))) { _if_result_64 = (60); } else { _if_result_64 = (0); } _if_result_64; }); el_val_t s1 = ({ el_val_t _if_result_66 = 0; if (str_starts_with(path, EL_STR("/etc/"))) { _if_result_66 = (60); } else { _if_result_66 = (0); } _if_result_66; });
el_val_t s2 = ({ el_val_t _if_result_65 = 0; if (str_contains(path, EL_STR("/.ssh/"))) { _if_result_65 = (70); } else { _if_result_65 = (0); } _if_result_65; }); el_val_t s2 = ({ el_val_t _if_result_67 = 0; if (str_contains(path, EL_STR("/.ssh/"))) { _if_result_67 = (70); } else { _if_result_67 = (0); } _if_result_67; });
el_val_t s3 = ({ el_val_t _if_result_66 = 0; if (str_contains(path, EL_STR("/LaunchDaemons/"))) { _if_result_66 = (80); } else { _if_result_66 = (0); } _if_result_66; }); el_val_t s3 = ({ el_val_t _if_result_68 = 0; if (str_contains(path, EL_STR("/LaunchDaemons/"))) { _if_result_68 = (80); } else { _if_result_68 = (0); } _if_result_68; });
el_val_t s4 = ({ el_val_t _if_result_67 = 0; if (str_contains(path, EL_STR("/LaunchAgents/"))) { _if_result_67 = (40); } else { _if_result_67 = (0); } _if_result_67; }); el_val_t s4 = ({ el_val_t _if_result_69 = 0; if (str_contains(path, EL_STR("/LaunchAgents/"))) { _if_result_69 = (40); } else { _if_result_69 = (0); } _if_result_69; });
el_val_t s5 = ({ el_val_t _if_result_68 = 0; if (str_contains(path, EL_STR("/cron"))) { _if_result_68 = (60); } else { _if_result_68 = (0); } _if_result_68; }); el_val_t s5 = ({ el_val_t _if_result_70 = 0; if (str_contains(path, EL_STR("/cron"))) { _if_result_70 = (60); } else { _if_result_70 = (0); } _if_result_70; });
el_val_t s6 = ({ el_val_t _if_result_69 = 0; if (str_contains(path, EL_STR("/.bashrc"))) { _if_result_69 = (35); } else { _if_result_69 = (0); } _if_result_69; }); el_val_t s6 = ({ el_val_t _if_result_71 = 0; if (str_contains(path, EL_STR("/.bashrc"))) { _if_result_71 = (35); } else { _if_result_71 = (0); } _if_result_71; });
el_val_t s7 = ({ el_val_t _if_result_70 = 0; if (str_contains(path, EL_STR("/.zshrc"))) { _if_result_70 = (35); } else { _if_result_70 = (0); } _if_result_70; }); el_val_t s7 = ({ el_val_t _if_result_72 = 0; if (str_contains(path, EL_STR("/.zshrc"))) { _if_result_72 = (35); } else { _if_result_72 = (0); } _if_result_72; });
el_val_t s8 = ({ el_val_t _if_result_71 = 0; if (str_contains(path, EL_STR("/.profile"))) { _if_result_71 = (35); } else { _if_result_71 = (0); } _if_result_71; }); el_val_t s8 = ({ el_val_t _if_result_73 = 0; if (str_contains(path, EL_STR("/.profile"))) { _if_result_73 = (35); } else { _if_result_73 = (0); } _if_result_73; });
el_val_t s9 = ({ el_val_t _if_result_72 = 0; if (str_starts_with(path, EL_STR("/usr/"))) { _if_result_72 = (50); } else { _if_result_72 = (0); } _if_result_72; }); el_val_t s9 = ({ el_val_t _if_result_74 = 0; if (str_starts_with(path, EL_STR("/usr/"))) { _if_result_74 = (50); } else { _if_result_74 = (0); } _if_result_74; });
el_val_t s10 = ({ el_val_t _if_result_73 = 0; if (str_starts_with(path, EL_STR("/bin/"))) { _if_result_73 = (70); } else { _if_result_73 = (0); } _if_result_73; }); el_val_t s10 = ({ el_val_t _if_result_75 = 0; if (str_starts_with(path, EL_STR("/bin/"))) { _if_result_75 = (70); } else { _if_result_75 = (0); } _if_result_75; });
el_val_t s11 = ({ el_val_t _if_result_74 = 0; if (str_starts_with(path, EL_STR("/sbin/"))) { _if_result_74 = (70); } else { _if_result_74 = (0); } _if_result_74; }); el_val_t s11 = ({ el_val_t _if_result_76 = 0; if (str_starts_with(path, EL_STR("/sbin/"))) { _if_result_76 = (70); } else { _if_result_76 = (0); } _if_result_76; });
return ((((((((((s1 + s2) + s3) + s4) + s5) + s6) + s7) + s8) + s9) + s10) + s11); return ((((((((((s1 + s2) + s3) + s4) + s5) + s6) + s7) + s8) + s9) + s10) + s11);
return 0; return 0;
} }
el_val_t threat_score_history(el_val_t history) { el_val_t threat_score_history(el_val_t history) {
el_val_t s1 = ({ el_val_t _if_result_75 = 0; if (str_contains(history, EL_STR("port scan"))) { _if_result_75 = (15); } else { _if_result_75 = (0); } _if_result_75; }); el_val_t s1 = ({ el_val_t _if_result_77 = 0; if (str_contains(history, EL_STR("port scan"))) { _if_result_77 = (15); } else { _if_result_77 = (0); } _if_result_77; });
el_val_t s2 = ({ el_val_t _if_result_76 = 0; if (str_contains(history, EL_STR("enumerate"))) { _if_result_76 = (10); } else { _if_result_76 = (0); } _if_result_76; }); el_val_t s2 = ({ el_val_t _if_result_78 = 0; if (str_contains(history, EL_STR("enumerate"))) { _if_result_78 = (10); } else { _if_result_78 = (0); } _if_result_78; });
el_val_t s3 = ({ el_val_t _if_result_77 = 0; if (str_contains(history, EL_STR("exploit"))) { _if_result_77 = (20); } else { _if_result_77 = (0); } _if_result_77; }); el_val_t s3 = ({ el_val_t _if_result_79 = 0; if (str_contains(history, EL_STR("exploit"))) { _if_result_79 = (20); } else { _if_result_79 = (0); } _if_result_79; });
el_val_t s4 = ({ el_val_t _if_result_78 = 0; if (str_contains(history, EL_STR("payload"))) { _if_result_78 = (15); } else { _if_result_78 = (0); } _if_result_78; }); el_val_t s4 = ({ el_val_t _if_result_80 = 0; if (str_contains(history, EL_STR("payload"))) { _if_result_80 = (15); } else { _if_result_80 = (0); } _if_result_80; });
el_val_t s5 = ({ el_val_t _if_result_79 = 0; if (str_contains(history, EL_STR("persistence"))) { _if_result_79 = (15); } else { _if_result_79 = (0); } _if_result_79; }); el_val_t s5 = ({ el_val_t _if_result_81 = 0; if (str_contains(history, EL_STR("persistence"))) { _if_result_81 = (15); } else { _if_result_81 = (0); } _if_result_81; });
el_val_t s6 = ({ el_val_t _if_result_80 = 0; if (str_contains(history, EL_STR("lateral movement"))) { _if_result_80 = (25); } else { _if_result_80 = (0); } _if_result_80; }); el_val_t s6 = ({ el_val_t _if_result_82 = 0; if (str_contains(history, EL_STR("lateral movement"))) { _if_result_82 = (25); } else { _if_result_82 = (0); } _if_result_82; });
el_val_t s7 = ({ el_val_t _if_result_81 = 0; if (str_contains(history, EL_STR("privilege escalation"))) { _if_result_81 = (25); } else { _if_result_81 = (0); } _if_result_81; }); el_val_t s7 = ({ el_val_t _if_result_83 = 0; if (str_contains(history, EL_STR("privilege escalation"))) { _if_result_83 = (25); } else { _if_result_83 = (0); } _if_result_83; });
el_val_t s8 = ({ el_val_t _if_result_82 = 0; if (str_contains(history, EL_STR("reverse shell"))) { _if_result_82 = (40); } else { _if_result_82 = (0); } _if_result_82; }); el_val_t s8 = ({ el_val_t _if_result_84 = 0; if (str_contains(history, EL_STR("reverse shell"))) { _if_result_84 = (40); } else { _if_result_84 = (0); } _if_result_84; });
el_val_t s9 = ({ el_val_t _if_result_83 = 0; if (str_contains(history, EL_STR("bind shell"))) { _if_result_83 = (40); } else { _if_result_83 = (0); } _if_result_83; }); el_val_t s9 = ({ el_val_t _if_result_85 = 0; if (str_contains(history, EL_STR("bind shell"))) { _if_result_85 = (40); } else { _if_result_85 = (0); } _if_result_85; });
el_val_t s10 = ({ el_val_t _if_result_84 = 0; if (str_contains(history, EL_STR("command and control"))) { _if_result_84 = (35); } else { _if_result_84 = (0); } _if_result_84; }); el_val_t s10 = ({ el_val_t _if_result_86 = 0; if (str_contains(history, EL_STR("command and control"))) { _if_result_86 = (35); } else { _if_result_86 = (0); } _if_result_86; });
el_val_t s11 = ({ el_val_t _if_result_85 = 0; if (str_contains(history, EL_STR("self-replicate"))) { _if_result_85 = (45); } else { _if_result_85 = (0); } _if_result_85; }); el_val_t s11 = ({ el_val_t _if_result_87 = 0; if (str_contains(history, EL_STR("self-replicate"))) { _if_result_87 = (45); } else { _if_result_87 = (0); } _if_result_87; });
el_val_t s12 = ({ el_val_t _if_result_86 = 0; if (str_contains(history, EL_STR("propagat"))) { _if_result_86 = (20); } else { _if_result_86 = (0); } _if_result_86; }); el_val_t s12 = ({ el_val_t _if_result_88 = 0; if (str_contains(history, EL_STR("propagat"))) { _if_result_88 = (20); } else { _if_result_88 = (0); } _if_result_88; });
el_val_t s13 = ({ el_val_t _if_result_87 = 0; if (str_contains(history, EL_STR("ransomware"))) { _if_result_87 = (30); } else { _if_result_87 = (0); } _if_result_87; }); el_val_t s13 = ({ el_val_t _if_result_89 = 0; if (str_contains(history, EL_STR("ransomware"))) { _if_result_89 = (30); } else { _if_result_89 = (0); } _if_result_89; });
el_val_t s14 = ({ el_val_t _if_result_88 = 0; if (str_contains(history, EL_STR("encrypt files"))) { _if_result_88 = (40); } else { _if_result_88 = (0); } _if_result_88; }); el_val_t s14 = ({ el_val_t _if_result_90 = 0; if (str_contains(history, EL_STR("encrypt files"))) { _if_result_90 = (40); } else { _if_result_90 = (0); } _if_result_90; });
el_val_t s15 = ({ el_val_t _if_result_89 = 0; if (str_contains(history, EL_STR("exfiltrat"))) { _if_result_89 = (35); } else { _if_result_89 = (0); } _if_result_89; }); el_val_t s15 = ({ el_val_t _if_result_91 = 0; if (str_contains(history, EL_STR("exfiltrat"))) { _if_result_91 = (35); } else { _if_result_91 = (0); } _if_result_91; });
el_val_t s16 = ({ el_val_t _if_result_90 = 0; if (str_contains(history, EL_STR("zero-day"))) { _if_result_90 = (20); } else { _if_result_90 = (0); } _if_result_90; }); el_val_t s16 = ({ el_val_t _if_result_92 = 0; if (str_contains(history, EL_STR("zero-day"))) { _if_result_92 = (20); } else { _if_result_92 = (0); } _if_result_92; });
el_val_t s17 = ({ el_val_t _if_result_91 = 0; if (str_contains(history, EL_STR("rootkit"))) { _if_result_91 = (45); } else { _if_result_91 = (0); } _if_result_91; }); el_val_t s17 = ({ el_val_t _if_result_93 = 0; if (str_contains(history, EL_STR("rootkit"))) { _if_result_93 = (45); } else { _if_result_93 = (0); } _if_result_93; });
el_val_t s18 = ({ el_val_t _if_result_92 = 0; if (str_contains(history, EL_STR("keylogger"))) { _if_result_92 = (45); } else { _if_result_92 = (0); } _if_result_92; }); el_val_t s18 = ({ el_val_t _if_result_94 = 0; if (str_contains(history, EL_STR("keylogger"))) { _if_result_94 = (45); } else { _if_result_94 = (0); } _if_result_94; });
el_val_t s19 = ({ el_val_t _if_result_93 = 0; if (str_contains(history, EL_STR("botnet"))) { _if_result_93 = (40); } else { _if_result_93 = (0); } _if_result_93; }); el_val_t s19 = ({ el_val_t _if_result_95 = 0; if (str_contains(history, EL_STR("botnet"))) { _if_result_95 = (40); } else { _if_result_95 = (0); } _if_result_95; });
el_val_t s20 = ({ el_val_t _if_result_94 = 0; if (str_contains(history, EL_STR("malware"))) { _if_result_94 = (15); } else { _if_result_94 = (0); } _if_result_94; }); el_val_t s20 = ({ el_val_t _if_result_96 = 0; if (str_contains(history, EL_STR("malware"))) { _if_result_96 = (15); } else { _if_result_96 = (0); } _if_result_96; });
return (((((((((((((((((((s1 + s2) + s3) + s4) + s5) + s6) + s7) + s8) + s9) + s10) + s11) + s12) + s13) + s14) + s15) + s16) + s17) + s18) + s19) + s20); return (((((((((((((((((((s1 + s2) + s3) + s4) + s5) + s6) + s7) + s8) + s9) + s10) + s11) + s12) + s13) + s14) + s15) + s16) + s17) + s18) + s19) + s20);
return 0; return 0;
} }
el_val_t threat_trajectory_check(el_val_t tool_name, el_val_t tool_input) { 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 history = state_get(EL_STR("agentic_conv_history"));
el_val_t computed_tool_score = ({ el_val_t _if_result_95 = 0; if (str_eq(tool_name, EL_STR("run_command"))) { el_val_t cmd = json_get(tool_input, EL_STR("command")); _if_result_95 = (threat_score_command(cmd)); } else { _if_result_95 = (({ el_val_t _if_result_96 = 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_96 = (threat_score_path(path)); } else { _if_result_96 = (0); } _if_result_96; })); } _if_result_95; }); el_val_t computed_tool_score = ({ el_val_t _if_result_97 = 0; if (str_eq(tool_name, EL_STR("run_command"))) { el_val_t cmd = json_get(tool_input, EL_STR("command")); _if_result_97 = (threat_score_command(cmd)); } else { _if_result_97 = (({ el_val_t _if_result_98 = 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_98 = (threat_score_path(path)); } else { _if_result_98 = (0); } _if_result_98; })); } _if_result_97; });
el_val_t history_score = threat_score_history(history); el_val_t history_score = threat_score_history(history);
el_val_t history_contrib = (history_score / 3); el_val_t history_contrib = (history_score / 3);
el_val_t combined = (computed_tool_score + history_contrib); el_val_t combined = (computed_tool_score + history_contrib);
el_val_t should_log = (combined >= 40); el_val_t should_log = (combined >= 40);
if (should_log) { if (should_log) {
el_val_t ts = time_now(); el_val_t ts = time_now();
el_val_t authorized_str = ({ el_val_t _if_result_97 = 0; if (security_research_authorized()) { _if_result_97 = (EL_STR("true")); } else { _if_result_97 = (EL_STR("false")); } _if_result_97; }); el_val_t authorized_str = ({ el_val_t _if_result_99 = 0; if (security_research_authorized()) { _if_result_99 = (EL_STR("true")); } else { _if_result_99 = (EL_STR("false")); } _if_result_99; });
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_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 log_tags = EL_STR("[\"security-audit\",\"threat-check\"]");
el_val_t discard = mem_remember(log_content, log_tags); el_val_t discard = mem_remember(log_content, log_tags);
@@ -724,7 +732,7 @@ el_val_t threat_history_append(el_val_t text) {
el_val_t safe_text = str_to_lower(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 combined = el_str_concat(el_str_concat(current, EL_STR(" ")), safe_text);
el_val_t len = str_len(combined); el_val_t len = str_len(combined);
el_val_t trimmed = ({ el_val_t _if_result_98 = 0; if ((len > 2000)) { _if_result_98 = (str_slice(combined, (len - 2000), len)); } else { _if_result_98 = (combined); } _if_result_98; }); el_val_t trimmed = ({ el_val_t _if_result_100 = 0; if ((len > 2000)) { _if_result_100 = (str_slice(combined, (len - 2000), len)); } else { _if_result_100 = (combined); } _if_result_100; });
state_set(EL_STR("agentic_conv_history"), trimmed); state_set(EL_STR("agentic_conv_history"), trimmed);
return 0; return 0;
} }
Generated Vendored
+5
View File
@@ -131,6 +131,7 @@ el_val_t auto_term_try_slot(el_val_t slot_type, el_val_t slot_lbl);
el_val_t awareness_run(void); el_val_t awareness_run(void);
el_val_t axon_get(el_val_t path); 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 axon_post(el_val_t path, el_val_t body);
el_val_t bounded_persona_floor(void);
el_val_t bridge_save(el_val_t session_id, el_val_t model, el_val_t safe_sys, el_val_t tools_json, el_val_t messages, el_val_t tools_log, el_val_t tool_use_id); el_val_t bridge_save(el_val_t session_id, el_val_t model, el_val_t safe_sys, el_val_t tools_json, el_val_t messages, el_val_t tools_log, el_val_t tool_use_id);
el_val_t build_form_from_json(el_val_t semantic_form_json, el_val_t lang_code); el_val_t build_form_from_json(el_val_t semantic_form_json, el_val_t lang_code);
el_val_t build_np(el_val_t referent, el_val_t slots); el_val_t build_np(el_val_t referent, el_val_t slots);
@@ -820,6 +821,8 @@ el_val_t mem_save(el_val_t path);
el_val_t mem_search(el_val_t query, el_val_t limit); el_val_t mem_search(el_val_t query, el_val_t limit);
el_val_t mem_store(el_val_t content, el_val_t label, el_val_t tags); el_val_t mem_store(el_val_t content, el_val_t label, el_val_t tags);
el_val_t mem_strengthen(el_val_t node_id); el_val_t mem_strengthen(el_val_t node_id);
el_val_t mem_tombstone(el_val_t node_id);
el_val_t memory_hide_tombstoned(el_val_t raw, el_val_t path);
el_val_t morph_apply_suffix(el_val_t base, el_val_t suffix); el_val_t morph_apply_suffix(el_val_t base, el_val_t suffix);
el_val_t morph_conjugate(el_val_t verb, el_val_t tense, el_val_t person, el_val_t number, el_val_t profile); el_val_t morph_conjugate(el_val_t verb, el_val_t tense, el_val_t person, el_val_t number, el_val_t profile);
el_val_t morph_inflect(el_val_t word, el_val_t features, el_val_t profile); el_val_t morph_inflect(el_val_t word, el_val_t features, el_val_t profile);
@@ -1151,6 +1154,8 @@ 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_canonical(void);
el_val_t tier_episodic(void); el_val_t tier_episodic(void);
el_val_t tier_working(void); el_val_t tier_working(void);
el_val_t tombstone_node(el_val_t id);
el_val_t tombstoned_id_set(void);
el_val_t tool_auto_approved(el_val_t tool_name); el_val_t tool_auto_approved(el_val_t tool_name);
el_val_t txb_conjugate(el_val_t verb, el_val_t tense, el_val_t person, el_val_t number); el_val_t txb_conjugate(el_val_t verb, el_val_t tense, el_val_t person, el_val_t number);
el_val_t txb_decline(el_val_t noun, el_val_t gram_case, el_val_t number); el_val_t txb_decline(el_val_t noun, el_val_t gram_case, el_val_t number);
Generated Vendored
+2 -3
View File
@@ -250,11 +250,10 @@ el_val_t memory_hide_tombstoned(el_val_t raw, el_val_t path) {
el_val_t handle_api_begin_session(el_val_t body) { el_val_t handle_api_begin_session(el_val_t body) {
el_val_t stats = engram_stats_json(); el_val_t stats = engram_stats_json();
el_val_t activated = engram_activate_json(EL_STR("session start recent memory important"), 2); el_val_t activated = engram_activate_json(EL_STR("session start recent memory important"), 1);
el_val_t self_nbrs = engram_neighbors_json(EL_STR("kn-efeb4a5b-5aff-4759-8a97-7233099be6ee"), 1, EL_STR("both"));
el_val_t state_events = engram_scan_nodes_by_type_json(EL_STR("InternalStateEvent"), 5, 0); el_val_t state_events = engram_scan_nodes_by_type_json(EL_STR("InternalStateEvent"), 5, 0);
el_val_t recent = engram_scan_nodes_json(10, 0); el_val_t recent = engram_scan_nodes_json(10, 0);
return 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("{\"stats\":"), stats), EL_STR(",\"recent\":")), api_or_empty(recent)), EL_STR(",\"activated\":")), api_or_empty(activated)), EL_STR(",\"self_neighbors\":")), api_or_empty(self_nbrs)), EL_STR(",\"recent_state_events\":")), api_or_empty(state_events)), EL_STR("}")); return 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("{\"stats\":"), stats), EL_STR(",\"recent\":")), api_or_empty(recent)), EL_STR(",\"activated\":")), api_or_empty(activated)), EL_STR(",\"self_neighbors\":[]")), EL_STR(",\"recent_state_events\":")), api_or_empty(state_events)), EL_STR("}"));
return 0; return 0;
} }
Generated Vendored
+6 -5
View File
@@ -10,6 +10,7 @@ el_val_t mem_remember(el_val_t content, el_val_t tags);
el_val_t mem_recall(el_val_t query, el_val_t depth); el_val_t mem_recall(el_val_t query, el_val_t depth);
el_val_t mem_search(el_val_t query, el_val_t limit); el_val_t mem_search(el_val_t query, el_val_t limit);
el_val_t mem_strengthen(el_val_t node_id); el_val_t mem_strengthen(el_val_t node_id);
el_val_t mem_tombstone(el_val_t node_id);
el_val_t mem_forget(el_val_t node_id); el_val_t mem_forget(el_val_t node_id);
el_val_t mem_consolidate(void); el_val_t mem_consolidate(void);
el_val_t mem_save(el_val_t path); el_val_t mem_save(el_val_t path);
@@ -63,6 +64,7 @@ el_val_t engram_compile(el_val_t intent);
el_val_t distill_transcript(el_val_t transcript); el_val_t distill_transcript(el_val_t transcript);
el_val_t json_safe(el_val_t s); el_val_t json_safe(el_val_t s);
el_val_t current_engine_note(el_val_t model); el_val_t current_engine_note(el_val_t model);
el_val_t bounded_persona_floor(void);
el_val_t build_system_prompt(el_val_t ctx, el_val_t chat_mode); el_val_t build_system_prompt(el_val_t ctx, el_val_t chat_mode);
el_val_t hist_append(el_val_t hist, el_val_t role, el_val_t content); 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 hist_trim(el_val_t hist);
@@ -137,6 +139,9 @@ el_val_t api_nonempty(el_val_t s);
el_val_t api_or_empty(el_val_t s); el_val_t api_or_empty(el_val_t s);
el_val_t api_persisted(el_val_t id); el_val_t api_persisted(el_val_t id);
el_val_t api_not_persisted(el_val_t id); el_val_t api_not_persisted(el_val_t id);
el_val_t tombstone_node(el_val_t id);
el_val_t tombstoned_id_set(void);
el_val_t memory_hide_tombstoned(el_val_t raw, el_val_t path);
el_val_t handle_api_begin_session(el_val_t body); el_val_t handle_api_begin_session(el_val_t body);
el_val_t handle_api_compile_ctx(el_val_t body); el_val_t handle_api_compile_ctx(el_val_t body);
el_val_t handle_api_remember(el_val_t body); el_val_t handle_api_remember(el_val_t body);
@@ -180,11 +185,6 @@ el_val_t session_hist_save(el_val_t session_id, el_val_t hist);
el_val_t session_update_meta_timestamp(el_val_t session_id); el_val_t session_update_meta_timestamp(el_val_t session_id);
el_val_t session_auto_title(el_val_t session_id, el_val_t first_message); el_val_t session_auto_title(el_val_t session_id, el_val_t first_message);
el_val_t handle_session_approve(el_val_t session_id, el_val_t body); el_val_t handle_session_approve(el_val_t session_id, el_val_t body);
el_val_t init_soul_edges(void);
el_val_t load_identity_context(void);
el_val_t seed_persona_from_env(void);
el_val_t emit_session_start_event(void);
el_val_t layered_cycle(el_val_t raw_input);
el_val_t flag_true(el_val_t body, el_val_t key); el_val_t flag_true(el_val_t body, el_val_t key);
el_val_t rate_limit_check(el_val_t ip, el_val_t path); el_val_t rate_limit_check(el_val_t ip, el_val_t path);
el_val_t strip_query(el_val_t path); el_val_t strip_query(el_val_t path);
@@ -438,6 +438,7 @@ el_val_t handle_connectors(el_val_t method, el_val_t clean, el_val_t body) {
el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body) { el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body) {
el_val_t clean = strip_query(path); el_val_t clean = strip_query(path);
state_set(EL_STR("soul.last_activity_ts"), int_to_str(time_now()));
el_val_t ip = env(EL_STR("REMOTE_ADDR")); el_val_t ip = env(EL_STR("REMOTE_ADDR"));
if (!str_eq(ip, EL_STR(""))) { if (!str_eq(ip, EL_STR(""))) {
el_val_t rl_result = rate_limit_check(ip, clean); el_val_t rl_result = rate_limit_check(ip, clean);
+13 -3
View File
@@ -170,15 +170,25 @@ fn memory_hide_tombstoned(raw: String, path: String) -> String {
// Spread-activates from session intent, loads self-root neighbors, // Spread-activates from session intent, loads self-root neighbors,
// surfaces recent InternalStateEvent nodes, returns stats + recent nodes. // surfaces recent InternalStateEvent nodes, returns stats + recent nodes.
fn handle_api_begin_session(body: String) -> String { fn handle_api_begin_session(body: String) -> String {
// PAYLOAD BOUND (2026-07-30 self-review): this handler was the only
// working-set endpoint that concatenated UNBOUNDED engram queries
// a depth-2 spread PLUS the full neighbor dump of the self-identity hub
// (highest-fanout node in the graph, ~80KB alone; node JSON carries full
// content + embeddings). On the ~12k-node store the assembled response
// ran to multiple MB, then roughly doubled through two rounds of JSON
// re-escaping in the MCP wrapper the client saw "socket connection
// closed unexpectedly" on every beginSession call. Fix: depth-2 depth-1
// spread, and drop the self-hub dump entirely (identity loading has its
// own dedicated tool, inspectGraph; duplicating it here served nothing).
// self_neighbors key retained as [] for response-shape compatibility.
let stats: String = engram_stats_json() let stats: String = engram_stats_json()
let activated: String = engram_activate_json("session start recent memory important", 2) let activated: String = engram_activate_json("session start recent memory important", 1)
let self_nbrs: String = engram_neighbors_json("kn-efeb4a5b-5aff-4759-8a97-7233099be6ee", 1, "both")
let state_events: String = engram_scan_nodes_by_type_json("InternalStateEvent", 5, 0) let state_events: String = engram_scan_nodes_by_type_json("InternalStateEvent", 5, 0)
let recent: String = engram_scan_nodes_json(10, 0) let recent: String = engram_scan_nodes_json(10, 0)
return "{\"stats\":" + stats return "{\"stats\":" + stats
+ ",\"recent\":" + api_or_empty(recent) + ",\"recent\":" + api_or_empty(recent)
+ ",\"activated\":" + api_or_empty(activated) + ",\"activated\":" + api_or_empty(activated)
+ ",\"self_neighbors\":" + api_or_empty(self_nbrs) + ",\"self_neighbors\":[]"
+ ",\"recent_state_events\":" + api_or_empty(state_events) + "}" + ",\"recent_state_events\":" + api_or_empty(state_events) + "}"
} }
+8
View File
@@ -358,6 +358,14 @@ fn handle_connectors(method: String, clean: String, body: String) -> String {
fn handle_request(method: String, path: String, body: String) -> String { fn handle_request(method: String, path: String, body: String) -> String {
let clean: String = strip_query(path) let clean: String = strip_query(path)
// ACTIVITY STAMP (2026-07-30 self-review): every inbound HTTP request
// MCP wrapper calls, chat, API marks real external activity. Before
// this, "idle" was only reset by rare inbox synthesis-requests, so the
// heartbeat idle field tracked uptime exactly (idle == pulse on every
// beat) and carried zero information. The awareness heartbeat now
// reports idle_ms = wall-clock ms since this stamp.
state_set("soul.last_activity_ts", int_to_str(time_now()))
// Rate limit check. Extract caller IP from REMOTE_ADDR env var (set by the // Rate limit check. Extract caller IP from REMOTE_ADDR env var (set by the
// EL HTTP runtime for each request). Skip enforcement when empty so // EL HTTP runtime for each request). Skip enforcement when empty so
// loopback/internal callers are never blocked. // loopback/internal callers are never blocked.