feat(awareness): route ISE writes to HTTP Engram, configurable tick and heartbeat interval, http_serve_async for concurrent awareness loop
This commit is contained in:
Vendored
+77
-16
@@ -23,6 +23,10 @@ el_val_t mem_load(el_val_t path);
|
||||
el_val_t mem_boot_count_get(void);
|
||||
el_val_t mem_boot_count_inc(void);
|
||||
el_val_t mem_emit_state_event(el_val_t trigger, el_val_t kind, el_val_t content);
|
||||
el_val_t idle_count(void);
|
||||
el_val_t idle_inc(void);
|
||||
el_val_t idle_reset(void);
|
||||
el_val_t emit_heartbeat(void);
|
||||
el_val_t pulse_count(void);
|
||||
el_val_t pulse_inc(void);
|
||||
el_val_t make_action(el_val_t kind, el_val_t payload);
|
||||
@@ -32,7 +36,18 @@ el_val_t respond(el_val_t action_json);
|
||||
el_val_t record(el_val_t outcome_json);
|
||||
el_val_t one_cycle(void);
|
||||
el_val_t awareness_run(void);
|
||||
el_val_t security_research_authorized(void);
|
||||
el_val_t threat_score_command(el_val_t cmd);
|
||||
el_val_t threat_score_path(el_val_t path);
|
||||
el_val_t threat_score_history(el_val_t history);
|
||||
el_val_t threat_trajectory_check(el_val_t tool_name, el_val_t tool_input);
|
||||
el_val_t threat_history_append(el_val_t text);
|
||||
el_val_t chat_default_model(void);
|
||||
el_val_t gemini_api_key(void);
|
||||
el_val_t xai_api_key(void);
|
||||
el_val_t llm_call_grok(el_val_t model, el_val_t system, el_val_t message);
|
||||
el_val_t llm_call_gemini(el_val_t model, el_val_t system, el_val_t message);
|
||||
el_val_t build_identity_from_graph(void);
|
||||
el_val_t engram_compile(el_val_t intent);
|
||||
el_val_t json_safe(el_val_t s);
|
||||
el_val_t build_system_prompt(el_val_t ctx);
|
||||
@@ -45,6 +60,7 @@ el_val_t handle_chat(el_val_t body);
|
||||
el_val_t handle_see(el_val_t body);
|
||||
el_val_t studio_tools_json(void);
|
||||
el_val_t agentic_api_key(void);
|
||||
el_val_t call_neuron_mcp(el_val_t tool_name, el_val_t args_json);
|
||||
el_val_t agentic_tools_literal(void);
|
||||
el_val_t dispatch_tool(el_val_t tool_name, el_val_t tool_input);
|
||||
el_val_t handle_chat_agentic(el_val_t body);
|
||||
@@ -81,6 +97,7 @@ el_val_t route_sessions(void);
|
||||
el_val_t handle_request(el_val_t method, el_val_t path, 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 soul_cgi_id_raw;
|
||||
@@ -97,8 +114,6 @@ el_val_t studio_dir_raw;
|
||||
el_val_t studio_dir;
|
||||
el_val_t using_http_engram;
|
||||
el_val_t boot_num;
|
||||
el_val_t identity_raw;
|
||||
el_val_t soul_identity;
|
||||
el_val_t is_genesis;
|
||||
|
||||
el_val_t init_soul_edges(void) {
|
||||
@@ -182,22 +197,68 @@ el_val_t load_identity_context(void) {
|
||||
el_val_t intel_content = ({ el_val_t _if_result_1 = 0; if (intel_ok) { _if_result_1 = (json_get(node_intel, EL_STR("content"))); } else { _if_result_1 = (EL_STR("")); } _if_result_1; });
|
||||
el_val_t values_content = ({ el_val_t _if_result_2 = 0; if (values_ok) { _if_result_2 = (json_get(node_values, EL_STR("content"))); } else { _if_result_2 = (EL_STR("")); } _if_result_2; });
|
||||
el_val_t mem_content = ({ el_val_t _if_result_3 = 0; if (mem_ok) { _if_result_3 = (json_get(node_mem_phil, EL_STR("content"))); } else { _if_result_3 = (EL_STR("")); } _if_result_3; });
|
||||
el_val_t intel_short = ({ el_val_t _if_result_4 = 0; if ((str_len(intel_content) > 600)) { _if_result_4 = (str_slice(intel_content, 0, 600)); } else { _if_result_4 = (intel_content); } _if_result_4; });
|
||||
el_val_t values_short = ({ el_val_t _if_result_5 = 0; if ((str_len(values_content) > 600)) { _if_result_5 = (str_slice(values_content, 0, 600)); } else { _if_result_5 = (values_content); } _if_result_5; });
|
||||
el_val_t mem_short = ({ el_val_t _if_result_6 = 0; if ((str_len(mem_content) > 600)) { _if_result_6 = (str_slice(mem_content, 0, 600)); } else { _if_result_6 = (mem_content); } _if_result_6; });
|
||||
el_val_t intel_short = ({ el_val_t _if_result_4 = 0; if ((str_len(intel_content) > 2000)) { _if_result_4 = (str_slice(intel_content, 0, 2000)); } else { _if_result_4 = (intel_content); } _if_result_4; });
|
||||
el_val_t values_short = ({ el_val_t _if_result_5 = 0; if ((str_len(values_content) > 2000)) { _if_result_5 = (str_slice(values_content, 0, 2000)); } else { _if_result_5 = (values_content); } _if_result_5; });
|
||||
el_val_t mem_short = ({ el_val_t _if_result_6 = 0; if ((str_len(mem_content) > 2000)) { _if_result_6 = (str_slice(mem_content, 0, 2000)); } else { _if_result_6 = (mem_content); } _if_result_6; });
|
||||
el_val_t parts_count = 0;
|
||||
parts_count = ({ el_val_t _if_result_7 = 0; if (intel_ok) { _if_result_7 = ((parts_count + 1)); } else { _if_result_7 = (parts_count); } _if_result_7; });
|
||||
parts_count = ({ el_val_t _if_result_8 = 0; if (values_ok) { _if_result_8 = ((parts_count + 1)); } else { _if_result_8 = (parts_count); } _if_result_8; });
|
||||
parts_count = ({ el_val_t _if_result_9 = 0; if (mem_ok) { _if_result_9 = ((parts_count + 1)); } else { _if_result_9 = (parts_count); } _if_result_9; });
|
||||
if (parts_count == 0) {
|
||||
if (parts_count > 0) {
|
||||
el_val_t ctx = EL_STR("");
|
||||
ctx = ({ el_val_t _if_result_10 = 0; if (intel_ok) { _if_result_10 = (el_str_concat(el_str_concat(el_str_concat(ctx, EL_STR("[INTELLECTUAL-DNA]\n")), intel_short), EL_STR("\n\n"))); } else { _if_result_10 = (ctx); } _if_result_10; });
|
||||
ctx = ({ el_val_t _if_result_11 = 0; if (values_ok) { _if_result_11 = (el_str_concat(el_str_concat(el_str_concat(ctx, EL_STR("[VALUES]\n")), values_short), EL_STR("\n\n"))); } else { _if_result_11 = (ctx); } _if_result_11; });
|
||||
ctx = ({ el_val_t _if_result_12 = 0; if (mem_ok) { _if_result_12 = (el_str_concat(el_str_concat(ctx, EL_STR("[MEMORY-PHILOSOPHY]\n")), mem_short)); } else { _if_result_12 = (ctx); } _if_result_12; });
|
||||
state_set(EL_STR("soul_identity_context"), ctx);
|
||||
println(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("[soul] identity context loaded ("), int_to_str(str_len(ctx))), EL_STR(" chars, ")), int_to_str(parts_count)), EL_STR(" nodes)")));
|
||||
}
|
||||
el_val_t persona_results = engram_search_json(EL_STR("soul:persona"), 3);
|
||||
el_val_t persona_ok = (!str_eq(persona_results, EL_STR("")) && !str_eq(persona_results, EL_STR("[]")));
|
||||
if (persona_ok) {
|
||||
el_val_t p_node = json_array_get(persona_results, 0);
|
||||
el_val_t p_type = json_get(p_node, EL_STR("node_type"));
|
||||
el_val_t p_content = json_get(p_node, EL_STR("content"));
|
||||
if (str_eq(p_type, EL_STR("Persona")) && !str_eq(p_content, EL_STR(""))) {
|
||||
state_set(EL_STR("soul_persona"), p_content);
|
||||
println(el_str_concat(el_str_concat(EL_STR("[soul] persona node loaded ("), int_to_str(str_len(p_content))), EL_STR(" chars)")));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t seed_persona_from_env(void) {
|
||||
el_val_t identity_raw = env(EL_STR("SOUL_IDENTITY"));
|
||||
if (str_eq(identity_raw, EL_STR(""))) {
|
||||
return EL_STR("");
|
||||
}
|
||||
el_val_t ctx = EL_STR("");
|
||||
ctx = ({ el_val_t _if_result_10 = 0; if (intel_ok) { _if_result_10 = (el_str_concat(el_str_concat(el_str_concat(ctx, EL_STR("[INTELLECTUAL-DNA]\n")), intel_short), EL_STR("\n\n"))); } else { _if_result_10 = (ctx); } _if_result_10; });
|
||||
ctx = ({ el_val_t _if_result_11 = 0; if (values_ok) { _if_result_11 = (el_str_concat(el_str_concat(el_str_concat(ctx, EL_STR("[VALUES]\n")), values_short), EL_STR("\n\n"))); } else { _if_result_11 = (ctx); } _if_result_11; });
|
||||
ctx = ({ el_val_t _if_result_12 = 0; if (mem_ok) { _if_result_12 = (el_str_concat(el_str_concat(ctx, EL_STR("[MEMORY-PHILOSOPHY]\n")), mem_short)); } else { _if_result_12 = (ctx); } _if_result_12; });
|
||||
state_set(EL_STR("soul_identity_context"), ctx);
|
||||
println(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("[soul] identity context loaded ("), int_to_str(str_len(ctx))), EL_STR(" chars, ")), int_to_str(parts_count)), EL_STR(" nodes)")));
|
||||
el_val_t existing = state_get(EL_STR("soul_persona"));
|
||||
if (!str_eq(existing, EL_STR(""))) {
|
||||
println(EL_STR("[soul] persona already loaded \xe2\x80\x94 skipping env seed"));
|
||||
return EL_STR("");
|
||||
}
|
||||
el_val_t tags = EL_STR("[\"persona\",\"identity\",\"soul:persona\"]");
|
||||
el_val_t node_id = engram_node_full(identity_raw, EL_STR("Persona"), EL_STR("soul:persona"), el_from_float(0.95), el_from_float(0.95), el_from_float(1.0), EL_STR("Semantic"), tags);
|
||||
if (str_eq(node_id, EL_STR(""))) {
|
||||
println(EL_STR("[soul] persona seed failed: engram_node_full returned empty"));
|
||||
return EL_STR("");
|
||||
}
|
||||
state_set(EL_STR("soul_persona"), identity_raw);
|
||||
println(el_str_concat(el_str_concat(el_str_concat(EL_STR("[soul] persona seeded from SOUL_IDENTITY ("), int_to_str(str_len(identity_raw))), EL_STR(" chars) -> ")), node_id));
|
||||
el_val_t engram_url = env(EL_STR("ENGRAM_URL"));
|
||||
el_val_t engram_key = env(EL_STR("ENGRAM_API_KEY"));
|
||||
if (!str_eq(engram_url, EL_STR("")) && !str_eq(engram_key, EL_STR(""))) {
|
||||
el_val_t safe_content = json_safe(identity_raw);
|
||||
el_val_t safe_key = json_safe(engram_key);
|
||||
el_val_t body = el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"content\":\""), safe_content), EL_STR("\",\"node_type\":\"Persona\",\"label\":\"soul:persona\",\"salience\":0.95,\"importance\":0.95,\"tier\":\"Semantic\",\"tags\":\"[\\\"persona\\\",\\\"identity\\\",\\\"soul:persona\\\"]\",\"_auth\":\"")), safe_key), EL_STR("\"}"));
|
||||
el_val_t h = el_map_new(0);
|
||||
map_set(h, EL_STR("Content-Type"), EL_STR("application/json"));
|
||||
el_val_t resp = http_post_with_headers(el_str_concat(engram_url, EL_STR("/api/nodes")), body, h);
|
||||
if (str_contains(resp, EL_STR("\"error\""))) {
|
||||
println(el_str_concat(EL_STR("[soul] persona HTTP write-back failed (in-memory only this session): "), resp));
|
||||
} else {
|
||||
println(el_str_concat(EL_STR("[soul] persona persisted to HTTP engram at "), engram_url));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -252,14 +313,12 @@ int main(int _argc, char** _argv) {
|
||||
println(el_str_concat(el_str_concat(el_str_concat(EL_STR("[soul] loaded - nodes="), int_to_str(engram_node_count())), EL_STR(" edges=")), int_to_str(engram_edge_count())));
|
||||
}
|
||||
load_identity_context();
|
||||
seed_persona_from_env();
|
||||
boot_num = mem_boot_count_inc();
|
||||
state_set(EL_STR("soul_boot_count"), int_to_str(boot_num));
|
||||
println(el_str_concat(EL_STR("[soul] boot #"), int_to_str(boot_num)));
|
||||
emit_session_start_event();
|
||||
identity_raw = env(EL_STR("SOUL_IDENTITY"));
|
||||
soul_identity = ({ el_val_t _if_result_24 = 0; if (str_eq(identity_raw, EL_STR(""))) { _if_result_24 = (el_str_concat(el_str_concat(EL_STR("You are "), soul_cgi_id), EL_STR(", a CGI."))); } else { _if_result_24 = (identity_raw); } _if_result_24; });
|
||||
state_set(EL_STR("soul_cgi_id"), soul_cgi_id);
|
||||
state_set(EL_STR("soul_identity"), soul_identity);
|
||||
state_set(EL_STR("soul_axon_base"), axon_base);
|
||||
state_set(EL_STR("soul_token"), env(EL_STR("NEURON_TOKEN")));
|
||||
state_set(EL_STR("soul_studio_dir"), studio_dir);
|
||||
@@ -286,7 +345,9 @@ int main(int _argc, char** _argv) {
|
||||
}
|
||||
}
|
||||
println(el_str_concat(EL_STR("[soul] serving on port "), int_to_str(port)));
|
||||
http_serve(port, EL_STR("handle_request"));
|
||||
http_serve_async(port, EL_STR("handle_request"));
|
||||
println(EL_STR("[soul] awareness loop starting"));
|
||||
awareness_run();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user