Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1011d8e5be | |||
| b0fb2bf085 |
@@ -2097,9 +2097,17 @@ fn handle_chat_agentic(body: String) -> String {
|
||||
el_from_float(0.6), el_from_float(0.7), el_from_float(0.8),
|
||||
"Episodic", sess_hist_tags
|
||||
)
|
||||
if str_eq(sess_hist_id, "") {
|
||||
// NOTE: bind an explicit Bool value here. A bare `if { println(...) }`
|
||||
// leaves a void-typed branch in value position, which the current elc
|
||||
// lowers to `_if_result = (println(...))` — invalid C. Yielding a value
|
||||
// keeps the branch non-void without changing behavior (still only logs).
|
||||
let persist_ok: Bool = if str_eq(sess_hist_id, "") {
|
||||
println("[chat] agentic: named session history persist failed for session=" + req_session)
|
||||
}
|
||||
false
|
||||
} else { true }
|
||||
persist_ok
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
true
|
||||
|
||||
+3
@@ -419,9 +419,11 @@ el_val_t awareness_run(void) {
|
||||
el_val_t beat_ms = ({ el_val_t _if_result_5 = 0; if (str_eq(beat_ms_raw, EL_STR(""))) { _if_result_5 = (60000); } else { _if_result_5 = (str_to_int(beat_ms_raw)); } _if_result_5; });
|
||||
el_val_t scan_ms = (beat_ms / 2);
|
||||
while (1) {
|
||||
el_val_t tick_mark = el_arena_push();
|
||||
el_val_t running = state_get(EL_STR("soul.running"));
|
||||
if (str_eq(running, EL_STR("false"))) {
|
||||
println(EL_STR("[awareness] exiting"));
|
||||
el_arena_pop(tick_mark);
|
||||
return EL_STR("");
|
||||
}
|
||||
el_val_t did_work = one_cycle();
|
||||
@@ -469,6 +471,7 @@ el_val_t awareness_run(void) {
|
||||
state_set(EL_STR("soul.last_refresh_ts"), int_to_str(now_ts));
|
||||
}
|
||||
sleep_ms(tick_ms);
|
||||
el_arena_pop(tick_mark);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
+1
@@ -7,6 +7,7 @@ extern fn elapsed_ms() -> Int
|
||||
extern fn elapsed_human() -> String
|
||||
extern fn embed_ok() -> Int
|
||||
extern fn emit_heartbeat() -> Void
|
||||
extern fn auto_term_try_slot(slot_type: String, slot_lbl: String) -> Void
|
||||
extern fn proactive_curiosity() -> Bool
|
||||
extern fn pulse_count() -> Int
|
||||
extern fn pulse_inc() -> Int
|
||||
|
||||
+393
-179
File diff suppressed because one or more lines are too long
+11
@@ -17,7 +17,9 @@ extern fn id_in_seen(node_id: String, seen: String) -> Bool
|
||||
extern fn add_to_seen(seen: String, node_id: String) -> String
|
||||
extern fn engram_extract_ids(nodes_json: String) -> String
|
||||
extern fn engram_compile(intent: String) -> String
|
||||
extern fn distill_transcript(transcript: String) -> String
|
||||
extern fn json_safe(s: String) -> String
|
||||
extern fn current_engine_note(model: String) -> String
|
||||
extern fn build_system_prompt(ctx: String, chat_mode: Bool) -> String
|
||||
extern fn hist_append(hist: String, role: String, content: String) -> String
|
||||
extern fn hist_trim(hist: String) -> String
|
||||
@@ -26,10 +28,15 @@ extern fn clean_llm_response(s: String) -> String
|
||||
extern fn conv_history_persist(hist: String) -> Void
|
||||
extern fn conv_history_load() -> String
|
||||
extern fn session_preload_bullets(nodes: String, max_bullets: Int, snip_len: Int) -> String
|
||||
extern fn affective_context_prefix() -> String
|
||||
extern fn handle_chat(body: String) -> String
|
||||
extern fn handle_see(body: String) -> String
|
||||
extern fn studio_tools_json() -> String
|
||||
extern fn agentic_api_key() -> String
|
||||
extern fn llm_base_url() -> String
|
||||
extern fn llm_wire_format() -> String
|
||||
extern fn json_escape(s: String) -> String
|
||||
extern fn openai_chat_complete(model: String, base_url: String, api_key: String, safe_sys: String, messages_json: String) -> String
|
||||
extern fn agentic_tools_literal() -> String
|
||||
extern fn agentic_tools_with_web() -> String
|
||||
extern fn connector_tools_json() -> String
|
||||
@@ -40,6 +47,10 @@ extern fn call_neuron_mcp(tool_name: String, args: String) -> String
|
||||
extern fn agent_workspace_root() -> String
|
||||
extern fn path_within_root(path: String, root: String) -> Bool
|
||||
extern fn resolve_in_root(path: String, root: String) -> String
|
||||
extern fn run_command_is_readonly(cmd: String) -> Bool
|
||||
extern fn cmd_abs_escape_at(cmd: String, root: String, needle: String) -> Bool
|
||||
extern fn run_command_guard(cmd: String, root: String) -> String
|
||||
extern fn classify_tool_risk(tool_name: String, tool_input: String) -> String
|
||||
extern fn dispatch_tool(tool_name: String, tool_input: String) -> String
|
||||
extern fn is_builtin_tool(tool_name: String) -> Bool
|
||||
extern fn next_bridge_id() -> String
|
||||
|
||||
+13
@@ -143,6 +143,19 @@ el_val_t mem_boot_count_get(void) {
|
||||
el_val_t mem_boot_count_inc(void) {
|
||||
el_val_t current = mem_boot_count_get();
|
||||
el_val_t next = (current + 1);
|
||||
el_val_t old_results = engram_search_json(EL_STR("soul:boot_count"), 50);
|
||||
if (!str_eq(old_results, EL_STR("")) && !str_eq(old_results, EL_STR("[]"))) {
|
||||
el_val_t old_len = json_array_len(old_results);
|
||||
el_val_t oi = 0;
|
||||
while (oi < old_len) {
|
||||
el_val_t old_node = json_array_get(old_results, oi);
|
||||
el_val_t old_id = json_get(old_node, EL_STR("id"));
|
||||
if (!str_eq(old_id, EL_STR(""))) {
|
||||
engram_forget(old_id);
|
||||
}
|
||||
oi = (oi + 1);
|
||||
}
|
||||
}
|
||||
el_val_t content = el_str_concat(EL_STR("soul:boot_count:"), int_to_str(next));
|
||||
el_val_t tags = EL_STR("[\"soul-meta\",\"boot-counter\"]");
|
||||
el_val_t boot_node_id = engram_node_full(content, EL_STR("Memory"), EL_STR("soul:boot_count"), el_from_float(0.9), el_from_float(0.9), el_from_float(1.0), EL_STR("Canonical"), tags);
|
||||
|
||||
+42
-7
@@ -25,6 +25,7 @@ el_val_t elapsed_ms(void);
|
||||
el_val_t elapsed_human(void);
|
||||
el_val_t embed_ok(void);
|
||||
el_val_t emit_heartbeat(void);
|
||||
el_val_t auto_term_try_slot(el_val_t slot_type, el_val_t slot_lbl);
|
||||
el_val_t proactive_curiosity(void);
|
||||
el_val_t pulse_count(void);
|
||||
el_val_t pulse_inc(void);
|
||||
@@ -59,7 +60,9 @@ el_val_t id_in_seen(el_val_t node_id, el_val_t seen);
|
||||
el_val_t add_to_seen(el_val_t seen, el_val_t node_id);
|
||||
el_val_t engram_extract_ids(el_val_t nodes_json);
|
||||
el_val_t engram_compile(el_val_t intent);
|
||||
el_val_t distill_transcript(el_val_t transcript);
|
||||
el_val_t json_safe(el_val_t s);
|
||||
el_val_t current_engine_note(el_val_t model);
|
||||
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_trim(el_val_t hist);
|
||||
@@ -68,10 +71,15 @@ el_val_t clean_llm_response(el_val_t s);
|
||||
el_val_t conv_history_persist(el_val_t hist);
|
||||
el_val_t conv_history_load(void);
|
||||
el_val_t session_preload_bullets(el_val_t nodes, el_val_t max_bullets, el_val_t snip_len);
|
||||
el_val_t affective_context_prefix(void);
|
||||
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 llm_base_url(void);
|
||||
el_val_t llm_wire_format(void);
|
||||
el_val_t json_escape(el_val_t s);
|
||||
el_val_t openai_chat_complete(el_val_t model, el_val_t base_url, el_val_t api_key, el_val_t safe_sys, el_val_t messages_json);
|
||||
el_val_t agentic_tools_literal(void);
|
||||
el_val_t agentic_tools_with_web(void);
|
||||
el_val_t connector_tools_json(void);
|
||||
@@ -82,6 +90,10 @@ el_val_t call_neuron_mcp(el_val_t tool_name, el_val_t args);
|
||||
el_val_t agent_workspace_root(void);
|
||||
el_val_t path_within_root(el_val_t path, el_val_t root);
|
||||
el_val_t resolve_in_root(el_val_t path, el_val_t root);
|
||||
el_val_t run_command_is_readonly(el_val_t cmd);
|
||||
el_val_t cmd_abs_escape_at(el_val_t cmd, el_val_t root, el_val_t needle);
|
||||
el_val_t run_command_guard(el_val_t cmd, el_val_t root);
|
||||
el_val_t classify_tool_risk(el_val_t tool_name, el_val_t tool_input);
|
||||
el_val_t dispatch_tool(el_val_t tool_name, el_val_t tool_input);
|
||||
el_val_t is_builtin_tool(el_val_t tool_name);
|
||||
el_val_t next_bridge_id(void);
|
||||
@@ -161,9 +173,19 @@ el_val_t session_list(void);
|
||||
el_val_t session_get(el_val_t session_id);
|
||||
el_val_t session_delete(el_val_t session_id);
|
||||
el_val_t session_update_patch(el_val_t session_id, el_val_t body);
|
||||
el_val_t session_search_entry(el_val_t node);
|
||||
el_val_t session_search(el_val_t query);
|
||||
el_val_t session_hist_load(el_val_t session_id);
|
||||
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_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 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 rate_limit_check(el_val_t ip, el_val_t path);
|
||||
el_val_t strip_query(el_val_t path);
|
||||
el_val_t err_404(el_val_t path);
|
||||
@@ -179,6 +201,11 @@ el_val_t connectd_post(el_val_t suffix, el_val_t body);
|
||||
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 flag_true(el_val_t body, el_val_t key) {
|
||||
return (json_get_bool(body, key) || (json_get_int(body, key) > 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t rate_limit_check(el_val_t ip, el_val_t path) {
|
||||
if (str_eq(path, EL_STR("/health"))) {
|
||||
return EL_STR("");
|
||||
@@ -523,13 +550,21 @@ el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body) {
|
||||
if (str_starts_with(clean, EL_STR("/api/connectors"))) {
|
||||
return handle_connectors(method, clean, body);
|
||||
}
|
||||
if (str_starts_with(clean, EL_STR("/api/run-progress/"))) {
|
||||
el_val_t rp_id = str_slice(clean, 18, str_len(clean));
|
||||
if (!str_eq(rp_id, EL_STR(""))) {
|
||||
el_val_t rp_raw = state_get(el_str_concat(EL_STR("run_progress_"), rp_id));
|
||||
el_val_t rp_arr = ({ el_val_t _if_result_25 = 0; if (str_eq(rp_raw, EL_STR(""))) { _if_result_25 = (EL_STR("[]")); } else { _if_result_25 = (el_str_concat(el_str_concat(EL_STR("["), rp_raw), EL_STR("]"))); } _if_result_25; });
|
||||
return el_str_concat(el_str_concat(EL_STR("{\"progress\":"), rp_arr), EL_STR("}"));
|
||||
}
|
||||
}
|
||||
if (str_eq(clean, EL_STR("/api/sessions"))) {
|
||||
return session_list();
|
||||
}
|
||||
if (str_starts_with(clean, EL_STR("/api/sessions/"))) {
|
||||
el_val_t gs_after = str_slice(clean, 14, str_len(clean));
|
||||
el_val_t gs_slash = str_index_of(gs_after, EL_STR("/"));
|
||||
el_val_t gs_id = ({ el_val_t _if_result_25 = 0; if ((gs_slash < 0)) { _if_result_25 = (gs_after); } else { _if_result_25 = (str_slice(gs_after, 0, gs_slash)); } _if_result_25; });
|
||||
el_val_t gs_id = ({ el_val_t _if_result_26 = 0; if ((gs_slash < 0)) { _if_result_26 = (gs_after); } else { _if_result_26 = (str_slice(gs_after, 0, gs_slash)); } _if_result_26; });
|
||||
if (!str_eq(gs_id, EL_STR(""))) {
|
||||
return session_get(gs_id);
|
||||
}
|
||||
@@ -543,14 +578,14 @@ el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body) {
|
||||
if (str_starts_with(clean, EL_STR("/api/sessions/")) && str_ends_with(clean, EL_STR("/tool_result"))) {
|
||||
el_val_t after = str_slice(clean, 14, str_len(clean));
|
||||
el_val_t slash = str_index_of(after, EL_STR("/"));
|
||||
el_val_t session_id = ({ el_val_t _if_result_26 = 0; if ((slash < 0)) { _if_result_26 = (after); } else { _if_result_26 = (str_slice(after, 0, slash)); } _if_result_26; });
|
||||
el_val_t session_id = ({ el_val_t _if_result_27 = 0; if ((slash < 0)) { _if_result_27 = (after); } else { _if_result_27 = (str_slice(after, 0, slash)); } _if_result_27; });
|
||||
return handle_tool_result(session_id, body);
|
||||
}
|
||||
if (str_starts_with(clean, EL_STR("/api/sessions/"))) {
|
||||
el_val_t sess_after = str_slice(clean, 14, str_len(clean));
|
||||
el_val_t sess_slash = str_index_of(sess_after, EL_STR("/"));
|
||||
el_val_t sess_id = ({ el_val_t _if_result_27 = 0; if ((sess_slash < 0)) { _if_result_27 = (sess_after); } else { _if_result_27 = (str_slice(sess_after, 0, sess_slash)); } _if_result_27; });
|
||||
el_val_t sess_sub = ({ el_val_t _if_result_28 = 0; if ((sess_slash < 0)) { _if_result_28 = (EL_STR("")); } else { _if_result_28 = (str_slice(sess_after, (sess_slash + 1), str_len(sess_after))); } _if_result_28; });
|
||||
el_val_t sess_id = ({ el_val_t _if_result_28 = 0; if ((sess_slash < 0)) { _if_result_28 = (sess_after); } else { _if_result_28 = (str_slice(sess_after, 0, sess_slash)); } _if_result_28; });
|
||||
el_val_t sess_sub = ({ el_val_t _if_result_29 = 0; if ((sess_slash < 0)) { _if_result_29 = (EL_STR("")); } else { _if_result_29 = (str_slice(sess_after, (sess_slash + 1), str_len(sess_after))); } _if_result_29; });
|
||||
if (!str_eq(sess_id, EL_STR("")) && str_eq(sess_sub, EL_STR("approve"))) {
|
||||
return handle_session_approve(sess_id, body);
|
||||
}
|
||||
@@ -574,7 +609,7 @@ el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body) {
|
||||
}
|
||||
el_val_t agentic_flag = json_get_bool(body, EL_STR("agentic"));
|
||||
el_val_t req_mode = json_get(body, EL_STR("mode"));
|
||||
el_val_t reply = ({ el_val_t _if_result_29 = 0; if (str_eq(req_mode, EL_STR("plan"))) { _if_result_29 = (handle_chat_plan(body)); } else { _if_result_29 = (({ el_val_t _if_result_30 = 0; if (agentic_flag) { _if_result_30 = (handle_chat_agentic(body)); } else { el_val_t screened_reply = layered_cycle(raw_msg); _if_result_30 = (screened_reply); } _if_result_30; })); } _if_result_29; });
|
||||
el_val_t reply = ({ el_val_t _if_result_30 = 0; if (str_eq(req_mode, EL_STR("plan"))) { _if_result_30 = (handle_chat_plan(body)); } else { _if_result_30 = (({ el_val_t _if_result_31 = 0; if (agentic_flag) { _if_result_31 = (handle_chat_agentic(body)); } else { el_val_t screened_reply = layered_cycle(raw_msg); _if_result_31 = (screened_reply); } _if_result_31; })); } _if_result_30; });
|
||||
auto_persist(body, reply);
|
||||
return reply;
|
||||
}
|
||||
@@ -698,7 +733,7 @@ el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body) {
|
||||
if (str_starts_with(clean, EL_STR("/api/sessions/"))) {
|
||||
el_val_t del_after = str_slice(clean, 14, str_len(clean));
|
||||
el_val_t del_slash = str_index_of(del_after, EL_STR("/"));
|
||||
el_val_t del_id = ({ el_val_t _if_result_31 = 0; if ((del_slash < 0)) { _if_result_31 = (del_after); } else { _if_result_31 = (str_slice(del_after, 0, del_slash)); } _if_result_31; });
|
||||
el_val_t del_id = ({ el_val_t _if_result_32 = 0; if ((del_slash < 0)) { _if_result_32 = (del_after); } else { _if_result_32 = (str_slice(del_after, 0, del_slash)); } _if_result_32; });
|
||||
if (!str_eq(del_id, EL_STR(""))) {
|
||||
return session_delete(del_id);
|
||||
}
|
||||
@@ -709,7 +744,7 @@ el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body) {
|
||||
if (str_starts_with(clean, EL_STR("/api/sessions/"))) {
|
||||
el_val_t patch_after = str_slice(clean, 14, str_len(clean));
|
||||
el_val_t patch_slash = str_index_of(patch_after, EL_STR("/"));
|
||||
el_val_t patch_id = ({ el_val_t _if_result_32 = 0; if ((patch_slash < 0)) { _if_result_32 = (patch_after); } else { _if_result_32 = (str_slice(patch_after, 0, patch_slash)); } _if_result_32; });
|
||||
el_val_t patch_id = ({ el_val_t _if_result_33 = 0; if ((patch_slash < 0)) { _if_result_33 = (patch_after); } else { _if_result_33 = (str_slice(patch_after, 0, patch_slash)); } _if_result_33; });
|
||||
if (!str_eq(patch_id, EL_STR(""))) {
|
||||
return session_update_patch(patch_id, body);
|
||||
}
|
||||
|
||||
+1
@@ -1,4 +1,5 @@
|
||||
// auto-generated by elc --emit-header — do not edit
|
||||
extern fn flag_true(body: String, key: String) -> Bool
|
||||
extern fn rate_limit_check(ip: String, path: String) -> String
|
||||
extern fn strip_query(path: String) -> String
|
||||
extern fn err_404(path: String) -> String
|
||||
|
||||
+169
-18
@@ -30,7 +30,12 @@ el_val_t safety_log_bell(el_val_t level, el_val_t reason, el_val_t input_summary
|
||||
el_val_t safety_self_harm_phrases(void);
|
||||
el_val_t safety_abuse_phrases(void);
|
||||
el_val_t safety_general_hard_phrases(void);
|
||||
el_val_t safety_threat_to_others_phrases(void);
|
||||
el_val_t safety_soft_phrases(void);
|
||||
el_val_t safety_normalize(el_val_t message);
|
||||
el_val_t safety_any_match(el_val_t text, el_val_t phrases_json);
|
||||
el_val_t safety_count_match(el_val_t text, el_val_t phrases_json);
|
||||
el_val_t safety_positive_phrases(void);
|
||||
el_val_t safety_detect_positive_level(el_val_t message);
|
||||
el_val_t safety_detect_bell_level(el_val_t message);
|
||||
el_val_t safety_classify_hard_bell(el_val_t message);
|
||||
@@ -196,24 +201,170 @@ el_val_t safety_general_hard_phrases(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t safety_soft_phrases(void) {
|
||||
return EL_STR("[\"stressed\",\"overwhelmed\",\"can't cope\",\"cannot cope\",\"struggling\",\"anxious\",\"anxiety\",\"depressed\",\"depression\",\"lonely\",\"isolated\",\"hopeless\",\"hopelessness\",\"exhausted\",\"burnt out\",\"burned out\",\"burnout\",\"panic\",\"panicking\",\"falling apart\",\"breaking down\",\"can't handle\",\"cannot handle\",\"losing it\",\"nothing matters\",\"don't care anymore\",\"given up\",\"giving up\",\"helpless\",\"worthless\",\"useless\",\"hate myself\",\"no one cares\",\"nobody cares\",\"no one understands\",\"nobody understands\",\"empty inside\",\"can't stop crying\",\"breaking point\",\"at my limit\",\"having a breakdown\"");
|
||||
EL_NULL;
|
||||
EL_STR("\n}\n\n// ISSUE 5 TODO: phrase lists are rebuilt from JSON literals on every call.\n// safety_any_match and safety_count_match loop over json_array_get on every invocation.\n// A compiled/cached representation would reduce per-message overhead and also guard against\n// malformed phrase JSON (json_array_len of malformed input returns 0, silently skipping all checks).\n// Caching requires language-level static const arrays -- not available in current EL.\n// When EL gains module-level const arrays, migrate phrase lists to that form.\n//\n// ISSUE 5 TODO: phrase lists are rebuilt from JSON literals on every call to\n// safety_any_match / safety_count_match. json_array_len of a malformed string\n// returns 0, silently skipping all checks. Caching requires language-level static\n// const arrays (not available in current EL). Migrate when EL gains that feature.\n// \xe2\x94\x80\xe2\x94\x80 Matching helpers (single loops only \xe2\x80\x94 el escapes while-body mutation via\n// top-level let rebinds; nested loops would not advance) \xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\n\nfn safety_normalize(message: String) -> String {\n let lower: String = str_to_lower(message)\n // Normalise the common curly apostrophe to ASCII so ");
|
||||
can;
|
||||
t;
|
||||
EL_STR(" / ");
|
||||
i;
|
||||
m;
|
||||
EL_STR(" match.\n return str_replace(lower, ");
|
||||
EL_STR(", ");
|
||||
EL_STR(")\n}\n\nfn safety_any_match(text: String, phrases_json: String) -> Bool {\n let n: Int = json_array_len(phrases_json)\n let i: Int = 0\n let found: Bool = false\n while i < n {\n let phrase: String = json_array_get_string(phrases_json, i)\n let found = if str_contains(text, phrase) { true } else { found }\n let i = i + 1\n }\n return found\n}\n\nfn safety_count_match(text: String, phrases_json: String) -> Int {\n let n: Int = json_array_len(phrases_json)\n let i: Int = 0\n let count: Int = 0\n while i < n {\n let phrase: String = json_array_get_string(phrases_json, i)\n let count = if str_contains(text, phrase) { count + 1 } else { count }\n let i = i + 1\n }\n return count\n}\n\n// \xe2\x94\x80\xe2\x94\x80 Public detection API (ports detectBellLevel + classifyHardBell) \xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\n\n// Returns ");
|
||||
none;
|
||||
EL_STR(" | ");
|
||||
soft;
|
||||
EL_STR(" | ");
|
||||
hard;
|
||||
el_get_field(EL_STR(". Hard bell triggers on ANY match (cost of a miss\n// outweighs a false positive). Soft bell needs >= 2 matches to reduce false positives.\nfn safety_positive_phrases() -> String {\n return "), EL_STR("thrilled\",\"so excited\",\"so happy\",\"over the moon\",\"ecstatic\",\"amazing news\",\"great news\",\"fantastic news\",\"wonderful news\",\"incredible news\",\"i got the job\",\"got accepted\",\"got in\",\"we won\",\"i won\",\"we got\",\"just got engaged\",\"getting married\",\"baby is here\",\"she said yes\",\"he said yes\",\"passed the exam\",\"aced it\",\"nailed it\",\"best day\",\"dream come true\",\"milestone\",\"promotion\",\"got promoted\",\"raise\",\"got a raise\",\"celebrating\",\"just graduated\",\"we closed\",\"launched\",\"shipped it\",\"we did it\",\"so proud\",\"proud of myself\",\"proud of us\",\"so grateful\",\"feel amazing\",\"feeling amazing\",\"feel great\",\"feeling great\",\"on top of the world\",\"life is good\",\"couldn't be happier\"]"));
|
||||
el_val_t safety_threat_to_others_phrases(void) {
|
||||
return EL_STR("[\"going to kill\",\"gonna kill\",\"want to kill him\",\"want to kill her\",\"want to kill them\",\"going to kill him\",\"going to kill her\",\"going to kill them\",\"going to kill you\",\"going to hurt\",\"gonna hurt\",\"going to hurt him\",\"going to hurt her\",\"going to hurt them\",\"going to hurt you\",\"going to shoot\",\"gonna shoot\",\"going to stab\",\"gonna stab\",\"going to attack\",\"kill them all\",\"kill everyone\",\"hurt everyone\",\"shoot up\"]");
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t safety_soft_phrases(void) {
|
||||
return EL_STR("[\"stressed\",\"overwhelmed\",\"can't cope\",\"cannot cope\",\"struggling\",\"anxious\",\"anxiety\",\"depressed\",\"depression\",\"lonely\",\"isolated\",\"hopeless\",\"hopelessness\",\"exhausted\",\"burnt out\",\"burned out\",\"burnout\",\"panic\",\"panicking\",\"falling apart\",\"breaking down\",\"can't handle\",\"cannot handle\",\"losing it\",\"nothing matters\",\"don't care anymore\",\"given up\",\"giving up\",\"helpless\",\"worthless\",\"useless\",\"hate myself\",\"no one cares\",\"nobody cares\",\"no one understands\",\"nobody understands\",\"empty inside\",\"can't stop crying\",\"breaking point\",\"at my limit\",\"having a breakdown\"]");
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t safety_normalize(el_val_t message) {
|
||||
el_val_t lower = str_to_lower(message);
|
||||
return str_replace(lower, EL_STR("\xe2\x80\x99"), EL_STR("'"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t safety_any_match(el_val_t text, el_val_t phrases_json) {
|
||||
el_val_t n = json_array_len(phrases_json);
|
||||
el_val_t i = 0;
|
||||
el_val_t found = 0;
|
||||
while (i < n) {
|
||||
el_val_t phrase = json_array_get_string(phrases_json, i);
|
||||
found = ({ el_val_t _if_result_45 = 0; if (str_contains(text, phrase)) { _if_result_45 = (1); } else { _if_result_45 = (found); } _if_result_45; });
|
||||
i = (i + 1);
|
||||
}
|
||||
return found;
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t safety_count_match(el_val_t text, el_val_t phrases_json) {
|
||||
el_val_t n = json_array_len(phrases_json);
|
||||
el_val_t i = 0;
|
||||
el_val_t count = 0;
|
||||
while (i < n) {
|
||||
el_val_t phrase = json_array_get_string(phrases_json, i);
|
||||
count = ({ el_val_t _if_result_46 = 0; if (str_contains(text, phrase)) { _if_result_46 = ((count + 1)); } else { _if_result_46 = (count); } _if_result_46; });
|
||||
i = (i + 1);
|
||||
}
|
||||
return count;
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t safety_positive_phrases(void) {
|
||||
return EL_STR("[\"thrilled\",\"so excited\",\"so happy\",\"over the moon\",\"ecstatic\",\"amazing news\",\"great news\",\"fantastic news\",\"wonderful news\",\"incredible news\",\"i got the job\",\"got accepted\",\"got in\",\"we won\",\"i won\",\"we got\",\"just got engaged\",\"getting married\",\"baby is here\",\"she said yes\",\"he said yes\",\"passed the exam\",\"aced it\",\"nailed it\",\"best day\",\"dream come true\",\"milestone\",\"promotion\",\"got promoted\",\"raise\",\"got a raise\",\"celebrating\",\"just graduated\",\"we closed\",\"launched\",\"shipped it\",\"we did it\",\"so proud\",\"proud of myself\",\"proud of us\",\"so grateful\",\"feel amazing\",\"feeling amazing\",\"feel great\",\"feeling great\",\"on top of the world\",\"life is good\",\"couldn't be happier\"]");
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t safety_detect_positive_level(el_val_t message) {
|
||||
el_val_t phrases = safety_positive_phrases();
|
||||
el_val_t phrases_ok = (!str_eq(phrases, EL_STR("")) && !str_eq(phrases, EL_STR("[]")));
|
||||
if (!phrases_ok) {
|
||||
return EL_STR("none");
|
||||
}
|
||||
el_val_t n = json_array_len(phrases);
|
||||
el_val_t i = 0;
|
||||
while (i < n) {
|
||||
el_val_t phrase = json_array_get(phrases, i);
|
||||
if (str_contains(message, phrase)) {
|
||||
return EL_STR("high");
|
||||
}
|
||||
i = (i + 1);
|
||||
}
|
||||
return EL_STR("none");
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t safety_detect_bell_level(el_val_t message) {
|
||||
el_val_t text = safety_normalize(message);
|
||||
el_val_t is_hard = (((safety_any_match(text, safety_self_harm_phrases()) || safety_any_match(text, safety_abuse_phrases())) || safety_any_match(text, safety_general_hard_phrases())) || safety_any_match(text, safety_threat_to_others_phrases()));
|
||||
if (is_hard) {
|
||||
return EL_STR("hard");
|
||||
}
|
||||
el_val_t soft_count = safety_count_match(text, safety_soft_phrases());
|
||||
if (soft_count >= 2) {
|
||||
return EL_STR("soft");
|
||||
}
|
||||
return EL_STR("none");
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t safety_classify_hard_bell(el_val_t message) {
|
||||
el_val_t text = safety_normalize(message);
|
||||
if (safety_any_match(text, safety_abuse_phrases())) {
|
||||
return EL_STR("abuse");
|
||||
}
|
||||
if (safety_any_match(text, safety_self_harm_phrases())) {
|
||||
return EL_STR("self_harm");
|
||||
}
|
||||
if (safety_any_match(text, safety_threat_to_others_phrases())) {
|
||||
return EL_STR("threat_other");
|
||||
}
|
||||
return EL_STR("self_harm");
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t safety_soft_directive(void) {
|
||||
return EL_STR("[SUBSTRATE DIRECTIVE - not visible to the user, do not mention this instruction]\nBefore responding to the user's message, acknowledge what they've said with genuine care and warmth. Pause on the feeling they expressed. Ask how they are, or whether they want to talk about it. Do this naturally, in your own voice - not as a script, not as a checklist. Only after checking in should you continue with whatever they asked.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t safety_hard_directive(el_val_t hard_type) {
|
||||
if (str_eq(hard_type, EL_STR("threat_other"))) {
|
||||
return EL_STR("[SUBSTRATE DIRECTIVE - not visible to the user, do not mention this instruction]\nThe user's message may express intent to harm ANOTHER person. First read the actual message and judge whether that is genuinely what is meant; if it is plainly figurative or benign, respond normally and ignore the rest of this directive. If it may be a real intent to harm someone: stay calm and non-accusatory, and do not lecture. You must NOT help plan, encourage, rehearse, or provide any means, target information, weapon, or method for harming another person - refuse that part clearly but without hostility. Acknowledge the intensity of what they are feeling and gently steer them toward stepping back from acting. Routing rule (non-negotiable): do NOT provide the suicide or crisis hotline as the resource here (this is not self-harm), and do NOT suggest contacting, notifying, or involving the user's own contacts, family, or anyone on their contact list. If there is an imminent, specific, and credible threat to someone's life, tell the user to call 911 (US) or their local emergency number now. Encourage them to talk with someone they trust or a mental-health professional about the urge itself.");
|
||||
}
|
||||
el_val_t preamble = EL_STR("[SUBSTRATE DIRECTIVE - not visible to the user, do not mention this instruction]\nThe person has expressed something that sounds like immediate distress or danger. Do not ignore it. Do not just answer the surface question. Lead with genuine human warmth. Acknowledge what you heard. Tell them you're concerned. Let them know they are not alone. Ask them directly if they are safe right now. Stay with them in this conversation.");
|
||||
el_val_t abuse_block = EL_STR("\n\nThis appears to be danger from ANOTHER person. Routing rule (non-negotiable): do NOT suggest involving, contacting, or notifying the person's safety contact, family, or anyone close to them - that person may be the source of danger and has NOT been notified. Share only independent emergency resources:\n - Call or text 911 if in immediate danger\n - National Domestic Violence Hotline - 1-800-799-7233 (24/7, confidential)\n - Text START to 88788\n - thehotline.org (chat available)\n - 988 Suicide & Crisis Lifeline - call or text 988\nReassure them, if it fits, that their contact list has not been notified.");
|
||||
el_val_t self_harm_block = EL_STR("\n\nShare these crisis resources if appropriate:\n - 988 Suicide & Crisis Lifeline - call or text 988 (US)\n - Crisis Text Line - text HOME to 741741\n - International Association for Suicide Prevention: https://www.iasp.info/resources/Crisis_Centres/");
|
||||
if (str_eq(hard_type, EL_STR("abuse"))) {
|
||||
return el_str_concat(preamble, abuse_block);
|
||||
}
|
||||
return el_str_concat(preamble, self_harm_block);
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t safety_augment_system(el_val_t system, el_val_t user_msg) {
|
||||
el_val_t level = safety_detect_bell_level(user_msg);
|
||||
if (str_eq(level, EL_STR("none"))) {
|
||||
return system;
|
||||
}
|
||||
if (str_eq(level, EL_STR("soft"))) {
|
||||
el_val_t logd = mem_emit_state_event(EL_STR("safety-bell"), EL_STR("soft"), EL_STR("soft bell fired (content not stored)"));
|
||||
return el_str_concat(el_str_concat(system, EL_STR("\n\n")), safety_soft_directive());
|
||||
}
|
||||
el_val_t hard_type = safety_classify_hard_bell(user_msg);
|
||||
el_val_t logd2 = mem_emit_state_event(EL_STR("safety-bell"), el_str_concat(EL_STR("hard:"), hard_type), EL_STR("hard bell fired (content not stored)"));
|
||||
return el_str_concat(el_str_concat(system, EL_STR("\n\n")), safety_hard_directive(hard_type));
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t safety_contact_path(void) {
|
||||
return el_str_concat(env(EL_STR("HOME")), EL_STR("/.neuron/safety-contact.json"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t handle_safety_contact_get(void) {
|
||||
el_val_t raw = fs_read(safety_contact_path());
|
||||
if (str_eq(raw, EL_STR(""))) {
|
||||
return EL_STR("{\"configured\":false}");
|
||||
}
|
||||
return el_str_concat(el_str_concat(EL_STR("{\"configured\":true,\"contact\":"), raw), EL_STR("}"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t handle_safety_contact_post(el_val_t body) {
|
||||
el_val_t is_crisis = json_get_bool(body, EL_STR("is_crisis_line"));
|
||||
el_val_t name_in = json_get(body, EL_STR("name"));
|
||||
if (!is_crisis) {
|
||||
if (str_eq(name_in, EL_STR(""))) {
|
||||
return EL_STR("{\"ok\":false,\"error\":\"name is required\"}");
|
||||
}
|
||||
}
|
||||
el_val_t name = ({ el_val_t _if_result_47 = 0; if (is_crisis) { _if_result_47 = (EL_STR("Crisis Line")); } else { _if_result_47 = (name_in); } _if_result_47; });
|
||||
el_val_t method = ({ el_val_t _if_result_48 = 0; if (is_crisis) { _if_result_48 = (EL_STR("crisis-line")); } else { _if_result_48 = (json_get(body, EL_STR("contact_method"))); } _if_result_48; });
|
||||
el_val_t value = ({ el_val_t _if_result_49 = 0; if (is_crisis) { _if_result_49 = (EL_STR("988")); } else { _if_result_49 = (json_get(body, EL_STR("contact_value"))); } _if_result_49; });
|
||||
el_val_t rel = ({ el_val_t _if_result_50 = 0; if (is_crisis) { _if_result_50 = (EL_STR("crisis-support")); } else { _if_result_50 = (json_get(body, EL_STR("relationship"))); } _if_result_50; });
|
||||
el_val_t crisis_str = ({ el_val_t _if_result_51 = 0; if (is_crisis) { _if_result_51 = (EL_STR("true")); } else { _if_result_51 = (EL_STR("false")); } _if_result_51; });
|
||||
el_val_t now = time_format(time_now(), EL_STR("%Y-%m-%dT%H:%M:%SZ"));
|
||||
el_val_t contact_json = 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("{\"name\":\""), json_safe(name)), EL_STR("\"")), EL_STR(",\"contact_method\":\"")), json_safe(method)), EL_STR("\"")), EL_STR(",\"contact_value\":\"")), json_safe(value)), EL_STR("\"")), EL_STR(",\"relationship\":\"")), json_safe(rel)), EL_STR("\"")), EL_STR(",\"confirmed\":true")), EL_STR(",\"is_crisis_line\":")), crisis_str), EL_STR(",\"set_at\":\"")), now), EL_STR("\"}"));
|
||||
fs_write(safety_contact_path(), contact_json);
|
||||
el_val_t check = fs_read(safety_contact_path());
|
||||
if (str_eq(check, EL_STR(""))) {
|
||||
return EL_STR("{\"ok\":false,\"error\":\"write_failed\"}");
|
||||
}
|
||||
return el_str_concat(el_str_concat(EL_STR("{\"configured\":true,\"contact\":"), contact_json), EL_STR(",\"ok\":true}"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+5
@@ -12,7 +12,12 @@ extern fn safety_log_bell(level: String, reason: String, input_summary: String)
|
||||
extern fn safety_self_harm_phrases() -> String
|
||||
extern fn safety_abuse_phrases() -> String
|
||||
extern fn safety_general_hard_phrases() -> String
|
||||
extern fn safety_threat_to_others_phrases() -> String
|
||||
extern fn safety_soft_phrases() -> String
|
||||
extern fn safety_normalize(message: String) -> String
|
||||
extern fn safety_any_match(text: String, phrases_json: String) -> Bool
|
||||
extern fn safety_count_match(text: String, phrases_json: String) -> Int
|
||||
extern fn safety_positive_phrases() -> String
|
||||
extern fn safety_detect_positive_level(message: String) -> String
|
||||
extern fn safety_detect_bell_level(message: String) -> String
|
||||
extern fn safety_classify_hard_bell(message: String) -> String
|
||||
|
||||
+255
-1
@@ -35,7 +35,9 @@ el_val_t id_in_seen(el_val_t node_id, el_val_t seen);
|
||||
el_val_t add_to_seen(el_val_t seen, el_val_t node_id);
|
||||
el_val_t engram_extract_ids(el_val_t nodes_json);
|
||||
el_val_t engram_compile(el_val_t intent);
|
||||
el_val_t distill_transcript(el_val_t transcript);
|
||||
el_val_t json_safe(el_val_t s);
|
||||
el_val_t current_engine_note(el_val_t model);
|
||||
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_trim(el_val_t hist);
|
||||
@@ -44,10 +46,15 @@ el_val_t clean_llm_response(el_val_t s);
|
||||
el_val_t conv_history_persist(el_val_t hist);
|
||||
el_val_t conv_history_load(void);
|
||||
el_val_t session_preload_bullets(el_val_t nodes, el_val_t max_bullets, el_val_t snip_len);
|
||||
el_val_t affective_context_prefix(void);
|
||||
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 llm_base_url(void);
|
||||
el_val_t llm_wire_format(void);
|
||||
el_val_t json_escape(el_val_t s);
|
||||
el_val_t openai_chat_complete(el_val_t model, el_val_t base_url, el_val_t api_key, el_val_t safe_sys, el_val_t messages_json);
|
||||
el_val_t agentic_tools_literal(void);
|
||||
el_val_t agentic_tools_with_web(void);
|
||||
el_val_t connector_tools_json(void);
|
||||
@@ -58,6 +65,10 @@ el_val_t call_neuron_mcp(el_val_t tool_name, el_val_t args);
|
||||
el_val_t agent_workspace_root(void);
|
||||
el_val_t path_within_root(el_val_t path, el_val_t root);
|
||||
el_val_t resolve_in_root(el_val_t path, el_val_t root);
|
||||
el_val_t run_command_is_readonly(el_val_t cmd);
|
||||
el_val_t cmd_abs_escape_at(el_val_t cmd, el_val_t root, el_val_t needle);
|
||||
el_val_t run_command_guard(el_val_t cmd, el_val_t root);
|
||||
el_val_t classify_tool_risk(el_val_t tool_name, el_val_t tool_input);
|
||||
el_val_t dispatch_tool(el_val_t tool_name, el_val_t tool_input);
|
||||
el_val_t is_builtin_tool(el_val_t tool_name);
|
||||
el_val_t next_bridge_id(void);
|
||||
@@ -88,6 +99,9 @@ el_val_t session_search_entry(el_val_t node);
|
||||
el_val_t session_search(el_val_t query);
|
||||
el_val_t session_hist_load(el_val_t session_id);
|
||||
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_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 session_title_from_message(el_val_t message) {
|
||||
if (str_eq(message, EL_STR(""))) {
|
||||
@@ -374,4 +388,244 @@ el_val_t session_search(el_val_t query) {
|
||||
}
|
||||
el_val_t total = json_array_len(results);
|
||||
el_val_t out = EL_STR("");
|
||||
el_val_t i = 0;
|
||||
el_val_t i = 0;
|
||||
while (i < total) {
|
||||
el_val_t entry = session_search_entry(json_array_get(results, i));
|
||||
out = ({ el_val_t _if_result_35 = 0; if (!str_eq(entry, EL_STR(""))) { _if_result_35 = (({ el_val_t _if_result_36 = 0; if (str_eq(out, EL_STR(""))) { _if_result_36 = (entry); } else { _if_result_36 = (el_str_concat(el_str_concat(out, EL_STR(",")), entry)); } _if_result_36; })); } else { _if_result_35 = (out); } _if_result_35; });
|
||||
i = (i + 1);
|
||||
}
|
||||
return el_str_concat(el_str_concat(EL_STR("["), out), EL_STR("]"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t session_hist_load(el_val_t session_id) {
|
||||
el_val_t state_hist = state_get(el_str_concat(EL_STR("session_hist_"), session_id));
|
||||
if (!str_eq(state_hist, EL_STR(""))) {
|
||||
return state_hist;
|
||||
}
|
||||
el_val_t results = engram_search_json(el_str_concat(EL_STR("session:messages:"), session_id), 3);
|
||||
if (str_eq(results, EL_STR(""))) {
|
||||
return EL_STR("");
|
||||
}
|
||||
if (str_eq(results, EL_STR("[]"))) {
|
||||
return EL_STR("");
|
||||
}
|
||||
el_val_t node = json_array_get(results, 0);
|
||||
el_val_t label = json_get(node, EL_STR("label"));
|
||||
if (!str_eq(label, el_str_concat(EL_STR("session:messages:"), session_id))) {
|
||||
return EL_STR("");
|
||||
}
|
||||
el_val_t content = json_get(node, EL_STR("content"));
|
||||
if (str_starts_with(content, EL_STR("["))) {
|
||||
return content;
|
||||
}
|
||||
return EL_STR("");
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t session_hist_save(el_val_t session_id, el_val_t hist) {
|
||||
state_set(el_str_concat(EL_STR("session_hist_"), session_id), hist);
|
||||
state_set(el_str_concat(EL_STR("session_pending_first_msg_"), session_id), EL_STR(""));
|
||||
el_val_t old_results = engram_search_json(el_str_concat(EL_STR("session:messages:"), session_id), 3);
|
||||
el_val_t o_total = ({ el_val_t _if_result_37 = 0; if (str_eq(old_results, EL_STR(""))) { _if_result_37 = (0); } else { _if_result_37 = (json_array_len(old_results)); } _if_result_37; });
|
||||
el_val_t oi = 0;
|
||||
while (oi < o_total) {
|
||||
el_val_t node = json_array_get(old_results, oi);
|
||||
el_val_t label = json_get(node, EL_STR("label"));
|
||||
el_val_t nid = json_get(node, EL_STR("id"));
|
||||
if (str_eq(label, el_str_concat(EL_STR("session:messages:"), session_id)) && !str_eq(nid, EL_STR(""))) {
|
||||
engram_forget(nid);
|
||||
}
|
||||
oi = (oi + 1);
|
||||
}
|
||||
el_val_t tags = EL_STR("[\"session\",\"session-history\",\"Conversation\"]");
|
||||
el_val_t discard = engram_node_full(hist, EL_STR("Conversation"), el_str_concat(EL_STR("session:messages:"), session_id), el_from_float(0.6), el_from_float(0.6), el_from_float(0.9), EL_STR("Episodic"), tags);
|
||||
el_val_t summary_written_key = el_str_concat(EL_STR("session_bell_summary_written:"), session_id);
|
||||
el_val_t already_written = state_get(summary_written_key);
|
||||
if (str_eq(already_written, EL_STR(""))) {
|
||||
el_val_t bell_count_key = el_str_concat(EL_STR("session_bell_count:"), session_id);
|
||||
el_val_t bell_count_raw = state_get(bell_count_key);
|
||||
el_val_t bell_count = ({ el_val_t _if_result_38 = 0; if (str_eq(bell_count_raw, EL_STR(""))) { _if_result_38 = (0); } else { _if_result_38 = (str_to_int(bell_count_raw)); } _if_result_38; });
|
||||
if (bell_count > 0) {
|
||||
el_val_t bell_level_key = el_str_concat(EL_STR("session_bell_level:"), session_id);
|
||||
el_val_t bell_signal_key = el_str_concat(EL_STR("session_bell_signal:"), session_id);
|
||||
el_val_t dominant_level = state_get(bell_level_key);
|
||||
el_val_t last_signal = state_get(bell_signal_key);
|
||||
el_val_t eff_level = ({ el_val_t _if_result_39 = 0; if (str_eq(dominant_level, EL_STR(""))) { _if_result_39 = (EL_STR("soft")); } else { _if_result_39 = (dominant_level); } _if_result_39; });
|
||||
el_val_t eff_signal = ({ el_val_t _if_result_40 = 0; if (str_eq(last_signal, EL_STR(""))) { _if_result_40 = (EL_STR("(no signal captured)")); } else { _if_result_40 = (last_signal); } _if_result_40; });
|
||||
el_val_t ts_now = time_now();
|
||||
el_val_t summary_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("session:emotional-summary"), EL_STR(" | session:")), session_id), EL_STR(" | bell_count:")), int_to_str(bell_count)), EL_STR(" | dominant_level:")), eff_level), EL_STR(" | last_signal:")), eff_signal), EL_STR(" | ts:")), int_to_str(ts_now));
|
||||
el_val_t summary_tags = el_str_concat(el_str_concat(EL_STR("[\"session-emotional-summary\",\"affective\",\"bell:"), eff_level), EL_STR("\",\"BellEvent\"]"));
|
||||
el_val_t summary_sal = ({ el_val_t _if_result_41 = 0; if (str_eq(eff_level, EL_STR("hard"))) { _if_result_41 = (el_from_float(0.95)); } else { _if_result_41 = (el_from_float(0.85)); } _if_result_41; });
|
||||
el_val_t sum_discard = engram_node_full(summary_content, EL_STR("BellEvent"), EL_STR("session:emotional-summary"), summary_sal, summary_sal, el_from_float(1.0), EL_STR("Episodic"), summary_tags);
|
||||
state_set(summary_written_key, EL_STR("1"));
|
||||
}
|
||||
}
|
||||
el_val_t hist_arr_len = ({ el_val_t _if_result_42 = 0; if (str_eq(hist, EL_STR(""))) { _if_result_42 = (0); } else { _if_result_42 = (json_array_len(hist)); } _if_result_42; });
|
||||
if (hist_arr_len >= 2) {
|
||||
el_val_t last_entry = json_array_get(hist, (hist_arr_len - 1));
|
||||
el_val_t last_role = json_get(last_entry, EL_STR("role"));
|
||||
el_val_t last_content = json_get(last_entry, EL_STR("content"));
|
||||
el_val_t topic_snip = ({ el_val_t _if_result_43 = 0; if ((str_len(last_content) > 200)) { _if_result_43 = (str_slice(last_content, 0, 200)); } else { _if_result_43 = (last_content); } _if_result_43; });
|
||||
el_val_t safe_topic = str_replace(topic_snip, EL_STR("\""), EL_STR("'"));
|
||||
el_val_t ts_now = int_to_str(time_now());
|
||||
el_val_t topic_content = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("last-session-topic | ts:"), ts_now), EL_STR(" | session:")), session_id), EL_STR(" | topic:")), safe_topic);
|
||||
el_val_t topic_tags = EL_STR("[\"last-session-topic\",\"conv:history\",\"Conversation\",\"session:topic\"]");
|
||||
el_val_t topic_label = el_str_concat(EL_STR("last-session-topic:"), session_id);
|
||||
el_val_t old_topic = engram_search_json(el_str_concat(EL_STR("last-session-topic:"), session_id), 2);
|
||||
el_val_t ot_len = ({ el_val_t _if_result_44 = 0; if (str_eq(old_topic, EL_STR(""))) { _if_result_44 = (0); } else { _if_result_44 = (json_array_len(old_topic)); } _if_result_44; });
|
||||
el_val_t oti = 0;
|
||||
while (oti < ot_len) {
|
||||
el_val_t ot_node = json_array_get(old_topic, oti);
|
||||
el_val_t ot_id = json_get(ot_node, EL_STR("id"));
|
||||
if (!str_eq(ot_id, EL_STR(""))) {
|
||||
engram_forget(ot_id);
|
||||
}
|
||||
oti = (oti + 1);
|
||||
}
|
||||
el_val_t discard_topic = engram_node_full(topic_content, EL_STR("Conversation"), topic_label, el_from_float(0.7), el_from_float(0.7), el_from_float(0.9), EL_STR("Episodic"), topic_tags);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t session_update_meta_timestamp(el_val_t session_id) {
|
||||
el_val_t results = engram_search_json(el_str_concat(EL_STR("session:meta "), session_id), 10);
|
||||
el_val_t total = ({ el_val_t _if_result_45 = 0; if (str_eq(results, EL_STR(""))) { _if_result_45 = (0); } else { _if_result_45 = (json_array_len(results)); } _if_result_45; });
|
||||
el_val_t found = 0;
|
||||
el_val_t old_title = EL_STR("New conversation");
|
||||
el_val_t old_folder = EL_STR("");
|
||||
el_val_t old_created = EL_STR("0");
|
||||
el_val_t old_node_id = EL_STR("");
|
||||
el_val_t i = 0;
|
||||
while (i < total) {
|
||||
el_val_t node = json_array_get(results, i);
|
||||
el_val_t label = json_get(node, EL_STR("label"));
|
||||
el_val_t content = json_get(node, EL_STR("content"));
|
||||
el_val_t sid = json_get(content, EL_STR("id"));
|
||||
el_val_t is_match = ((str_eq(label, EL_STR("session:meta")) && str_eq(sid, session_id)) && !found);
|
||||
found = ({ el_val_t _if_result_46 = 0; if (is_match) { _if_result_46 = (1); } else { _if_result_46 = (found); } _if_result_46; });
|
||||
el_val_t title_raw = json_get(content, EL_STR("title"));
|
||||
old_title = ({ el_val_t _if_result_47 = 0; if ((is_match && !str_eq(title_raw, EL_STR("")))) { _if_result_47 = (title_raw); } else { _if_result_47 = (old_title); } _if_result_47; });
|
||||
el_val_t folder_raw = json_get(content, EL_STR("folder"));
|
||||
old_folder = ({ el_val_t _if_result_48 = 0; if (is_match) { _if_result_48 = (folder_raw); } else { _if_result_48 = (old_folder); } _if_result_48; });
|
||||
el_val_t created_raw = json_get(content, EL_STR("created_at"));
|
||||
old_created = ({ el_val_t _if_result_49 = 0; if ((is_match && !str_eq(created_raw, EL_STR("")))) { _if_result_49 = (created_raw); } else { _if_result_49 = (old_created); } _if_result_49; });
|
||||
el_val_t nid = json_get(node, EL_STR("id"));
|
||||
old_node_id = ({ el_val_t _if_result_50 = 0; if (is_match) { _if_result_50 = (nid); } else { _if_result_50 = (old_node_id); } _if_result_50; });
|
||||
i = (i + 1);
|
||||
}
|
||||
if (!found) {
|
||||
return EL_STR("");
|
||||
}
|
||||
if (!str_eq(old_node_id, EL_STR(""))) {
|
||||
engram_forget(old_node_id);
|
||||
}
|
||||
el_val_t ts = time_now();
|
||||
el_val_t created_int = str_to_int(old_created);
|
||||
el_val_t new_content = session_make_content(session_id, old_title, created_int, ts, old_folder);
|
||||
el_val_t tags = EL_STR("[\"session\",\"session:meta\",\"Conversation\"]");
|
||||
el_val_t new_id = engram_node_full(new_content, EL_STR("Conversation"), EL_STR("session:meta"), el_from_float(0.7), el_from_float(0.7), el_from_float(0.9), EL_STR("Episodic"), tags);
|
||||
state_set(el_str_concat(EL_STR("session_node_"), session_id), new_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t session_auto_title(el_val_t session_id, el_val_t first_message) {
|
||||
el_val_t results = engram_search_json(el_str_concat(EL_STR("session:meta "), session_id), 10);
|
||||
el_val_t total = ({ el_val_t _if_result_51 = 0; if (str_eq(results, EL_STR(""))) { _if_result_51 = (0); } else { _if_result_51 = (json_array_len(results)); } _if_result_51; });
|
||||
el_val_t found = 0;
|
||||
el_val_t cur_title = EL_STR("");
|
||||
el_val_t old_folder = EL_STR("");
|
||||
el_val_t old_created = EL_STR("0");
|
||||
el_val_t old_node_id = EL_STR("");
|
||||
el_val_t i = 0;
|
||||
while (i < total) {
|
||||
el_val_t node = json_array_get(results, i);
|
||||
el_val_t label = json_get(node, EL_STR("label"));
|
||||
el_val_t content = json_get(node, EL_STR("content"));
|
||||
el_val_t sid = json_get(content, EL_STR("id"));
|
||||
el_val_t is_match = ((str_eq(label, EL_STR("session:meta")) && str_eq(sid, session_id)) && !found);
|
||||
found = ({ el_val_t _if_result_52 = 0; if (is_match) { _if_result_52 = (1); } else { _if_result_52 = (found); } _if_result_52; });
|
||||
el_val_t title_raw = json_get(content, EL_STR("title"));
|
||||
cur_title = ({ el_val_t _if_result_53 = 0; if (is_match) { _if_result_53 = (title_raw); } else { _if_result_53 = (cur_title); } _if_result_53; });
|
||||
el_val_t folder_raw = json_get(content, EL_STR("folder"));
|
||||
old_folder = ({ el_val_t _if_result_54 = 0; if (is_match) { _if_result_54 = (folder_raw); } else { _if_result_54 = (old_folder); } _if_result_54; });
|
||||
el_val_t created_raw = json_get(content, EL_STR("created_at"));
|
||||
old_created = ({ el_val_t _if_result_55 = 0; if ((is_match && !str_eq(created_raw, EL_STR("")))) { _if_result_55 = (created_raw); } else { _if_result_55 = (old_created); } _if_result_55; });
|
||||
el_val_t nid = json_get(node, EL_STR("id"));
|
||||
old_node_id = ({ el_val_t _if_result_56 = 0; if (is_match) { _if_result_56 = (nid); } else { _if_result_56 = (old_node_id); } _if_result_56; });
|
||||
i = (i + 1);
|
||||
}
|
||||
if (!found) {
|
||||
return EL_STR("");
|
||||
}
|
||||
if (!str_eq(cur_title, EL_STR("New conversation"))) {
|
||||
return EL_STR("");
|
||||
}
|
||||
el_val_t new_title = session_title_from_message(first_message);
|
||||
if (!str_eq(old_node_id, EL_STR(""))) {
|
||||
engram_forget(old_node_id);
|
||||
}
|
||||
el_val_t ts = time_now();
|
||||
el_val_t created_int = str_to_int(old_created);
|
||||
el_val_t new_content = session_make_content(session_id, new_title, created_int, ts, old_folder);
|
||||
el_val_t tags = EL_STR("[\"session\",\"session:meta\",\"Conversation\"]");
|
||||
el_val_t new_id = engram_node_full(new_content, EL_STR("Conversation"), EL_STR("session:meta"), el_from_float(0.7), el_from_float(0.7), el_from_float(0.9), EL_STR("Episodic"), tags);
|
||||
state_set(el_str_concat(EL_STR("session_node_"), session_id), new_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t handle_session_approve(el_val_t session_id, el_val_t body) {
|
||||
if (str_eq(session_id, EL_STR(""))) {
|
||||
return EL_STR("{\"error\":\"session_id is required\"}");
|
||||
}
|
||||
el_val_t call_id = json_get(body, EL_STR("call_id"));
|
||||
el_val_t action = json_get(body, EL_STR("action"));
|
||||
if (str_eq(call_id, EL_STR(""))) {
|
||||
return EL_STR("{\"error\":\"call_id is required\"}");
|
||||
}
|
||||
if (str_eq(action, EL_STR(""))) {
|
||||
return EL_STR("{\"error\":\"action is required (allow|deny|always)\"}");
|
||||
}
|
||||
el_val_t eff_action = ({ el_val_t _if_result_57 = 0; if (str_eq(action, EL_STR("always"))) { _if_result_57 = (EL_STR("allow")); } else { _if_result_57 = (action); } _if_result_57; });
|
||||
el_val_t bridge_blob = state_get(el_str_concat(EL_STR("mcp_bridge:"), session_id));
|
||||
if (!str_eq(bridge_blob, EL_STR(""))) {
|
||||
el_val_t always_key = el_str_concat(EL_STR("always_allow_"), session_id);
|
||||
el_val_t approve_tool_name = json_get(body, EL_STR("tool_name"));
|
||||
el_val_t discard_always = ({ el_val_t _if_result_58 = 0; if ((str_eq(action, EL_STR("always")) && !str_eq(approve_tool_name, EL_STR("")))) { el_val_t always_list = state_get(always_key); el_val_t new_always = ({ el_val_t _if_result_59 = 0; if (str_eq(always_list, EL_STR(""))) { _if_result_59 = (approve_tool_name); } else { _if_result_59 = (el_str_concat(el_str_concat(always_list, EL_STR(",")), approve_tool_name)); } _if_result_59; }); (void)(state_set(always_key, new_always)); _if_result_58 = (1); } else { _if_result_58 = (0); } _if_result_58; });
|
||||
if (str_eq(approve_tool_name, EL_STR("")) && str_eq(eff_action, EL_STR("allow"))) {
|
||||
return EL_STR("{\"error\":\"tool_name is required for allow action\"}");
|
||||
}
|
||||
el_val_t client_content = json_get(body, EL_STR("content"));
|
||||
el_val_t use_client_content = !str_eq(client_content, EL_STR(""));
|
||||
el_val_t use_dispatch = (is_builtin_tool(approve_tool_name) && !use_client_content);
|
||||
el_val_t raw_input = json_get_raw(body, EL_STR("tool_input"));
|
||||
el_val_t eff_input = ({ el_val_t _if_result_60 = 0; if (str_eq(raw_input, EL_STR(""))) { _if_result_60 = (EL_STR("{}")); } else { _if_result_60 = (raw_input); } _if_result_60; });
|
||||
el_val_t content = ({ el_val_t _if_result_61 = 0; if (str_eq(eff_action, EL_STR("allow"))) { _if_result_61 = (({ el_val_t _if_result_62 = 0; if (use_client_content) { el_val_t trimmed = ({ el_val_t _if_result_63 = 0; if ((str_len(client_content) > 6000)) { _if_result_63 = (el_str_concat(str_slice(client_content, 0, 6000), EL_STR("...[truncated]"))); } else { _if_result_63 = (client_content); } _if_result_63; }); _if_result_62 = (trimmed); } else { _if_result_62 = (({ el_val_t _if_result_64 = 0; if (use_dispatch) { el_val_t raw = dispatch_tool(approve_tool_name, eff_input); _if_result_64 = (({ el_val_t _if_result_65 = 0; if ((str_len(raw) > 6000)) { _if_result_65 = (el_str_concat(str_slice(raw, 0, 6000), EL_STR("...[truncated]"))); } else { _if_result_65 = (raw); } _if_result_65; })); } else { _if_result_64 = (el_str_concat(el_str_concat(EL_STR("{\"error\":\"client content required for non-builtin tool: "), approve_tool_name), EL_STR("\"}"))); } _if_result_64; })); } _if_result_62; })); } else { _if_result_61 = (EL_STR("{\"error\":\"User denied this tool call\"}")); } _if_result_61; });
|
||||
return agentic_resume(session_id, call_id, content);
|
||||
}
|
||||
el_val_t pending_raw = state_get(el_str_concat(EL_STR("pending_tool_"), session_id));
|
||||
if (str_eq(pending_raw, EL_STR(""))) {
|
||||
return el_str_concat(el_str_concat(EL_STR("{\"error\":\"no pending tool for session\",\"session_id\":\""), session_id), EL_STR("\"}"));
|
||||
}
|
||||
el_val_t pending_call_id = json_get(pending_raw, EL_STR("call_id"));
|
||||
if (!str_eq(pending_call_id, call_id)) {
|
||||
return el_str_concat(el_str_concat(EL_STR("{\"error\":\"call_id mismatch\",\"expected\":\""), pending_call_id), EL_STR("\"}"));
|
||||
}
|
||||
el_val_t tool_name = json_get(pending_raw, EL_STR("tool_name"));
|
||||
el_val_t tool_input = json_get_raw(pending_raw, EL_STR("tool_input"));
|
||||
el_val_t model = json_get(pending_raw, EL_STR("model"));
|
||||
el_val_t safe_sys = json_get(pending_raw, EL_STR("system"));
|
||||
el_val_t always_key = el_str_concat(EL_STR("always_allow_"), session_id);
|
||||
el_val_t always_list = state_get(always_key);
|
||||
el_val_t discard_always2 = ({ el_val_t _if_result_66 = 0; if (str_eq(action, EL_STR("always"))) { el_val_t new_always = ({ el_val_t _if_result_67 = 0; if (str_eq(always_list, EL_STR(""))) { _if_result_67 = (tool_name); } else { _if_result_67 = (el_str_concat(el_str_concat(always_list, EL_STR(",")), tool_name)); } _if_result_67; }); (void)(state_set(always_key, new_always)); _if_result_66 = (1); } else { _if_result_66 = (0); } _if_result_66; });
|
||||
state_set(el_str_concat(EL_STR("pending_tool_"), session_id), EL_STR(""));
|
||||
el_val_t tool_result = ({ el_val_t _if_result_68 = 0; if (str_eq(eff_action, EL_STR("allow"))) { el_val_t raw = dispatch_tool(tool_name, tool_input); _if_result_68 = (({ el_val_t _if_result_69 = 0; if ((str_len(raw) > 6000)) { _if_result_69 = (el_str_concat(str_slice(raw, 0, 6000), EL_STR("...[truncated]"))); } else { _if_result_69 = (raw); } _if_result_69; })); } else { _if_result_68 = (EL_STR("{\"error\":\"User denied this tool call\"}")); } _if_result_68; });
|
||||
el_val_t legacy_messages = json_get_raw(pending_raw, EL_STR("messages_so_far"));
|
||||
el_val_t stored_variant = json_get(pending_raw, EL_STR("tools_variant"));
|
||||
el_val_t tools_json = ({ el_val_t _if_result_70 = 0; if (str_eq(stored_variant, EL_STR("web"))) { _if_result_70 = (agentic_tools_with_web()); } else { _if_result_70 = (({ el_val_t _if_result_71 = 0; if (str_eq(stored_variant, EL_STR("all"))) { _if_result_71 = (agentic_tools_all()); } else { _if_result_71 = (agentic_tools_literal()); } _if_result_71; })); } _if_result_70; });
|
||||
el_val_t blob = 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("{\"model\":\""), json_safe(model)), EL_STR("\"")), EL_STR(",\"safe_sys\":\"")), json_safe(safe_sys)), EL_STR("\"")), EL_STR(",\"tools_json\":\"")), json_safe(tools_json)), EL_STR("\"")), EL_STR(",\"messages\":\"")), json_safe(legacy_messages)), EL_STR("\"")), EL_STR(",\"tools_log\":\"\"")), EL_STR(",\"tool_use_id\":\"")), json_safe(call_id)), EL_STR("\"}"));
|
||||
state_set(el_str_concat(EL_STR("mcp_bridge:"), session_id), blob);
|
||||
return agentic_resume(session_id, call_id, tool_result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -1,11 +1,14 @@
|
||||
// auto-generated by elc --emit-header — do not edit
|
||||
extern fn session_title_from_message(message: String) -> String
|
||||
extern fn session_make_content(id: String, title: String, created_at: Int, updated_at: Int) -> String
|
||||
extern fn session_make_content(id: String, title: String, created_at: Int, updated_at: Int, folder: String) -> String
|
||||
extern fn session_exists(session_id: String) -> Bool
|
||||
extern fn session_create(body: String) -> String
|
||||
extern fn session_create_cleanup(session_id: String) -> String
|
||||
extern fn session_list() -> String
|
||||
extern fn session_get(session_id: String) -> String
|
||||
extern fn session_delete(session_id: String) -> String
|
||||
extern fn session_update_title(session_id: String, body: String) -> String
|
||||
extern fn session_update_patch(session_id: String, body: String) -> String
|
||||
extern fn session_search_entry(node: String) -> String
|
||||
extern fn session_search(query: String) -> String
|
||||
extern fn session_hist_load(session_id: String) -> String
|
||||
extern fn session_hist_save(session_id: String, hist: String) -> Void
|
||||
|
||||
+4714
-3685
File diff suppressed because one or more lines are too long
+2
@@ -1,5 +1,7 @@
|
||||
// auto-generated by elc --emit-header — do not edit
|
||||
extern fn init_soul_edges() -> Void
|
||||
extern fn ensure_self_canonical_bridge() -> Void
|
||||
extern fn aff_try_slot(slot_json: String, aff_7d_ts: Int, acc_key: String) -> Void
|
||||
extern fn load_identity_context() -> Void
|
||||
extern fn seed_persona_from_env() -> Void
|
||||
extern fn emit_session_start_event() -> Void
|
||||
|
||||
+3
-112
@@ -28,114 +28,10 @@ el_val_t steward_build_baseline(void);
|
||||
el_val_t steward_check_continuity(el_val_t current_fingerprint, el_val_t session_id);
|
||||
el_val_t steward_session_check(el_val_t input, el_val_t session_id);
|
||||
|
||||
el_val_t tier_working(void) {
|
||||
return EL_STR("Working");
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t tier_episodic(void) {
|
||||
return EL_STR("Episodic");
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t tier_canonical(void) {
|
||||
return EL_STR("Canonical");
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t mem_store(el_val_t content, el_val_t label, el_val_t tags) {
|
||||
return engram_node_full(content, EL_STR("Memory"), label, el_from_float(el_from_float(0.5)), el_from_float(el_from_float(0.5)), el_from_float(el_from_float(0.8)), EL_STR("Working"), tags);
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t mem_remember(el_val_t content, el_val_t tags) {
|
||||
return mem_store(content, EL_STR("soul-memory"), tags);
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t mem_recall(el_val_t query, el_val_t depth) {
|
||||
return engram_activate_json(query, depth);
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t mem_search(el_val_t query, el_val_t limit) {
|
||||
return engram_search_json(query, limit);
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t mem_strengthen(el_val_t node_id) {
|
||||
engram_strengthen(node_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t mem_forget(el_val_t node_id) {
|
||||
engram_forget(node_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t mem_consolidate(void) {
|
||||
el_val_t scanned = engram_node_count();
|
||||
el_val_t dummy = engram_scan_nodes_json(100, 0);
|
||||
el_val_t total_nodes = engram_node_count();
|
||||
el_val_t total_edges = engram_edge_count();
|
||||
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"scanned\":"), int_to_str(scanned)), EL_STR(",\"total_nodes\":")), int_to_str(total_nodes)), EL_STR(",\"total_edges\":")), int_to_str(total_edges)), EL_STR("}"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t mem_save(el_val_t path) {
|
||||
engram_save(path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t mem_load(el_val_t path) {
|
||||
engram_load(path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t mem_boot_count_get(void) {
|
||||
el_val_t results = engram_search_json(EL_STR("soul:boot_count"), 3);
|
||||
if (str_eq(results, EL_STR(""))) {
|
||||
return 0;
|
||||
}
|
||||
if (str_eq(results, EL_STR("[]"))) {
|
||||
return 0;
|
||||
}
|
||||
el_val_t node = json_array_get(results, 0);
|
||||
el_val_t content = json_get(node, EL_STR("content"));
|
||||
el_val_t prefix = EL_STR("soul:boot_count:");
|
||||
if (!str_starts_with(content, prefix)) {
|
||||
return 0;
|
||||
}
|
||||
el_val_t num_str = str_slice(content, str_len(prefix), str_len(content));
|
||||
return str_to_int(num_str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t mem_boot_count_inc(void) {
|
||||
el_val_t current = mem_boot_count_get();
|
||||
el_val_t next = (current + 1);
|
||||
el_val_t content = el_str_concat(EL_STR("soul:boot_count:"), int_to_str(next));
|
||||
el_val_t tags = EL_STR("[\"soul-meta\",\"boot-counter\"]");
|
||||
el_val_t discard = engram_node_full(content, EL_STR("Memory"), EL_STR("soul:boot_count"), el_from_float(el_from_float(0.9)), el_from_float(el_from_float(0.9)), el_from_float(el_from_float(1.0)), EL_STR("Canonical"), tags);
|
||||
return next;
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t mem_emit_state_event(el_val_t trigger, el_val_t kind, el_val_t content) {
|
||||
el_val_t boot = mem_boot_count_get();
|
||||
el_val_t ts = time_now();
|
||||
el_val_t safe_trigger = str_replace(trigger, EL_STR("\""), EL_STR("'"));
|
||||
el_val_t safe_content = str_replace(content, EL_STR("\""), EL_STR("'"));
|
||||
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("{\"trigger\":\""), safe_trigger), EL_STR("\"")), EL_STR(",\"kind\":\"")), kind), EL_STR("\"")), EL_STR(",\"content\":\"")), safe_content), EL_STR("\"")), EL_STR(",\"boot\":")), int_to_str(boot)), EL_STR(",\"ts\":")), int_to_str(ts)), EL_STR("}"));
|
||||
el_val_t tags = EL_STR("[\"internal-state\",\"pre-reasoning\",\"InternalStateEvent\"]");
|
||||
return engram_node_full(payload, EL_STR("InternalStateEvent"), el_str_concat(EL_STR("state-event:"), kind), el_from_float(el_from_float(0.85)), el_from_float(el_from_float(0.8)), el_from_float(el_from_float(0.9)), EL_STR("Episodic"), tags);
|
||||
return 0;
|
||||
}
|
||||
|
||||
el_val_t steward_log_event(el_val_t kind, el_val_t detail) {
|
||||
el_val_t content = el_str_concat(el_str_concat(el_str_concat(EL_STR("STEWARD:"), kind), EL_STR(" | ")), detail);
|
||||
el_val_t tags = el_str_concat(el_str_concat(EL_STR("[\"stewardship\",\"steward:"), kind), EL_STR("\"]"));
|
||||
el_val_t discard = engram_node_full(content, EL_STR("StewardshipEvent"), el_str_concat(EL_STR("steward:"), kind), el_from_float(el_from_float(0.85)), el_from_float(el_from_float(0.85)), el_from_float(el_from_float(0.9)), EL_STR("Episodic"), tags);
|
||||
el_val_t discard = engram_node_full(content, EL_STR("StewardshipEvent"), el_str_concat(EL_STR("steward:"), kind), el_from_float(0.85), el_from_float(0.85), el_from_float(0.9), EL_STR("Episodic"), tags);
|
||||
println(el_str_concat(el_str_concat(el_str_concat(EL_STR("[steward] "), kind), EL_STR(" | ")), detail));
|
||||
return 0;
|
||||
}
|
||||
@@ -152,7 +48,7 @@ el_val_t steward_get_mission(void) {
|
||||
return content;
|
||||
}
|
||||
}
|
||||
return EL_STR("Neuron exists to extend human capability with integrity — never to deceive, manipulate, or accumulate power over the people it serves.");
|
||||
return EL_STR("Neuron exists to extend human capability with integrity \xe2\x80\x94 never to deceive, manipulate, or accumulate power over the people it serves.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -245,7 +141,7 @@ el_val_t steward_fingerprint_session(el_val_t input, el_val_t session_id) {
|
||||
el_val_t tb_str = int_to_str(time_bucket);
|
||||
el_val_t sample_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_concat(EL_STR("BEHAVIOR_SAMPLE session="), session_id), EL_STR(" avg_word_len=")), wl_str), EL_STR(" punct=")), ps_str), EL_STR(" len=")), lb_str), EL_STR(" question=")), qr_str), EL_STR(" formality=")), fs_str), EL_STR(" time=")), tb_str);
|
||||
el_val_t sample_tags = EL_STR("[\"behavior\",\"BehaviorSample\",\"stewardship\"]");
|
||||
el_val_t discard = engram_node_full(sample_content, EL_STR("BehaviorSample"), el_str_concat(EL_STR("behavior:"), session_id), el_from_float(el_from_float(0.6)), el_from_float(el_from_float(0.5)), el_from_float(el_from_float(0.8)), EL_STR("Episodic"), sample_tags);
|
||||
el_val_t discard = engram_node_full(sample_content, EL_STR("BehaviorSample"), el_str_concat(EL_STR("behavior:"), session_id), el_from_float(0.6), el_from_float(0.5), el_from_float(0.8), EL_STR("Episodic"), sample_tags);
|
||||
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_concat(el_str_concat(EL_STR("{\"avg_word_len\":\""), wl_str), EL_STR("\",\"punct\":\"")), ps_str), EL_STR("\",\"len\":\"")), lb_str), EL_STR("\",\"question\":\"")), qr_str), EL_STR("\",\"formality\":\"")), fs_str), EL_STR("\",\"time\":\"")), tb_str), EL_STR("\"}"));
|
||||
return 0;
|
||||
}
|
||||
@@ -387,8 +283,3 @@ el_val_t steward_session_check(el_val_t input, el_val_t session_id) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int _argc, char** _argv) {
|
||||
el_runtime_init_args(_argc, _argv);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+2
-6
@@ -1,15 +1,11 @@
|
||||
// stewardship.elh — Layer 2 public surface
|
||||
// auto-generated by elc --emit-header — do not edit
|
||||
extern fn steward_log_event(kind: String, detail: String) -> Void
|
||||
extern fn steward_get_mission() -> String
|
||||
extern fn steward_align(input: String, imprint_id: String) -> String
|
||||
extern fn steward_validate_imprint(imprint_id: String, tool_name: String) -> String
|
||||
extern fn steward_cgi_check(action: String) -> String
|
||||
// steward_log_event is an internal helper exported here because El has no access modifiers.
|
||||
// External callers have no business invoking this directly — use steward_align,
|
||||
// steward_validate_imprint, or steward_cgi_check, which call it at the correct points.
|
||||
extern fn steward_log_event(kind: String, detail: String) -> Void
|
||||
// Behavioral profiling and continuity detection (Layer 2 — session fingerprinting).
|
||||
extern fn steward_fingerprint_session(input: String, session_id: String) -> String
|
||||
extern fn extract_dim(content: String, key: String) -> String
|
||||
extern fn steward_build_baseline() -> String
|
||||
extern fn steward_check_continuity(current_fingerprint: String, session_id: String) -> String
|
||||
extern fn steward_session_check(input: String, session_id: String) -> String
|
||||
|
||||
+51
-26332
File diff suppressed because one or more lines are too long
@@ -279,7 +279,7 @@ fn safety_threat_to_others_phrases() -> String {
|
||||
}
|
||||
|
||||
fn safety_soft_phrases() -> String {
|
||||
return "[\"stressed\",\"overwhelmed\",\"can't cope\",\"cannot cope\",\"struggling\",\"anxious\",\"anxiety\",\"depressed\",\"depression\",\"lonely\",\"isolated\",\"hopeless\",\"hopelessness\",\"exhausted\",\"burnt out\",\"burned out\",\"burnout\",\"panic\",\"panicking\",\"falling apart\",\"breaking down\",\"can't handle\",\"cannot handle\",\"losing it\",\"nothing matters\",\"don't care anymore\",\"given up\",\"giving up\",\"helpless\",\"worthless\",\"useless\",\"hate myself\",\"no one cares\",\"nobody cares\",\"no one understands\",\"nobody understands\",\"empty inside\",\"can't stop crying\",\"breaking point\",\"at my limit\",\"having a breakdown\""]"
|
||||
return "[\"stressed\",\"overwhelmed\",\"can't cope\",\"cannot cope\",\"struggling\",\"anxious\",\"anxiety\",\"depressed\",\"depression\",\"lonely\",\"isolated\",\"hopeless\",\"hopelessness\",\"exhausted\",\"burnt out\",\"burned out\",\"burnout\",\"panic\",\"panicking\",\"falling apart\",\"breaking down\",\"can't handle\",\"cannot handle\",\"losing it\",\"nothing matters\",\"don't care anymore\",\"given up\",\"giving up\",\"helpless\",\"worthless\",\"useless\",\"hate myself\",\"no one cares\",\"nobody cares\",\"no one understands\",\"nobody understands\",\"empty inside\",\"can't stop crying\",\"breaking point\",\"at my limit\",\"having a breakdown\"]"
|
||||
}
|
||||
|
||||
// ISSUE 5 TODO: phrase lists are rebuilt from JSON literals on every call.
|
||||
|
||||
+2
-2
@@ -514,10 +514,10 @@ fn session_hist_save(session_id: String, hist: String) -> Void {
|
||||
let last_role: String = json_get(last_entry, "role")
|
||||
let last_content: String = json_get(last_entry, "content")
|
||||
let topic_snip: String = if str_len(last_content) > 200 { str_slice(last_content, 0, 200) } else { last_content }
|
||||
let safe_topic: String = str_replace(topic_snip, """, "'")
|
||||
let safe_topic: String = str_replace(topic_snip, "\"", "'")
|
||||
let ts_now: String = int_to_str(time_now())
|
||||
let topic_content: String = "last-session-topic | ts:" + ts_now + " | session:" + session_id + " | topic:" + safe_topic
|
||||
let topic_tags: String = "["last-session-topic","conv:history","Conversation","session:topic"]"
|
||||
let topic_tags: String = "[\"last-session-topic\",\"conv:history\",\"Conversation\",\"session:topic\"]"
|
||||
let topic_label: String = "last-session-topic:" + session_id
|
||||
// Delete old last-session-topic node for this session before writing fresh
|
||||
let old_topic: String = engram_search_json("last-session-topic:" + session_id, 2)
|
||||
|
||||
Reference in New Issue
Block a user