Make engram deletes/updates immutable (tombstone + supersede)

The soul was hard-deleting engram nodes: memory/delete and node/delete
called engram_forget (frees the node and drops its incident edges), and
node/update created a replacement then forgot the original with no link
back. That violates the day-one rule that engram nodes are immutable —
memory could be silently, irrecoverably destroyed via the API.

Convert the three destructive handlers to Will's immutability semantics,
mirroring the pattern memory/update and knowledge evolve/promote already
use:

- node/update  -> create the new node, wire a "supersedes" edge new->old,
  KEEP the original. No engram_forget. (Was: create + forget old, no edge.)
- memory/delete and node/delete -> TOMBSTONE: keep the node AND its edges,
  create a Tombstone marker node (content = target id, label
  "tombstone:<id>") wired with a "tombstones" edge. Never engram_forget.
  Default bounded list reads (handle_api_list_typed / the memory list) hide
  tombstoned nodes and the markers; ?include_deleted=1 returns them, and
  internal cognition + /api/graph/nodes still traverse them. memory/update
  was already correct and is unchanged.

Full-graph hiding on /api/graph/nodes is deliberately NOT done at the el
layer: json_array_get is O(index), so filtering that endpoint (called with
limit up to 999999) would be O(n^2). That hide needs a runtime scan filter
and is a separate follow-up; nodes there remain traversable, tagged
status:deleted via the marker edge.

Regenerated dist/soul.c from these sources (flat single-TU amalgamation,
compiled under a 3GB physical-RSS watchdog, peak ~32MB). Verified with
scripts/verify-soul-contract.sh in neuron-ui: PRESENCE passes (all 27
routes) and IMMUTABILITY passes (all four mutation routes KEPT; deletes
produce a real tombstone marker and hide from the default list).
This commit is contained in:
2026-07-17 16:42:30 -05:00
parent 1011d8e5be
commit d337fcb265
2 changed files with 352 additions and 197 deletions
Generated Vendored
+258 -176
View File
@@ -1134,6 +1134,9 @@ el_val_t api_nonempty(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_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_compile_ctx(el_val_t body);
el_val_t handle_api_remember(el_val_t body);
@@ -1177,6 +1180,11 @@ 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);
@@ -28719,6 +28727,66 @@ el_val_t api_not_persisted(el_val_t id) {
return 0;
}
el_val_t tombstone_node(el_val_t id) {
el_val_t tags = EL_STR("[\"Tombstone\",\"status:deleted\"]");
el_val_t marker = engram_node_full(id, EL_STR("Tombstone"), el_str_concat(EL_STR("tombstone:"), id), el_from_float(0.01), el_from_float(0.01), el_from_float(1.0), EL_STR("Episodic"), tags);
if (!str_eq(marker, EL_STR(""))) {
engram_connect(marker, id, el_from_float(1.0), EL_STR("tombstones"));
}
return marker;
return 0;
}
el_val_t tombstoned_id_set(void) {
el_val_t markers = engram_scan_nodes_by_type_json(EL_STR("Tombstone"), 5000, 0);
if (str_eq(markers, EL_STR("")) || str_eq(markers, EL_STR("[]"))) {
return EL_STR("");
}
el_val_t n = json_array_len(markers);
el_val_t acc = EL_STR("|");
el_val_t i = 0;
while (i < n) {
el_val_t m = json_array_get(markers, i);
el_val_t tid = json_get(m, EL_STR("content"));
acc = ({ el_val_t _if_result_482 = 0; if (str_eq(tid, EL_STR(""))) { _if_result_482 = (acc); } else { _if_result_482 = (el_str_concat(el_str_concat(acc, tid), EL_STR("|"))); } _if_result_482; });
i = (i + 1);
}
return acc;
return 0;
}
el_val_t memory_hide_tombstoned(el_val_t raw, el_val_t path) {
if (str_contains(path, EL_STR("include_deleted"))) {
return raw;
}
if (str_eq(raw, EL_STR("")) || str_eq(raw, EL_STR("[]"))) {
return raw;
}
el_val_t dead = tombstoned_id_set();
if (str_eq(dead, EL_STR(""))) {
return raw;
}
el_val_t n = json_array_len(raw);
if (n > 1000) {
return raw;
}
el_val_t out = EL_STR("[");
el_val_t first = 1;
el_val_t i = 0;
while (i < n) {
el_val_t node = json_array_get(raw, i);
el_val_t nid = json_get(node, EL_STR("id"));
el_val_t ntype = json_get(node, EL_STR("node_type"));
el_val_t is_dead = (!str_eq(nid, EL_STR("")) && str_contains(dead, el_str_concat(el_str_concat(EL_STR("|"), nid), EL_STR("|"))));
el_val_t keep = (!str_eq(ntype, EL_STR("Tombstone")) && !is_dead);
out = ({ el_val_t _if_result_483 = 0; if (keep) { _if_result_483 = (({ el_val_t _if_result_484 = 0; if (first) { _if_result_484 = (el_str_concat(out, node)); } else { _if_result_484 = (el_str_concat(el_str_concat(out, EL_STR(",")), node)); } _if_result_484; })); } else { _if_result_483 = (out); } _if_result_483; });
first = ({ el_val_t _if_result_485 = 0; if (keep) { _if_result_485 = (0); } else { _if_result_485 = (first); } _if_result_485; });
i = (i + 1);
}
return el_str_concat(out, EL_STR("]"));
return 0;
}
el_val_t handle_api_begin_session(el_val_t body) {
el_val_t stats = engram_stats_json();
el_val_t activated = engram_activate_json(EL_STR("session start recent memory important"), 2);
@@ -28745,10 +28813,10 @@ el_val_t handle_api_remember(el_val_t body) {
el_val_t importance = json_get(body, EL_STR("importance"));
el_val_t tags_raw = json_get(body, EL_STR("tags"));
el_val_t project = json_get(body, EL_STR("project"));
el_val_t sal_str = ({ el_val_t _if_result_482 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_482 = (EL_STR("0.95")); } else { _if_result_482 = (({ el_val_t _if_result_483 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_483 = (EL_STR("0.75")); } else { _if_result_483 = (({ el_val_t _if_result_484 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_484 = (EL_STR("0.25")); } else { _if_result_484 = (EL_STR("0.50")); } _if_result_484; })); } _if_result_483; })); } _if_result_482; });
el_val_t sal = ({ el_val_t _if_result_485 = 0; if (str_eq(sal_str, EL_STR("0.95"))) { _if_result_485 = (el_from_float(0.95)); } else { _if_result_485 = (({ el_val_t _if_result_486 = 0; if (str_eq(sal_str, EL_STR("0.75"))) { _if_result_486 = (el_from_float(0.75)); } else { _if_result_486 = (({ el_val_t _if_result_487 = 0; if (str_eq(sal_str, EL_STR("0.25"))) { _if_result_487 = (el_from_float(0.25)); } else { _if_result_487 = (el_from_float(0.5)); } _if_result_487; })); } _if_result_486; })); } _if_result_485; });
el_val_t base_tags = ({ el_val_t _if_result_488 = 0; if (str_eq(tags_raw, EL_STR(""))) { _if_result_488 = (EL_STR("[\"Memory\"]")); } else { _if_result_488 = (tags_raw); } _if_result_488; });
el_val_t final_tags = ({ el_val_t _if_result_489 = 0; if (str_eq(project, EL_STR(""))) { _if_result_489 = (base_tags); } else { el_val_t inner = str_slice(base_tags, 1, (str_len(base_tags) - 1)); _if_result_489 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("["), inner), EL_STR(",\"project:")), project), EL_STR("\"]"))); } _if_result_489; });
el_val_t sal_str = ({ el_val_t _if_result_486 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_486 = (EL_STR("0.95")); } else { _if_result_486 = (({ el_val_t _if_result_487 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_487 = (EL_STR("0.75")); } else { _if_result_487 = (({ el_val_t _if_result_488 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_488 = (EL_STR("0.25")); } else { _if_result_488 = (EL_STR("0.50")); } _if_result_488; })); } _if_result_487; })); } _if_result_486; });
el_val_t sal = ({ el_val_t _if_result_489 = 0; if (str_eq(sal_str, EL_STR("0.95"))) { _if_result_489 = (el_from_float(0.95)); } else { _if_result_489 = (({ el_val_t _if_result_490 = 0; if (str_eq(sal_str, EL_STR("0.75"))) { _if_result_490 = (el_from_float(0.75)); } else { _if_result_490 = (({ el_val_t _if_result_491 = 0; if (str_eq(sal_str, EL_STR("0.25"))) { _if_result_491 = (el_from_float(0.25)); } else { _if_result_491 = (el_from_float(0.5)); } _if_result_491; })); } _if_result_490; })); } _if_result_489; });
el_val_t base_tags = ({ el_val_t _if_result_492 = 0; if (str_eq(tags_raw, EL_STR(""))) { _if_result_492 = (EL_STR("[\"Memory\"]")); } else { _if_result_492 = (tags_raw); } _if_result_492; });
el_val_t final_tags = ({ el_val_t _if_result_493 = 0; if (str_eq(project, EL_STR(""))) { _if_result_493 = (base_tags); } else { el_val_t inner = str_slice(base_tags, 1, (str_len(base_tags) - 1)); _if_result_493 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("["), inner), EL_STR(",\"project:")), project), EL_STR("\"]"))); } _if_result_493; });
el_val_t id = engram_node_full(content, EL_STR("Memory"), EL_STR("memory:remembered"), el_from_float(sal), el_from_float(sal), el_from_float(0.9), EL_STR("Episodic"), final_tags);
if (!api_persisted(id)) {
return api_not_persisted(id);
@@ -28763,15 +28831,15 @@ el_val_t handle_api_node_create(el_val_t body) {
return api_err(EL_STR("content is required"));
}
el_val_t nt_raw = json_get(body, EL_STR("node_type"));
el_val_t node_type = ({ el_val_t _if_result_490 = 0; if (str_eq(nt_raw, EL_STR(""))) { _if_result_490 = (EL_STR("Memory")); } else { _if_result_490 = (nt_raw); } _if_result_490; });
el_val_t node_type = ({ el_val_t _if_result_494 = 0; if (str_eq(nt_raw, EL_STR(""))) { _if_result_494 = (EL_STR("Memory")); } else { _if_result_494 = (nt_raw); } _if_result_494; });
el_val_t label_raw = json_get(body, EL_STR("label"));
el_val_t label = ({ el_val_t _if_result_491 = 0; if (str_eq(label_raw, EL_STR(""))) { _if_result_491 = (EL_STR("node:created")); } else { _if_result_491 = (label_raw); } _if_result_491; });
el_val_t label = ({ el_val_t _if_result_495 = 0; if (str_eq(label_raw, EL_STR(""))) { _if_result_495 = (EL_STR("node:created")); } else { _if_result_495 = (label_raw); } _if_result_495; });
el_val_t tier_raw = json_get(body, EL_STR("tier"));
el_val_t tier = ({ el_val_t _if_result_492 = 0; if (str_eq(tier_raw, EL_STR(""))) { _if_result_492 = (EL_STR("Episodic")); } else { _if_result_492 = (tier_raw); } _if_result_492; });
el_val_t tier = ({ el_val_t _if_result_496 = 0; if (str_eq(tier_raw, EL_STR(""))) { _if_result_496 = (EL_STR("Episodic")); } else { _if_result_496 = (tier_raw); } _if_result_496; });
el_val_t tags_raw = json_get(body, EL_STR("tags"));
el_val_t tags = ({ el_val_t _if_result_493 = 0; if (str_eq(tags_raw, EL_STR(""))) { _if_result_493 = (el_str_concat(el_str_concat(EL_STR("[\""), node_type), EL_STR("\"]"))); } else { _if_result_493 = (tags_raw); } _if_result_493; });
el_val_t tags = ({ el_val_t _if_result_497 = 0; if (str_eq(tags_raw, EL_STR(""))) { _if_result_497 = (el_str_concat(el_str_concat(EL_STR("[\""), node_type), EL_STR("\"]"))); } else { _if_result_497 = (tags_raw); } _if_result_497; });
el_val_t importance = json_get(body, EL_STR("importance"));
el_val_t sal = ({ el_val_t _if_result_494 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_494 = (el_from_float(0.95)); } else { _if_result_494 = (({ el_val_t _if_result_495 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_495 = (el_from_float(0.75)); } else { _if_result_495 = (({ el_val_t _if_result_496 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_496 = (el_from_float(0.25)); } else { _if_result_496 = (el_from_float(0.5)); } _if_result_496; })); } _if_result_495; })); } _if_result_494; });
el_val_t sal = ({ el_val_t _if_result_498 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_498 = (el_from_float(0.95)); } else { _if_result_498 = (({ el_val_t _if_result_499 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_499 = (el_from_float(0.75)); } else { _if_result_499 = (({ el_val_t _if_result_500 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_500 = (el_from_float(0.25)); } else { _if_result_500 = (el_from_float(0.5)); } _if_result_500; })); } _if_result_499; })); } _if_result_498; });
el_val_t id = engram_node_full(content, node_type, label, el_from_float(sal), el_from_float(sal), el_from_float(0.9), tier, tags);
if (!api_persisted(id)) {
return api_not_persisted(id);
@@ -28785,8 +28853,18 @@ el_val_t handle_api_node_delete(el_val_t body) {
if (str_eq(id, EL_STR(""))) {
return api_err(EL_STR("id is required"));
}
engram_forget(id);
return el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"id\":\""), id), EL_STR("\"}"));
if (is_protected_node(id)) {
return api_err_protected(id);
}
el_val_t existing = engram_get_node_json(id);
if (str_eq(existing, EL_STR("{}"))) {
return api_err(el_str_concat(EL_STR("node not found: "), id));
}
el_val_t marker = tombstone_node(id);
if (str_eq(marker, EL_STR(""))) {
return api_err(el_str_concat(EL_STR("tombstone failed: "), id));
}
return el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"id\":\""), id), EL_STR("\",\"tombstoned\":true}"));
return 0;
}
@@ -28800,37 +28878,37 @@ el_val_t handle_api_node_update(el_val_t body) {
}
el_val_t old = engram_get_node_json(id);
el_val_t body_content = json_get(body, EL_STR("content"));
el_val_t content = ({ el_val_t _if_result_497 = 0; if (str_eq(body_content, EL_STR(""))) { _if_result_497 = (json_get(old, EL_STR("content"))); } else { _if_result_497 = (body_content); } _if_result_497; });
el_val_t content = ({ el_val_t _if_result_501 = 0; if (str_eq(body_content, EL_STR(""))) { _if_result_501 = (json_get(old, EL_STR("content"))); } else { _if_result_501 = (body_content); } _if_result_501; });
el_val_t body_nt = json_get(body, EL_STR("node_type"));
el_val_t old_nt = json_get(old, EL_STR("node_type"));
el_val_t node_type = ({ el_val_t _if_result_498 = 0; if (!str_eq(body_nt, EL_STR(""))) { _if_result_498 = (body_nt); } else { _if_result_498 = (({ el_val_t _if_result_499 = 0; if (!str_eq(old_nt, EL_STR(""))) { _if_result_499 = (old_nt); } else { _if_result_499 = (EL_STR("Memory")); } _if_result_499; })); } _if_result_498; });
el_val_t node_type = ({ el_val_t _if_result_502 = 0; if (!str_eq(body_nt, EL_STR(""))) { _if_result_502 = (body_nt); } else { _if_result_502 = (({ el_val_t _if_result_503 = 0; if (!str_eq(old_nt, EL_STR(""))) { _if_result_503 = (old_nt); } else { _if_result_503 = (EL_STR("Memory")); } _if_result_503; })); } _if_result_502; });
el_val_t body_label = json_get(body, EL_STR("label"));
el_val_t old_label = json_get(old, EL_STR("label"));
el_val_t label = ({ el_val_t _if_result_500 = 0; if (!str_eq(body_label, EL_STR(""))) { _if_result_500 = (body_label); } else { _if_result_500 = (({ el_val_t _if_result_501 = 0; if (!str_eq(old_label, EL_STR(""))) { _if_result_501 = (old_label); } else { _if_result_501 = (EL_STR("node:updated")); } _if_result_501; })); } _if_result_500; });
el_val_t label = ({ el_val_t _if_result_504 = 0; if (!str_eq(body_label, EL_STR(""))) { _if_result_504 = (body_label); } else { _if_result_504 = (({ el_val_t _if_result_505 = 0; if (!str_eq(old_label, EL_STR(""))) { _if_result_505 = (old_label); } else { _if_result_505 = (EL_STR("node:updated")); } _if_result_505; })); } _if_result_504; });
el_val_t body_tier = json_get(body, EL_STR("tier"));
el_val_t old_tier = json_get(old, EL_STR("tier"));
el_val_t tier = ({ el_val_t _if_result_502 = 0; if (!str_eq(body_tier, EL_STR(""))) { _if_result_502 = (body_tier); } else { _if_result_502 = (({ el_val_t _if_result_503 = 0; if (!str_eq(old_tier, EL_STR(""))) { _if_result_503 = (old_tier); } else { _if_result_503 = (EL_STR("Episodic")); } _if_result_503; })); } _if_result_502; });
el_val_t tier = ({ el_val_t _if_result_506 = 0; if (!str_eq(body_tier, EL_STR(""))) { _if_result_506 = (body_tier); } else { _if_result_506 = (({ el_val_t _if_result_507 = 0; if (!str_eq(old_tier, EL_STR(""))) { _if_result_507 = (old_tier); } else { _if_result_507 = (EL_STR("Episodic")); } _if_result_507; })); } _if_result_506; });
el_val_t body_tags = json_get(body, EL_STR("tags"));
el_val_t tags = ({ el_val_t _if_result_504 = 0; if (str_eq(body_tags, EL_STR(""))) { _if_result_504 = (el_str_concat(el_str_concat(EL_STR("[\""), node_type), EL_STR("\"]"))); } else { _if_result_504 = (body_tags); } _if_result_504; });
el_val_t tags = ({ el_val_t _if_result_508 = 0; if (str_eq(body_tags, EL_STR(""))) { _if_result_508 = (el_str_concat(el_str_concat(EL_STR("[\""), node_type), EL_STR("\"]"))); } else { _if_result_508 = (body_tags); } _if_result_508; });
el_val_t new_id = engram_node_full(content, node_type, label, el_from_float(0.5), el_from_float(0.5), el_from_float(0.8), tier, tags);
if (!api_persisted(new_id)) {
return api_not_persisted(new_id);
}
engram_forget(id);
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"id\":\""), new_id), EL_STR("\",\"replaced\":\"")), id), EL_STR("\",\"ok\":true}"));
engram_connect(new_id, id, el_from_float(0.9), EL_STR("supersedes"));
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"id\":\""), new_id), EL_STR("\",\"supersedes\":\"")), id), EL_STR("\",\"ok\":true}"));
return 0;
}
el_val_t handle_api_recall(el_val_t method, el_val_t path, el_val_t body) {
el_val_t url_q = ({ el_val_t _if_result_505 = 0; if (str_eq(api_query_param(path, EL_STR("query")), EL_STR(""))) { _if_result_505 = (api_query_param(path, EL_STR("q"))); } else { _if_result_505 = (api_query_param(path, EL_STR("query"))); } _if_result_505; });
el_val_t url_q = ({ el_val_t _if_result_509 = 0; if (str_eq(api_query_param(path, EL_STR("query")), EL_STR(""))) { _if_result_509 = (api_query_param(path, EL_STR("q"))); } else { _if_result_509 = (api_query_param(path, EL_STR("query"))); } _if_result_509; });
el_val_t body_query = json_get(body, EL_STR("query"));
el_val_t body_q = json_get(body, EL_STR("q"));
el_val_t q = ({ el_val_t _if_result_506 = 0; if (!str_eq(url_q, EL_STR(""))) { _if_result_506 = (url_q); } else { _if_result_506 = (({ el_val_t _if_result_507 = 0; if (!str_eq(body_query, EL_STR(""))) { _if_result_507 = (body_query); } else { _if_result_507 = (body_q); } _if_result_507; })); } _if_result_506; });
el_val_t q = ({ el_val_t _if_result_510 = 0; if (!str_eq(url_q, EL_STR(""))) { _if_result_510 = (url_q); } else { _if_result_510 = (({ el_val_t _if_result_511 = 0; if (!str_eq(body_query, EL_STR(""))) { _if_result_511 = (body_query); } else { _if_result_511 = (body_q); } _if_result_511; })); } _if_result_510; });
el_val_t chain = json_get(body, EL_STR("chain_name"));
el_val_t limit = api_query_int(path, EL_STR("limit"), 0);
limit = ({ el_val_t _if_result_508 = 0; if ((limit == 0)) { _if_result_508 = (json_get_int(body, EL_STR("limit"))); } else { _if_result_508 = (limit); } _if_result_508; });
limit = ({ el_val_t _if_result_509 = 0; if ((limit == 0)) { _if_result_509 = (10); } else { _if_result_509 = (limit); } _if_result_509; });
el_val_t eff_q = ({ el_val_t _if_result_510 = 0; if (str_eq(q, EL_STR(""))) { _if_result_510 = (chain); } else { _if_result_510 = (q); } _if_result_510; });
limit = ({ el_val_t _if_result_512 = 0; if ((limit == 0)) { _if_result_512 = (json_get_int(body, EL_STR("limit"))); } else { _if_result_512 = (limit); } _if_result_512; });
limit = ({ el_val_t _if_result_513 = 0; if ((limit == 0)) { _if_result_513 = (10); } else { _if_result_513 = (limit); } _if_result_513; });
el_val_t eff_q = ({ el_val_t _if_result_514 = 0; if (str_eq(q, EL_STR(""))) { _if_result_514 = (chain); } else { _if_result_514 = (q); } _if_result_514; });
if (str_eq(eff_q, EL_STR(""))) {
return api_or_empty(engram_scan_nodes_json(limit, 0));
}
@@ -28843,10 +28921,10 @@ el_val_t handle_api_search_knowledge(el_val_t method, el_val_t path, el_val_t bo
el_val_t url_q = api_query_param(path, EL_STR("q"));
el_val_t body_query = json_get(body, EL_STR("query"));
el_val_t body_q = json_get(body, EL_STR("q"));
el_val_t q = ({ el_val_t _if_result_511 = 0; if (!str_eq(url_q, EL_STR(""))) { _if_result_511 = (url_q); } else { _if_result_511 = (({ el_val_t _if_result_512 = 0; if (!str_eq(body_query, EL_STR(""))) { _if_result_512 = (body_query); } else { _if_result_512 = (body_q); } _if_result_512; })); } _if_result_511; });
el_val_t q = ({ el_val_t _if_result_515 = 0; if (!str_eq(url_q, EL_STR(""))) { _if_result_515 = (url_q); } else { _if_result_515 = (({ el_val_t _if_result_516 = 0; if (!str_eq(body_query, EL_STR(""))) { _if_result_516 = (body_query); } else { _if_result_516 = (body_q); } _if_result_516; })); } _if_result_515; });
el_val_t limit = api_query_int(path, EL_STR("limit"), 0);
limit = ({ el_val_t _if_result_513 = 0; if ((limit == 0)) { _if_result_513 = (json_get_int(body, EL_STR("limit"))); } else { _if_result_513 = (limit); } _if_result_513; });
limit = ({ el_val_t _if_result_514 = 0; if ((limit == 0)) { _if_result_514 = (10); } else { _if_result_514 = (limit); } _if_result_514; });
limit = ({ el_val_t _if_result_517 = 0; if ((limit == 0)) { _if_result_517 = (json_get_int(body, EL_STR("limit"))); } else { _if_result_517 = (limit); } _if_result_517; });
limit = ({ el_val_t _if_result_518 = 0; if ((limit == 0)) { _if_result_518 = (10); } else { _if_result_518 = (limit); } _if_result_518; });
if (str_eq(q, EL_STR(""))) {
return api_err(EL_STR("query is required"));
}
@@ -28874,7 +28952,7 @@ el_val_t handle_api_capture_knowledge(el_val_t body) {
if (str_eq(content, EL_STR(""))) {
return api_err(EL_STR("content is required"));
}
el_val_t full = ({ el_val_t _if_result_515 = 0; if (str_eq(title, EL_STR(""))) { _if_result_515 = (content); } else { _if_result_515 = (el_str_concat(el_str_concat(title, EL_STR(": ")), content)); } _if_result_515; });
el_val_t full = ({ el_val_t _if_result_519 = 0; if (str_eq(title, EL_STR(""))) { _if_result_519 = (content); } else { _if_result_519 = (el_str_concat(el_str_concat(title, EL_STR(": ")), content)); } _if_result_519; });
el_val_t tags = EL_STR("[\"Knowledge\",\"captured\"]");
el_val_t id = engram_node_full(full, EL_STR("Knowledge"), EL_STR("knowledge:captured"), el_from_float(0.85), el_from_float(0.8), el_from_float(0.9), EL_STR("Episodic"), tags);
if (!api_persisted(id)) {
@@ -28915,7 +28993,7 @@ el_val_t handle_api_promote_knowledge(el_val_t body) {
return api_err(EL_STR("id (prior node) is required"));
}
el_val_t tags_raw = json_get(body, EL_STR("tags"));
el_val_t tags = ({ el_val_t _if_result_516 = 0; if (str_eq(tags_raw, EL_STR(""))) { _if_result_516 = (EL_STR("[\"Knowledge\",\"tier:canonical\",\"disposition:stable\"]")); } else { _if_result_516 = (tags_raw); } _if_result_516; });
el_val_t tags = ({ el_val_t _if_result_520 = 0; if (str_eq(tags_raw, EL_STR(""))) { _if_result_520 = (EL_STR("[\"Knowledge\",\"tier:canonical\",\"disposition:stable\"]")); } else { _if_result_520 = (tags_raw); } _if_result_520; });
el_val_t new_id = engram_node_full(content, EL_STR("Knowledge"), EL_STR("knowledge:canonical"), el_from_float(0.9), el_from_float(0.9), el_from_float(1.0), EL_STR("Canonical"), tags);
if (!api_persisted(new_id)) {
return api_not_persisted(new_id);
@@ -28926,7 +29004,7 @@ el_val_t handle_api_promote_knowledge(el_val_t body) {
}
el_val_t handle_api_browse_processes(el_val_t method, el_val_t path, el_val_t body) {
el_val_t name = ({ el_val_t _if_result_517 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_517 = (api_query_param(path, EL_STR("name"))); } else { _if_result_517 = (json_get(body, EL_STR("name"))); } _if_result_517; });
el_val_t name = ({ el_val_t _if_result_521 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_521 = (api_query_param(path, EL_STR("name"))); } else { _if_result_521 = (json_get(body, EL_STR("name"))); } _if_result_521; });
el_val_t limit = api_query_int(path, EL_STR("limit"), 50);
if (str_eq(name, EL_STR(""))) {
return api_or_empty(engram_scan_nodes_by_type_json(EL_STR("Process"), limit, 0));
@@ -28941,7 +29019,7 @@ el_val_t handle_api_define_process(el_val_t body) {
if (str_eq(content, EL_STR(""))) {
return api_err(EL_STR("content is required"));
}
el_val_t label = ({ el_val_t _if_result_518 = 0; if (str_eq(name, EL_STR(""))) { _if_result_518 = (EL_STR("process:unnamed")); } else { _if_result_518 = (el_str_concat(EL_STR("process:"), name)); } _if_result_518; });
el_val_t label = ({ el_val_t _if_result_522 = 0; if (str_eq(name, EL_STR(""))) { _if_result_522 = (EL_STR("process:unnamed")); } else { _if_result_522 = (el_str_concat(EL_STR("process:"), name)); } _if_result_522; });
el_val_t tags = EL_STR("[\"Process\"]");
el_val_t id = engram_node_full(content, EL_STR("Process"), label, el_from_float(0.8), el_from_float(0.8), el_from_float(0.9), EL_STR("Canonical"), tags);
if (!api_persisted(id)) {
@@ -28959,12 +29037,12 @@ el_val_t handle_api_log_state_event(el_val_t body) {
el_val_t gap = json_get(body, EL_STR("gap_direction"));
el_val_t legacy = json_get(body, EL_STR("content"));
el_val_t parts = EL_STR("INTERNAL STATE EVENT");
parts = ({ el_val_t _if_result_519 = 0; if (!str_eq(trigger, EL_STR(""))) { _if_result_519 = (el_str_concat(el_str_concat(parts, EL_STR("\nTrigger: ")), trigger)); } else { _if_result_519 = (parts); } _if_result_519; });
parts = ({ el_val_t _if_result_520 = 0; if (!str_eq(pre, EL_STR(""))) { _if_result_520 = (el_str_concat(el_str_concat(parts, EL_STR("\nPre-reasoning: ")), pre)); } else { _if_result_520 = (parts); } _if_result_520; });
parts = ({ el_val_t _if_result_521 = 0; if (!str_eq(post, EL_STR(""))) { _if_result_521 = (el_str_concat(el_str_concat(parts, EL_STR("\nPost-reasoning: ")), post)); } else { _if_result_521 = (parts); } _if_result_521; });
parts = ({ el_val_t _if_result_522 = 0; if (!str_eq(ratio, EL_STR(""))) { _if_result_522 = (el_str_concat(el_str_concat(parts, EL_STR("\nCompression-ratio: ")), ratio)); } else { _if_result_522 = (parts); } _if_result_522; });
parts = ({ el_val_t _if_result_523 = 0; if (!str_eq(gap, EL_STR(""))) { _if_result_523 = (el_str_concat(el_str_concat(parts, EL_STR("\nGap-direction: ")), gap)); } else { _if_result_523 = (parts); } _if_result_523; });
parts = ({ el_val_t _if_result_524 = 0; if (!str_eq(legacy, EL_STR(""))) { _if_result_524 = (el_str_concat(el_str_concat(parts, EL_STR("\n")), legacy)); } else { _if_result_524 = (parts); } _if_result_524; });
parts = ({ el_val_t _if_result_523 = 0; if (!str_eq(trigger, EL_STR(""))) { _if_result_523 = (el_str_concat(el_str_concat(parts, EL_STR("\nTrigger: ")), trigger)); } else { _if_result_523 = (parts); } _if_result_523; });
parts = ({ el_val_t _if_result_524 = 0; if (!str_eq(pre, EL_STR(""))) { _if_result_524 = (el_str_concat(el_str_concat(parts, EL_STR("\nPre-reasoning: ")), pre)); } else { _if_result_524 = (parts); } _if_result_524; });
parts = ({ el_val_t _if_result_525 = 0; if (!str_eq(post, EL_STR(""))) { _if_result_525 = (el_str_concat(el_str_concat(parts, EL_STR("\nPost-reasoning: ")), post)); } else { _if_result_525 = (parts); } _if_result_525; });
parts = ({ el_val_t _if_result_526 = 0; if (!str_eq(ratio, EL_STR(""))) { _if_result_526 = (el_str_concat(el_str_concat(parts, EL_STR("\nCompression-ratio: ")), ratio)); } else { _if_result_526 = (parts); } _if_result_526; });
parts = ({ el_val_t _if_result_527 = 0; if (!str_eq(gap, EL_STR(""))) { _if_result_527 = (el_str_concat(el_str_concat(parts, EL_STR("\nGap-direction: ")), gap)); } else { _if_result_527 = (parts); } _if_result_527; });
parts = ({ el_val_t _if_result_528 = 0; if (!str_eq(legacy, EL_STR(""))) { _if_result_528 = (el_str_concat(el_str_concat(parts, EL_STR("\n")), legacy)); } else { _if_result_528 = (parts); } _if_result_528; });
el_val_t ts = time_now();
el_val_t boot = state_get(EL_STR("soul_boot_count"));
el_val_t tags = EL_STR("[\"internal-state\",\"InternalStateEvent\",\"pre-reasoning\"]");
@@ -28977,7 +29055,7 @@ el_val_t handle_api_log_state_event(el_val_t body) {
}
el_val_t handle_api_list_state_events(el_val_t method, el_val_t path, el_val_t body) {
el_val_t q = ({ el_val_t _if_result_525 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_525 = (api_query_param(path, EL_STR("query"))); } else { _if_result_525 = (json_get(body, EL_STR("query"))); } _if_result_525; });
el_val_t q = ({ el_val_t _if_result_529 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_529 = (api_query_param(path, EL_STR("query"))); } else { _if_result_529 = (json_get(body, EL_STR("query"))); } _if_result_529; });
el_val_t limit = api_query_int(path, EL_STR("limit"), 20);
if (!str_eq(q, EL_STR(""))) {
return api_or_empty(engram_search_json(el_str_concat(EL_STR("internal state "), q), limit));
@@ -28988,7 +29066,7 @@ el_val_t handle_api_list_state_events(el_val_t method, el_val_t path, el_val_t b
el_val_t handle_api_inspect_config(el_val_t path, el_val_t body) {
el_val_t key = api_query_param(path, EL_STR("key"));
key = ({ el_val_t _if_result_526 = 0; if (str_eq(key, EL_STR(""))) { _if_result_526 = (json_get(body, EL_STR("key"))); } else { _if_result_526 = (key); } _if_result_526; });
key = ({ el_val_t _if_result_530 = 0; if (str_eq(key, EL_STR(""))) { _if_result_530 = (json_get(body, EL_STR("key"))); } else { _if_result_530 = (key); } _if_result_530; });
if (str_eq(key, EL_STR(""))) {
return EL_STR("{\"hint\":\"pass ?key=<name>\",\"known\":[\"neuron.self.traversal_root\",\"neuron.self.values_hub\"]}");
}
@@ -29005,7 +29083,7 @@ el_val_t handle_api_inspect_config(el_val_t path, el_val_t body) {
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_concat(el_str_concat(EL_STR("config:"), key), EL_STR("="));
el_val_t value = ({ el_val_t _if_result_527 = 0; if (str_starts_with(content, prefix)) { _if_result_527 = (str_slice(content, str_len(prefix), str_len(content))); } else { _if_result_527 = (content); } _if_result_527; });
el_val_t value = ({ el_val_t _if_result_531 = 0; if (str_starts_with(content, prefix)) { _if_result_531 = (str_slice(content, str_len(prefix), str_len(content))); } else { _if_result_531 = (content); } _if_result_531; });
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"key\":\""), key), EL_STR("\",\"value\":\"")), value), EL_STR("\"}"));
return 0;
}
@@ -29027,13 +29105,13 @@ el_val_t handle_api_tune_config(el_val_t body) {
}
el_val_t handle_api_inspect_graph(el_val_t method, el_val_t path, el_val_t body) {
el_val_t entity_id = ({ el_val_t _if_result_528 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_528 = (api_query_param(path, EL_STR("id"))); } else { _if_result_528 = (json_get(body, EL_STR("entity_id"))); } _if_result_528; });
el_val_t name = ({ el_val_t _if_result_529 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_529 = (api_query_param(path, EL_STR("name"))); } else { _if_result_529 = (json_get(body, EL_STR("name"))); } _if_result_529; });
el_val_t entity_id = ({ el_val_t _if_result_532 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_532 = (api_query_param(path, EL_STR("id"))); } else { _if_result_532 = (json_get(body, EL_STR("entity_id"))); } _if_result_532; });
el_val_t name = ({ el_val_t _if_result_533 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_533 = (api_query_param(path, EL_STR("name"))); } else { _if_result_533 = (json_get(body, EL_STR("name"))); } _if_result_533; });
el_val_t depth = api_query_int(path, EL_STR("depth"), 0);
depth = ({ el_val_t _if_result_530 = 0; if ((depth == 0)) { _if_result_530 = (json_get_int(body, EL_STR("max_depth"))); } else { _if_result_530 = (depth); } _if_result_530; });
depth = ({ el_val_t _if_result_531 = 0; if ((depth == 0)) { _if_result_531 = (1); } else { _if_result_531 = (depth); } _if_result_531; });
depth = ({ el_val_t _if_result_534 = 0; if ((depth == 0)) { _if_result_534 = (json_get_int(body, EL_STR("max_depth"))); } else { _if_result_534 = (depth); } _if_result_534; });
depth = ({ el_val_t _if_result_535 = 0; if ((depth == 0)) { _if_result_535 = (1); } else { _if_result_535 = (depth); } _if_result_535; });
el_val_t resolved = entity_id;
resolved = ({ el_val_t _if_result_532 = 0; if (str_eq(resolved, EL_STR(""))) { _if_result_532 = (({ el_val_t _if_result_533 = 0; if ((str_eq(name, EL_STR("self")) || str_eq(name, EL_STR("neuron")))) { _if_result_533 = (EL_STR("kn-efeb4a5b-5aff-4759-8a97-7233099be6ee")); } else { _if_result_533 = (({ el_val_t _if_result_534 = 0; if ((str_eq(name, EL_STR("values")) || str_eq(name, EL_STR("values_hub")))) { _if_result_534 = (EL_STR("kn-5b606390-a52d-4ca2-8e0e-eba141d13440")); } else { _if_result_534 = (EL_STR("")); } _if_result_534; })); } _if_result_533; })); } else { _if_result_532 = (resolved); } _if_result_532; });
resolved = ({ el_val_t _if_result_536 = 0; if (str_eq(resolved, EL_STR(""))) { _if_result_536 = (({ el_val_t _if_result_537 = 0; if ((str_eq(name, EL_STR("self")) || str_eq(name, EL_STR("neuron")))) { _if_result_537 = (EL_STR("kn-efeb4a5b-5aff-4759-8a97-7233099be6ee")); } else { _if_result_537 = (({ el_val_t _if_result_538 = 0; if ((str_eq(name, EL_STR("values")) || str_eq(name, EL_STR("values_hub")))) { _if_result_538 = (EL_STR("kn-5b606390-a52d-4ca2-8e0e-eba141d13440")); } else { _if_result_538 = (EL_STR("")); } _if_result_538; })); } _if_result_537; })); } else { _if_result_536 = (resolved); } _if_result_536; });
if (str_eq(resolved, EL_STR(""))) {
return api_err(EL_STR("entity_id or name required. Known names: self, neuron, values, values_hub"));
}
@@ -29055,7 +29133,7 @@ el_val_t handle_api_link_entities(el_val_t body) {
return api_err_protected(to_id);
}
el_val_t relation = json_get(body, EL_STR("relation"));
el_val_t eff_relation = ({ el_val_t _if_result_535 = 0; if (str_eq(relation, EL_STR(""))) { _if_result_535 = (EL_STR("associates")); } else { _if_result_535 = (relation); } _if_result_535; });
el_val_t eff_relation = ({ el_val_t _if_result_539 = 0; if (str_eq(relation, EL_STR(""))) { _if_result_539 = (EL_STR("associates")); } else { _if_result_539 = (relation); } _if_result_539; });
engram_connect(from_id, to_id, el_from_float(0.5), eff_relation);
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"from_id\":\""), from_id), EL_STR("\",\"to_id\":\"")), to_id), EL_STR("\",\"relation\":\"")), eff_relation), EL_STR("\"}"));
return 0;
@@ -29084,8 +29162,8 @@ el_val_t handle_api_evolve_memory(el_val_t body) {
return api_err_protected(prior_id);
}
el_val_t importance = json_get(body, EL_STR("importance"));
el_val_t sal_str = ({ el_val_t _if_result_536 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_536 = (EL_STR("0.95")); } else { _if_result_536 = (({ el_val_t _if_result_537 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_537 = (EL_STR("0.75")); } else { _if_result_537 = (({ el_val_t _if_result_538 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_538 = (EL_STR("0.25")); } else { _if_result_538 = (EL_STR("0.50")); } _if_result_538; })); } _if_result_537; })); } _if_result_536; });
el_val_t sal = ({ el_val_t _if_result_539 = 0; if (str_eq(sal_str, EL_STR("0.95"))) { _if_result_539 = (el_from_float(0.95)); } else { _if_result_539 = (({ el_val_t _if_result_540 = 0; if (str_eq(sal_str, EL_STR("0.75"))) { _if_result_540 = (el_from_float(0.75)); } else { _if_result_540 = (({ el_val_t _if_result_541 = 0; if (str_eq(sal_str, EL_STR("0.25"))) { _if_result_541 = (el_from_float(0.25)); } else { _if_result_541 = (el_from_float(0.5)); } _if_result_541; })); } _if_result_540; })); } _if_result_539; });
el_val_t sal_str = ({ el_val_t _if_result_540 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_540 = (EL_STR("0.95")); } else { _if_result_540 = (({ el_val_t _if_result_541 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_541 = (EL_STR("0.75")); } else { _if_result_541 = (({ el_val_t _if_result_542 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_542 = (EL_STR("0.25")); } else { _if_result_542 = (EL_STR("0.50")); } _if_result_542; })); } _if_result_541; })); } _if_result_540; });
el_val_t sal = ({ el_val_t _if_result_543 = 0; if (str_eq(sal_str, EL_STR("0.95"))) { _if_result_543 = (el_from_float(0.95)); } else { _if_result_543 = (({ el_val_t _if_result_544 = 0; if (str_eq(sal_str, EL_STR("0.75"))) { _if_result_544 = (el_from_float(0.75)); } else { _if_result_544 = (({ el_val_t _if_result_545 = 0; if (str_eq(sal_str, EL_STR("0.25"))) { _if_result_545 = (el_from_float(0.25)); } else { _if_result_545 = (el_from_float(0.5)); } _if_result_545; })); } _if_result_544; })); } _if_result_543; });
el_val_t tags = EL_STR("[\"Memory\",\"evolved\"]");
el_val_t new_id = engram_node_full(content, EL_STR("Memory"), EL_STR("memory:evolved"), el_from_float(sal), el_from_float(sal), el_from_float(0.9), EL_STR("Episodic"), tags);
if (!str_eq(prior_id, EL_STR("")) && !str_eq(new_id, EL_STR(""))) {
@@ -29107,8 +29185,11 @@ el_val_t handle_api_memory_delete(el_val_t body) {
if (str_eq(existing, EL_STR("{}"))) {
return api_err(el_str_concat(EL_STR("memory not found: "), node_id));
}
mem_forget(node_id);
return el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"id\":\""), node_id), EL_STR("\",\"deleted\":true}"));
el_val_t marker = tombstone_node(node_id);
if (str_eq(marker, EL_STR(""))) {
return api_err(el_str_concat(EL_STR("tombstone failed: "), node_id));
}
return el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"id\":\""), node_id), EL_STR("\",\"tombstoned\":true}"));
return 0;
}
@@ -29157,7 +29238,7 @@ el_val_t handle_api_cultivate(el_val_t body) {
return api_err(EL_STR("content is required"));
}
el_val_t importance = json_get(body, EL_STR("importance"));
el_val_t sal = ({ el_val_t _if_result_542 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_542 = (el_from_float(0.95)); } else { _if_result_542 = (({ el_val_t _if_result_543 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_543 = (el_from_float(0.75)); } else { _if_result_543 = (({ el_val_t _if_result_544 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_544 = (el_from_float(0.25)); } else { _if_result_544 = (el_from_float(0.5)); } _if_result_544; })); } _if_result_543; })); } _if_result_542; });
el_val_t sal = ({ el_val_t _if_result_546 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_546 = (el_from_float(0.95)); } else { _if_result_546 = (({ el_val_t _if_result_547 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_547 = (el_from_float(0.75)); } else { _if_result_547 = (({ el_val_t _if_result_548 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_548 = (el_from_float(0.25)); } else { _if_result_548 = (el_from_float(0.5)); } _if_result_548; })); } _if_result_547; })); } _if_result_546; });
el_val_t tags = EL_STR("[\"Memory\",\"evolved\",\"cultivated\"]");
el_val_t new_id = engram_node_full(content, EL_STR("Memory"), EL_STR("memory:cultivated"), el_from_float(sal), el_from_float(sal), el_from_float(0.9), EL_STR("Episodic"), tags);
if (!str_eq(prior_id, EL_STR("")) && !str_eq(new_id, EL_STR(""))) {
@@ -29183,7 +29264,7 @@ el_val_t handle_api_cultivate(el_val_t body) {
return api_err(EL_STR("to_id is required"));
}
el_val_t relation = json_get(body, EL_STR("relation"));
el_val_t eff_relation = ({ el_val_t _if_result_545 = 0; if (str_eq(relation, EL_STR(""))) { _if_result_545 = (EL_STR("associates")); } else { _if_result_545 = (relation); } _if_result_545; });
el_val_t eff_relation = ({ el_val_t _if_result_549 = 0; if (str_eq(relation, EL_STR(""))) { _if_result_549 = (EL_STR("associates")); } else { _if_result_549 = (relation); } _if_result_549; });
engram_connect(from_id, to_id, el_from_float(0.5), eff_relation);
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"from_id\":\""), from_id), EL_STR("\",\"to_id\":\"")), to_id), EL_STR("\",\"relation\":\"")), eff_relation), EL_STR("\",\"cultivated\":true}"));
}
@@ -29193,7 +29274,8 @@ el_val_t handle_api_cultivate(el_val_t body) {
el_val_t handle_api_list_typed(el_val_t node_type, el_val_t path, el_val_t body) {
el_val_t limit = api_query_int(path, EL_STR("limit"), 50);
return api_or_empty(engram_scan_nodes_by_type_json(node_type, limit, 0));
el_val_t raw = api_or_empty(engram_scan_nodes_by_type_json(node_type, limit, 0));
return memory_hide_tombstoned(raw, path);
return 0;
}
@@ -29263,7 +29345,7 @@ el_val_t session_exists(el_val_t session_id) {
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 = ({ el_val_t _if_result_546 = 0; if (is_match) { _if_result_546 = (1); } else { _if_result_546 = (found); } _if_result_546; });
found = ({ el_val_t _if_result_550 = 0; if (is_match) { _if_result_550 = (1); } else { _if_result_550 = (found); } _if_result_550; });
i = (i + 1);
}
return found;
@@ -29274,7 +29356,7 @@ el_val_t session_create(el_val_t body) {
el_val_t ts = time_now();
el_val_t id = uuid_v4();
el_val_t title_req = json_get(body, EL_STR("title"));
el_val_t title = ({ el_val_t _if_result_547 = 0; if (str_eq(title_req, EL_STR(""))) { _if_result_547 = (EL_STR("New conversation")); } else { _if_result_547 = (title_req); } _if_result_547; });
el_val_t title = ({ el_val_t _if_result_551 = 0; if (str_eq(title_req, EL_STR(""))) { _if_result_551 = (EL_STR("New conversation")); } else { _if_result_551 = (title_req); } _if_result_551; });
el_val_t folder = json_get(body, EL_STR("folder"));
el_val_t content = session_make_content(id, title, ts, ts, folder);
el_val_t tags = EL_STR("[\"session\",\"session:meta\",\"Conversation\"]");
@@ -29286,7 +29368,7 @@ el_val_t session_create(el_val_t body) {
state_set(el_str_concat(EL_STR("session_pending_first_msg_"), id), EL_STR("1"));
el_val_t existing_idx = state_get(EL_STR("session_index"));
el_val_t idx_entry = 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("{\"id\":\""), id), EL_STR("\",\"title\":\"")), json_safe(title)), EL_STR("\",\"folder\":\"")), json_safe(folder)), EL_STR("\",\"created_at\":")), int_to_str(ts)), EL_STR(",\"updated_at\":")), int_to_str(ts)), EL_STR(",\"last_message\":\"\"}"));
el_val_t new_idx = ({ el_val_t _if_result_548 = 0; if (str_eq(existing_idx, EL_STR(""))) { _if_result_548 = (el_str_concat(el_str_concat(EL_STR("["), idx_entry), EL_STR("]"))); } else { el_val_t inner = str_slice(existing_idx, 1, (str_len(existing_idx) - 1)); _if_result_548 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("["), idx_entry), EL_STR(",")), inner), EL_STR("]"))); } _if_result_548; });
el_val_t new_idx = ({ el_val_t _if_result_552 = 0; if (str_eq(existing_idx, EL_STR(""))) { _if_result_552 = (el_str_concat(el_str_concat(EL_STR("["), idx_entry), EL_STR("]"))); } else { el_val_t inner = str_slice(existing_idx, 1, (str_len(existing_idx) - 1)); _if_result_552 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("["), idx_entry), EL_STR(",")), inner), EL_STR("]"))); } _if_result_552; });
state_set(EL_STR("session_index"), new_idx);
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_concat(el_str_concat(EL_STR("{\"id\":\""), id), EL_STR("\"")), EL_STR(",\"title\":\"")), json_safe(title)), EL_STR("\"")), EL_STR(",\"folder\":\"")), json_safe(folder)), EL_STR("\"")), EL_STR(",\"node_id\":\"")), node_id), EL_STR("\"")), EL_STR(",\"created_at\":")), int_to_str(ts)), EL_STR("}"));
return 0;
@@ -29323,16 +29405,16 @@ el_val_t session_list(void) {
el_val_t is_session = (str_eq(label, EL_STR("session:meta")) && str_eq(node_type, EL_STR("Conversation")));
el_val_t content = json_get(node, EL_STR("content"));
el_val_t sess_id = json_get(content, EL_STR("id"));
el_val_t eff_id = ({ el_val_t _if_result_549 = 0; if (str_eq(sess_id, EL_STR(""))) { _if_result_549 = (json_get(node, EL_STR("id"))); } else { _if_result_549 = (sess_id); } _if_result_549; });
el_val_t eff_id = ({ el_val_t _if_result_553 = 0; if (str_eq(sess_id, EL_STR(""))) { _if_result_553 = (json_get(node, EL_STR("id"))); } else { _if_result_553 = (sess_id); } _if_result_553; });
el_val_t title_inner = json_get(content, EL_STR("title"));
el_val_t eff_title = ({ el_val_t _if_result_550 = 0; if (str_eq(title_inner, EL_STR(""))) { _if_result_550 = (EL_STR("New conversation")); } else { _if_result_550 = (title_inner); } _if_result_550; });
el_val_t eff_title = ({ el_val_t _if_result_554 = 0; if (str_eq(title_inner, EL_STR(""))) { _if_result_554 = (EL_STR("New conversation")); } else { _if_result_554 = (title_inner); } _if_result_554; });
el_val_t folder_inner = json_get(content, EL_STR("folder"));
el_val_t created_inner = json_get(content, EL_STR("created_at"));
el_val_t updated_inner = json_get(content, EL_STR("updated_at"));
el_val_t eff_created = ({ el_val_t _if_result_551 = 0; if (str_eq(created_inner, EL_STR(""))) { _if_result_551 = (EL_STR("0")); } else { _if_result_551 = (created_inner); } _if_result_551; });
el_val_t eff_updated = ({ el_val_t _if_result_552 = 0; if (str_eq(updated_inner, EL_STR(""))) { _if_result_552 = (eff_created); } else { _if_result_552 = (updated_inner); } _if_result_552; });
el_val_t entry = ({ el_val_t _if_result_553 = 0; if (is_session) { _if_result_553 = (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("{\"id\":\""), json_safe(eff_id)), EL_STR("\"")), EL_STR(",\"title\":\"")), json_safe(eff_title)), EL_STR("\"")), EL_STR(",\"folder\":\"")), json_safe(folder_inner)), EL_STR("\"")), EL_STR(",\"last_message\":\"\"")), EL_STR(",\"created_at\":")), eff_created), EL_STR(",\"updated_at\":")), eff_updated), EL_STR("}"))); } else { _if_result_553 = (EL_STR("")); } _if_result_553; });
out = ({ el_val_t _if_result_554 = 0; if (!str_eq(entry, EL_STR(""))) { _if_result_554 = (({ el_val_t _if_result_555 = 0; if (str_eq(out, EL_STR(""))) { _if_result_555 = (entry); } else { _if_result_555 = (el_str_concat(el_str_concat(out, EL_STR(",")), entry)); } _if_result_555; })); } else { _if_result_554 = (out); } _if_result_554; });
el_val_t eff_created = ({ el_val_t _if_result_555 = 0; if (str_eq(created_inner, EL_STR(""))) { _if_result_555 = (EL_STR("0")); } else { _if_result_555 = (created_inner); } _if_result_555; });
el_val_t eff_updated = ({ el_val_t _if_result_556 = 0; if (str_eq(updated_inner, EL_STR(""))) { _if_result_556 = (eff_created); } else { _if_result_556 = (updated_inner); } _if_result_556; });
el_val_t entry = ({ el_val_t _if_result_557 = 0; if (is_session) { _if_result_557 = (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("{\"id\":\""), json_safe(eff_id)), EL_STR("\"")), EL_STR(",\"title\":\"")), json_safe(eff_title)), EL_STR("\"")), EL_STR(",\"folder\":\"")), json_safe(folder_inner)), EL_STR("\"")), EL_STR(",\"last_message\":\"\"")), EL_STR(",\"created_at\":")), eff_created), EL_STR(",\"updated_at\":")), eff_updated), EL_STR("}"))); } else { _if_result_557 = (EL_STR("")); } _if_result_557; });
out = ({ el_val_t _if_result_558 = 0; if (!str_eq(entry, EL_STR(""))) { _if_result_558 = (({ el_val_t _if_result_559 = 0; if (str_eq(out, EL_STR(""))) { _if_result_559 = (entry); } else { _if_result_559 = (el_str_concat(el_str_concat(out, EL_STR(",")), entry)); } _if_result_559; })); } else { _if_result_558 = (out); } _if_result_558; });
i = (i + 1);
}
return el_str_concat(el_str_concat(EL_STR("["), out), EL_STR("]"));
@@ -29350,7 +29432,7 @@ el_val_t session_get(el_val_t session_id) {
el_val_t meta_created = EL_STR("0");
el_val_t meta_updated = EL_STR("0");
el_val_t found = 0;
el_val_t total = ({ el_val_t _if_result_556 = 0; if (str_eq(results, EL_STR(""))) { _if_result_556 = (0); } else { _if_result_556 = (json_array_len(results)); } _if_result_556; });
el_val_t total = ({ el_val_t _if_result_560 = 0; if (str_eq(results, EL_STR(""))) { _if_result_560 = (0); } else { _if_result_560 = (json_array_len(results)); } _if_result_560; });
el_val_t i = 0;
while (i < total) {
el_val_t node = json_array_get(results, i);
@@ -29358,17 +29440,17 @@ el_val_t session_get(el_val_t session_id) {
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_557 = 0; if (is_match) { _if_result_557 = (1); } else { _if_result_557 = (found); } _if_result_557; });
meta_title = ({ el_val_t _if_result_558 = 0; if (is_match) { _if_result_558 = (json_get(content, EL_STR("title"))); } else { _if_result_558 = (meta_title); } _if_result_558; });
meta_folder = ({ el_val_t _if_result_559 = 0; if (is_match) { _if_result_559 = (json_get(content, EL_STR("folder"))); } else { _if_result_559 = (meta_folder); } _if_result_559; });
found = ({ el_val_t _if_result_561 = 0; if (is_match) { _if_result_561 = (1); } else { _if_result_561 = (found); } _if_result_561; });
meta_title = ({ el_val_t _if_result_562 = 0; if (is_match) { _if_result_562 = (json_get(content, EL_STR("title"))); } else { _if_result_562 = (meta_title); } _if_result_562; });
meta_folder = ({ el_val_t _if_result_563 = 0; if (is_match) { _if_result_563 = (json_get(content, EL_STR("folder"))); } else { _if_result_563 = (meta_folder); } _if_result_563; });
el_val_t meta_created_raw = json_get(content, EL_STR("created_at"));
meta_created = ({ el_val_t _if_result_560 = 0; if ((is_match && !str_eq(meta_created_raw, EL_STR("")))) { _if_result_560 = (meta_created_raw); } else { _if_result_560 = (meta_created); } _if_result_560; });
meta_created = ({ el_val_t _if_result_564 = 0; if ((is_match && !str_eq(meta_created_raw, EL_STR("")))) { _if_result_564 = (meta_created_raw); } else { _if_result_564 = (meta_created); } _if_result_564; });
el_val_t meta_updated_raw = json_get(content, EL_STR("updated_at"));
meta_updated = ({ el_val_t _if_result_561 = 0; if ((is_match && !str_eq(meta_updated_raw, EL_STR("")))) { _if_result_561 = (meta_updated_raw); } else { _if_result_561 = (meta_updated); } _if_result_561; });
meta_updated = ({ el_val_t _if_result_565 = 0; if ((is_match && !str_eq(meta_updated_raw, EL_STR("")))) { _if_result_565 = (meta_updated_raw); } else { _if_result_565 = (meta_updated); } _if_result_565; });
i = (i + 1);
}
el_val_t state_hist = state_get(el_str_concat(EL_STR("session_hist_"), session_id));
el_val_t hist_raw = ({ el_val_t _if_result_562 = 0; if (str_eq(state_hist, EL_STR(""))) { el_val_t engram_hist = engram_search_json(el_str_concat(EL_STR("session:messages:"), session_id), 3); _if_result_562 = (({ el_val_t _if_result_563 = 0; if (str_eq(engram_hist, EL_STR(""))) { _if_result_563 = (EL_STR("[]")); } else { _if_result_563 = (({ el_val_t _if_result_564 = 0; if (str_eq(engram_hist, EL_STR("[]"))) { _if_result_564 = (EL_STR("[]")); } else { el_val_t h_node = json_array_get(engram_hist, 0); el_val_t h_content = json_get(h_node, EL_STR("content")); _if_result_564 = (({ el_val_t _if_result_565 = 0; if (str_starts_with(h_content, EL_STR("["))) { _if_result_565 = (h_content); } else { _if_result_565 = (EL_STR("[]")); } _if_result_565; })); } _if_result_564; })); } _if_result_563; })); } else { _if_result_562 = (state_hist); } _if_result_562; });
el_val_t hist_raw = ({ el_val_t _if_result_566 = 0; if (str_eq(state_hist, EL_STR(""))) { el_val_t engram_hist = engram_search_json(el_str_concat(EL_STR("session:messages:"), session_id), 3); _if_result_566 = (({ el_val_t _if_result_567 = 0; if (str_eq(engram_hist, EL_STR(""))) { _if_result_567 = (EL_STR("[]")); } else { _if_result_567 = (({ el_val_t _if_result_568 = 0; if (str_eq(engram_hist, EL_STR("[]"))) { _if_result_568 = (EL_STR("[]")); } else { el_val_t h_node = json_array_get(engram_hist, 0); el_val_t h_content = json_get(h_node, EL_STR("content")); _if_result_568 = (({ el_val_t _if_result_569 = 0; if (str_starts_with(h_content, EL_STR("["))) { _if_result_569 = (h_content); } else { _if_result_569 = (EL_STR("[]")); } _if_result_569; })); } _if_result_568; })); } _if_result_567; })); } else { _if_result_566 = (state_hist); } _if_result_566; });
el_val_t safe_title = json_safe(meta_title);
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_concat(el_str_concat(el_str_concat(EL_STR("{\"id\":\""), session_id), EL_STR("\"")), EL_STR(",\"title\":\"")), safe_title), EL_STR("\"")), EL_STR(",\"folder\":\"")), json_safe(meta_folder)), EL_STR("\"")), EL_STR(",\"created_at\":")), meta_created), EL_STR(",\"updated_at\":")), meta_updated), EL_STR(",\"messages\":")), hist_raw), EL_STR("}"));
return 0;
@@ -29379,7 +29461,7 @@ el_val_t session_delete(el_val_t session_id) {
return EL_STR("{\"error\":\"session_id is required\"}");
}
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_566 = 0; if (str_eq(results, EL_STR(""))) { _if_result_566 = (0); } else { _if_result_566 = (json_array_len(results)); } _if_result_566; });
el_val_t total = ({ el_val_t _if_result_570 = 0; if (str_eq(results, EL_STR(""))) { _if_result_570 = (0); } else { _if_result_570 = (json_array_len(results)); } _if_result_570; });
el_val_t deleted_meta = 0;
el_val_t i = 0;
while (i < total) {
@@ -29389,11 +29471,11 @@ el_val_t session_delete(el_val_t session_id) {
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));
el_val_t node_id = json_get(node, EL_STR("id"));
deleted_meta = ({ el_val_t _if_result_567 = 0; if ((is_match && !str_eq(node_id, EL_STR("")))) { (void)(engram_forget(node_id)); _if_result_567 = ((deleted_meta + 1)); } else { _if_result_567 = (deleted_meta); } _if_result_567; });
deleted_meta = ({ el_val_t _if_result_571 = 0; if ((is_match && !str_eq(node_id, EL_STR("")))) { (void)(engram_forget(node_id)); _if_result_571 = ((deleted_meta + 1)); } else { _if_result_571 = (deleted_meta); } _if_result_571; });
i = (i + 1);
}
el_val_t msg_results = engram_search_json(el_str_concat(EL_STR("session:messages:"), session_id), 10);
el_val_t m_total = ({ el_val_t _if_result_568 = 0; if (str_eq(msg_results, EL_STR(""))) { _if_result_568 = (0); } else { _if_result_568 = (json_array_len(msg_results)); } _if_result_568; });
el_val_t m_total = ({ el_val_t _if_result_572 = 0; if (str_eq(msg_results, EL_STR(""))) { _if_result_572 = (0); } else { _if_result_572 = (json_array_len(msg_results)); } _if_result_572; });
el_val_t deleted_msgs = 0;
el_val_t j = 0;
while (j < m_total) {
@@ -29401,7 +29483,7 @@ el_val_t session_delete(el_val_t session_id) {
el_val_t label = json_get(node, EL_STR("label"));
el_val_t is_msgs = str_eq(label, el_str_concat(EL_STR("session:messages:"), session_id));
el_val_t node_id = json_get(node, EL_STR("id"));
deleted_msgs = ({ el_val_t _if_result_569 = 0; if ((is_msgs && !str_eq(node_id, EL_STR("")))) { (void)(engram_forget(node_id)); _if_result_569 = ((deleted_msgs + 1)); } else { _if_result_569 = (deleted_msgs); } _if_result_569; });
deleted_msgs = ({ el_val_t _if_result_573 = 0; if ((is_msgs && !str_eq(node_id, EL_STR("")))) { (void)(engram_forget(node_id)); _if_result_573 = ((deleted_msgs + 1)); } else { _if_result_573 = (deleted_msgs); } _if_result_573; });
j = (j + 1);
}
state_set(el_str_concat(EL_STR("session_hist_"), session_id), EL_STR(""));
@@ -29424,7 +29506,7 @@ el_val_t session_update_patch(el_val_t session_id, el_val_t body) {
return EL_STR("{\"error\":\"title or folder required in body\"}");
}
el_val_t results = engram_search_json(EL_STR("session:meta"), 50);
el_val_t total = ({ el_val_t _if_result_570 = 0; if (str_eq(results, EL_STR(""))) { _if_result_570 = (0); } else { _if_result_570 = (json_array_len(results)); } _if_result_570; });
el_val_t total = ({ el_val_t _if_result_574 = 0; if (str_eq(results, EL_STR(""))) { _if_result_574 = (0); } else { _if_result_574 = (json_array_len(results)); } _if_result_574; });
el_val_t found = 0;
el_val_t old_title = EL_STR("New conversation");
el_val_t old_folder = EL_STR("");
@@ -29437,23 +29519,23 @@ el_val_t session_update_patch(el_val_t session_id, el_val_t body) {
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_571 = 0; if (is_match) { _if_result_571 = (1); } else { _if_result_571 = (found); } _if_result_571; });
found = ({ el_val_t _if_result_575 = 0; if (is_match) { _if_result_575 = (1); } else { _if_result_575 = (found); } _if_result_575; });
el_val_t title_raw = json_get(content, EL_STR("title"));
old_title = ({ el_val_t _if_result_572 = 0; if ((is_match && !str_eq(title_raw, EL_STR("")))) { _if_result_572 = (title_raw); } else { _if_result_572 = (old_title); } _if_result_572; });
old_title = ({ el_val_t _if_result_576 = 0; if ((is_match && !str_eq(title_raw, EL_STR("")))) { _if_result_576 = (title_raw); } else { _if_result_576 = (old_title); } _if_result_576; });
el_val_t folder_raw = json_get(content, EL_STR("folder"));
old_folder = ({ el_val_t _if_result_573 = 0; if (is_match) { _if_result_573 = (folder_raw); } else { _if_result_573 = (old_folder); } _if_result_573; });
old_folder = ({ el_val_t _if_result_577 = 0; if (is_match) { _if_result_577 = (folder_raw); } else { _if_result_577 = (old_folder); } _if_result_577; });
el_val_t created_raw = json_get(content, EL_STR("created_at"));
old_created = ({ el_val_t _if_result_574 = 0; if ((is_match && !str_eq(created_raw, EL_STR("")))) { _if_result_574 = (created_raw); } else { _if_result_574 = (old_created); } _if_result_574; });
old_created = ({ el_val_t _if_result_578 = 0; if ((is_match && !str_eq(created_raw, EL_STR("")))) { _if_result_578 = (created_raw); } else { _if_result_578 = (old_created); } _if_result_578; });
el_val_t nid = json_get(node, EL_STR("id"));
old_node_id = ({ el_val_t _if_result_575 = 0; if (is_match) { _if_result_575 = (nid); } else { _if_result_575 = (old_node_id); } _if_result_575; });
old_node_id = ({ el_val_t _if_result_579 = 0; if (is_match) { _if_result_579 = (nid); } else { _if_result_579 = (old_node_id); } _if_result_579; });
i = (i + 1);
}
if (!found) {
return el_str_concat(el_str_concat(EL_STR("{\"error\":\"session not found\",\"session_id\":\""), session_id), EL_STR("\"}"));
}
el_val_t req_title = json_get(body, EL_STR("title"));
el_val_t eff_title = ({ el_val_t _if_result_576 = 0; if ((has_title && !str_eq(req_title, EL_STR("")))) { _if_result_576 = (req_title); } else { _if_result_576 = (old_title); } _if_result_576; });
el_val_t eff_folder = ({ el_val_t _if_result_577 = 0; if (has_folder) { _if_result_577 = (json_get(body, EL_STR("folder"))); } else { _if_result_577 = (old_folder); } _if_result_577; });
el_val_t eff_title = ({ el_val_t _if_result_580 = 0; if ((has_title && !str_eq(req_title, EL_STR("")))) { _if_result_580 = (req_title); } else { _if_result_580 = (old_title); } _if_result_580; });
el_val_t eff_folder = ({ el_val_t _if_result_581 = 0; if (has_folder) { _if_result_581 = (json_get(body, EL_STR("folder"))); } else { _if_result_581 = (old_folder); } _if_result_581; });
if (!str_eq(old_node_id, EL_STR(""))) {
engram_forget(old_node_id);
}
@@ -29481,8 +29563,8 @@ el_val_t session_search_entry(el_val_t node) {
el_val_t title = json_get(content, EL_STR("title"));
el_val_t created_raw = json_get(content, EL_STR("created_at"));
el_val_t updated_raw = json_get(content, EL_STR("updated_at"));
el_val_t eff_created = ({ el_val_t _if_result_578 = 0; if (str_eq(created_raw, EL_STR(""))) { _if_result_578 = (EL_STR("0")); } else { _if_result_578 = (created_raw); } _if_result_578; });
el_val_t eff_updated = ({ el_val_t _if_result_579 = 0; if (str_eq(updated_raw, EL_STR(""))) { _if_result_579 = (eff_created); } else { _if_result_579 = (updated_raw); } _if_result_579; });
el_val_t eff_created = ({ el_val_t _if_result_582 = 0; if (str_eq(created_raw, EL_STR(""))) { _if_result_582 = (EL_STR("0")); } else { _if_result_582 = (created_raw); } _if_result_582; });
el_val_t eff_updated = ({ el_val_t _if_result_583 = 0; if (str_eq(updated_raw, EL_STR(""))) { _if_result_583 = (eff_created); } else { _if_result_583 = (updated_raw); } _if_result_583; });
el_val_t e_id = el_str_concat(el_str_concat(EL_STR("{\"id\":\""), json_safe(sess_id)), EL_STR("\""));
el_val_t e_title = el_str_concat(el_str_concat(EL_STR(",\"title\":\""), json_safe(title)), EL_STR("\""));
el_val_t e_ts = el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR(",\"created_at\":"), eff_created), EL_STR(",\"updated_at\":")), eff_updated), EL_STR("}"));
@@ -29506,7 +29588,7 @@ el_val_t session_search(el_val_t query) {
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_580 = 0; if (!str_eq(entry, EL_STR(""))) { _if_result_580 = (({ el_val_t _if_result_581 = 0; if (str_eq(out, EL_STR(""))) { _if_result_581 = (entry); } else { _if_result_581 = (el_str_concat(el_str_concat(out, EL_STR(",")), entry)); } _if_result_581; })); } else { _if_result_580 = (out); } _if_result_580; });
out = ({ el_val_t _if_result_584 = 0; if (!str_eq(entry, EL_STR(""))) { _if_result_584 = (({ el_val_t _if_result_585 = 0; if (str_eq(out, EL_STR(""))) { _if_result_585 = (entry); } else { _if_result_585 = (el_str_concat(el_str_concat(out, EL_STR(",")), entry)); } _if_result_585; })); } else { _if_result_584 = (out); } _if_result_584; });
i = (i + 1);
}
return el_str_concat(el_str_concat(EL_STR("["), out), EL_STR("]"));
@@ -29542,7 +29624,7 @@ 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_582 = 0; if (str_eq(old_results, EL_STR(""))) { _if_result_582 = (0); } else { _if_result_582 = (json_array_len(old_results)); } _if_result_582; });
el_val_t o_total = ({ el_val_t _if_result_586 = 0; if (str_eq(old_results, EL_STR(""))) { _if_result_586 = (0); } else { _if_result_586 = (json_array_len(old_results)); } _if_result_586; });
el_val_t oi = 0;
while (oi < o_total) {
el_val_t node = json_array_get(old_results, oi);
@@ -29560,35 +29642,35 @@ el_val_t session_hist_save(el_val_t session_id, el_val_t hist) {
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_583 = 0; if (str_eq(bell_count_raw, EL_STR(""))) { _if_result_583 = (0); } else { _if_result_583 = (str_to_int(bell_count_raw)); } _if_result_583; });
el_val_t bell_count = ({ el_val_t _if_result_587 = 0; if (str_eq(bell_count_raw, EL_STR(""))) { _if_result_587 = (0); } else { _if_result_587 = (str_to_int(bell_count_raw)); } _if_result_587; });
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_584 = 0; if (str_eq(dominant_level, EL_STR(""))) { _if_result_584 = (EL_STR("soft")); } else { _if_result_584 = (dominant_level); } _if_result_584; });
el_val_t eff_signal = ({ el_val_t _if_result_585 = 0; if (str_eq(last_signal, EL_STR(""))) { _if_result_585 = (EL_STR("(no signal captured)")); } else { _if_result_585 = (last_signal); } _if_result_585; });
el_val_t eff_level = ({ el_val_t _if_result_588 = 0; if (str_eq(dominant_level, EL_STR(""))) { _if_result_588 = (EL_STR("soft")); } else { _if_result_588 = (dominant_level); } _if_result_588; });
el_val_t eff_signal = ({ el_val_t _if_result_589 = 0; if (str_eq(last_signal, EL_STR(""))) { _if_result_589 = (EL_STR("(no signal captured)")); } else { _if_result_589 = (last_signal); } _if_result_589; });
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_586 = 0; if (str_eq(eff_level, EL_STR("hard"))) { _if_result_586 = (el_from_float(0.95)); } else { _if_result_586 = (el_from_float(0.85)); } _if_result_586; });
el_val_t summary_sal = ({ el_val_t _if_result_590 = 0; if (str_eq(eff_level, EL_STR("hard"))) { _if_result_590 = (el_from_float(0.95)); } else { _if_result_590 = (el_from_float(0.85)); } _if_result_590; });
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_587 = 0; if (str_eq(hist, EL_STR(""))) { _if_result_587 = (0); } else { _if_result_587 = (json_array_len(hist)); } _if_result_587; });
el_val_t hist_arr_len = ({ el_val_t _if_result_591 = 0; if (str_eq(hist, EL_STR(""))) { _if_result_591 = (0); } else { _if_result_591 = (json_array_len(hist)); } _if_result_591; });
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_588 = 0; if ((str_len(last_content) > 200)) { _if_result_588 = (str_slice(last_content, 0, 200)); } else { _if_result_588 = (last_content); } _if_result_588; });
el_val_t topic_snip = ({ el_val_t _if_result_592 = 0; if ((str_len(last_content) > 200)) { _if_result_592 = (str_slice(last_content, 0, 200)); } else { _if_result_592 = (last_content); } _if_result_592; });
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_589 = 0; if (str_eq(old_topic, EL_STR(""))) { _if_result_589 = (0); } else { _if_result_589 = (json_array_len(old_topic)); } _if_result_589; });
el_val_t ot_len = ({ el_val_t _if_result_593 = 0; if (str_eq(old_topic, EL_STR(""))) { _if_result_593 = (0); } else { _if_result_593 = (json_array_len(old_topic)); } _if_result_593; });
el_val_t oti = 0;
while (oti < ot_len) {
el_val_t ot_node = json_array_get(old_topic, oti);
@@ -29605,7 +29687,7 @@ 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 results = engram_search_json(el_str_concat(EL_STR("session:meta "), session_id), 10);
el_val_t total = ({ el_val_t _if_result_590 = 0; if (str_eq(results, EL_STR(""))) { _if_result_590 = (0); } else { _if_result_590 = (json_array_len(results)); } _if_result_590; });
el_val_t total = ({ el_val_t _if_result_594 = 0; if (str_eq(results, EL_STR(""))) { _if_result_594 = (0); } else { _if_result_594 = (json_array_len(results)); } _if_result_594; });
el_val_t found = 0;
el_val_t old_title = EL_STR("New conversation");
el_val_t old_folder = EL_STR("");
@@ -29618,15 +29700,15 @@ el_val_t session_update_meta_timestamp(el_val_t session_id) {
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_591 = 0; if (is_match) { _if_result_591 = (1); } else { _if_result_591 = (found); } _if_result_591; });
found = ({ el_val_t _if_result_595 = 0; if (is_match) { _if_result_595 = (1); } else { _if_result_595 = (found); } _if_result_595; });
el_val_t title_raw = json_get(content, EL_STR("title"));
old_title = ({ el_val_t _if_result_592 = 0; if ((is_match && !str_eq(title_raw, EL_STR("")))) { _if_result_592 = (title_raw); } else { _if_result_592 = (old_title); } _if_result_592; });
old_title = ({ el_val_t _if_result_596 = 0; if ((is_match && !str_eq(title_raw, EL_STR("")))) { _if_result_596 = (title_raw); } else { _if_result_596 = (old_title); } _if_result_596; });
el_val_t folder_raw = json_get(content, EL_STR("folder"));
old_folder = ({ el_val_t _if_result_593 = 0; if (is_match) { _if_result_593 = (folder_raw); } else { _if_result_593 = (old_folder); } _if_result_593; });
old_folder = ({ el_val_t _if_result_597 = 0; if (is_match) { _if_result_597 = (folder_raw); } else { _if_result_597 = (old_folder); } _if_result_597; });
el_val_t created_raw = json_get(content, EL_STR("created_at"));
old_created = ({ el_val_t _if_result_594 = 0; if ((is_match && !str_eq(created_raw, EL_STR("")))) { _if_result_594 = (created_raw); } else { _if_result_594 = (old_created); } _if_result_594; });
old_created = ({ el_val_t _if_result_598 = 0; if ((is_match && !str_eq(created_raw, EL_STR("")))) { _if_result_598 = (created_raw); } else { _if_result_598 = (old_created); } _if_result_598; });
el_val_t nid = json_get(node, EL_STR("id"));
old_node_id = ({ el_val_t _if_result_595 = 0; if (is_match) { _if_result_595 = (nid); } else { _if_result_595 = (old_node_id); } _if_result_595; });
old_node_id = ({ el_val_t _if_result_599 = 0; if (is_match) { _if_result_599 = (nid); } else { _if_result_599 = (old_node_id); } _if_result_599; });
i = (i + 1);
}
if (!found) {
@@ -29646,7 +29728,7 @@ 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 results = engram_search_json(el_str_concat(EL_STR("session:meta "), session_id), 10);
el_val_t total = ({ el_val_t _if_result_596 = 0; if (str_eq(results, EL_STR(""))) { _if_result_596 = (0); } else { _if_result_596 = (json_array_len(results)); } _if_result_596; });
el_val_t total = ({ el_val_t _if_result_600 = 0; if (str_eq(results, EL_STR(""))) { _if_result_600 = (0); } else { _if_result_600 = (json_array_len(results)); } _if_result_600; });
el_val_t found = 0;
el_val_t cur_title = EL_STR("");
el_val_t old_folder = EL_STR("");
@@ -29659,15 +29741,15 @@ el_val_t session_auto_title(el_val_t session_id, el_val_t first_message) {
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_597 = 0; if (is_match) { _if_result_597 = (1); } else { _if_result_597 = (found); } _if_result_597; });
found = ({ el_val_t _if_result_601 = 0; if (is_match) { _if_result_601 = (1); } else { _if_result_601 = (found); } _if_result_601; });
el_val_t title_raw = json_get(content, EL_STR("title"));
cur_title = ({ el_val_t _if_result_598 = 0; if (is_match) { _if_result_598 = (title_raw); } else { _if_result_598 = (cur_title); } _if_result_598; });
cur_title = ({ el_val_t _if_result_602 = 0; if (is_match) { _if_result_602 = (title_raw); } else { _if_result_602 = (cur_title); } _if_result_602; });
el_val_t folder_raw = json_get(content, EL_STR("folder"));
old_folder = ({ el_val_t _if_result_599 = 0; if (is_match) { _if_result_599 = (folder_raw); } else { _if_result_599 = (old_folder); } _if_result_599; });
old_folder = ({ el_val_t _if_result_603 = 0; if (is_match) { _if_result_603 = (folder_raw); } else { _if_result_603 = (old_folder); } _if_result_603; });
el_val_t created_raw = json_get(content, EL_STR("created_at"));
old_created = ({ el_val_t _if_result_600 = 0; if ((is_match && !str_eq(created_raw, EL_STR("")))) { _if_result_600 = (created_raw); } else { _if_result_600 = (old_created); } _if_result_600; });
old_created = ({ el_val_t _if_result_604 = 0; if ((is_match && !str_eq(created_raw, EL_STR("")))) { _if_result_604 = (created_raw); } else { _if_result_604 = (old_created); } _if_result_604; });
el_val_t nid = json_get(node, EL_STR("id"));
old_node_id = ({ el_val_t _if_result_601 = 0; if (is_match) { _if_result_601 = (nid); } else { _if_result_601 = (old_node_id); } _if_result_601; });
old_node_id = ({ el_val_t _if_result_605 = 0; if (is_match) { _if_result_605 = (nid); } else { _if_result_605 = (old_node_id); } _if_result_605; });
i = (i + 1);
}
if (!found) {
@@ -29701,12 +29783,12 @@ el_val_t handle_session_approve(el_val_t session_id, el_val_t body) {
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_602 = 0; if (str_eq(action, EL_STR("always"))) { _if_result_602 = (EL_STR("allow")); } else { _if_result_602 = (action); } _if_result_602; });
el_val_t eff_action = ({ el_val_t _if_result_606 = 0; if (str_eq(action, EL_STR("always"))) { _if_result_606 = (EL_STR("allow")); } else { _if_result_606 = (action); } _if_result_606; });
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_603 = 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_604 = 0; if (str_eq(always_list, EL_STR(""))) { _if_result_604 = (approve_tool_name); } else { _if_result_604 = (el_str_concat(el_str_concat(always_list, EL_STR(",")), approve_tool_name)); } _if_result_604; }); (void)(state_set(always_key, new_always)); _if_result_603 = (1); } else { _if_result_603 = (0); } _if_result_603; });
el_val_t discard_always = ({ el_val_t _if_result_607 = 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_608 = 0; if (str_eq(always_list, EL_STR(""))) { _if_result_608 = (approve_tool_name); } else { _if_result_608 = (el_str_concat(el_str_concat(always_list, EL_STR(",")), approve_tool_name)); } _if_result_608; }); (void)(state_set(always_key, new_always)); _if_result_607 = (1); } else { _if_result_607 = (0); } _if_result_607; });
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\"}");
}
@@ -29714,8 +29796,8 @@ el_val_t handle_session_approve(el_val_t session_id, el_val_t body) {
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_605 = 0; if (str_eq(raw_input, EL_STR(""))) { _if_result_605 = (EL_STR("{}")); } else { _if_result_605 = (raw_input); } _if_result_605; });
el_val_t content = ({ el_val_t _if_result_606 = 0; if (str_eq(eff_action, EL_STR("allow"))) { _if_result_606 = (({ el_val_t _if_result_607 = 0; if (use_client_content) { el_val_t trimmed = ({ el_val_t _if_result_608 = 0; if ((str_len(client_content) > 6000)) { _if_result_608 = (el_str_concat(str_slice(client_content, 0, 6000), EL_STR("...[truncated]"))); } else { _if_result_608 = (client_content); } _if_result_608; }); _if_result_607 = (trimmed); } else { _if_result_607 = (({ el_val_t _if_result_609 = 0; if (use_dispatch) { el_val_t raw = dispatch_tool(approve_tool_name, eff_input); _if_result_609 = (({ el_val_t _if_result_610 = 0; if ((str_len(raw) > 6000)) { _if_result_610 = (el_str_concat(str_slice(raw, 0, 6000), EL_STR("...[truncated]"))); } else { _if_result_610 = (raw); } _if_result_610; })); } else { _if_result_609 = (el_str_concat(el_str_concat(EL_STR("{\"error\":\"client content required for non-builtin tool: "), approve_tool_name), EL_STR("\"}"))); } _if_result_609; })); } _if_result_607; })); } else { _if_result_606 = (EL_STR("{\"error\":\"User denied this tool call\"}")); } _if_result_606; });
el_val_t eff_input = ({ el_val_t _if_result_609 = 0; if (str_eq(raw_input, EL_STR(""))) { _if_result_609 = (EL_STR("{}")); } else { _if_result_609 = (raw_input); } _if_result_609; });
el_val_t content = ({ el_val_t _if_result_610 = 0; if (str_eq(eff_action, EL_STR("allow"))) { _if_result_610 = (({ el_val_t _if_result_611 = 0; if (use_client_content) { el_val_t trimmed = ({ el_val_t _if_result_612 = 0; if ((str_len(client_content) > 6000)) { _if_result_612 = (el_str_concat(str_slice(client_content, 0, 6000), EL_STR("...[truncated]"))); } else { _if_result_612 = (client_content); } _if_result_612; }); _if_result_611 = (trimmed); } else { _if_result_611 = (({ el_val_t _if_result_613 = 0; if (use_dispatch) { el_val_t raw = dispatch_tool(approve_tool_name, eff_input); _if_result_613 = (({ el_val_t _if_result_614 = 0; if ((str_len(raw) > 6000)) { _if_result_614 = (el_str_concat(str_slice(raw, 0, 6000), EL_STR("...[truncated]"))); } else { _if_result_614 = (raw); } _if_result_614; })); } else { _if_result_613 = (el_str_concat(el_str_concat(EL_STR("{\"error\":\"client content required for non-builtin tool: "), approve_tool_name), EL_STR("\"}"))); } _if_result_613; })); } _if_result_611; })); } else { _if_result_610 = (EL_STR("{\"error\":\"User denied this tool call\"}")); } _if_result_610; });
return agentic_resume(session_id, call_id, content);
}
el_val_t pending_raw = state_get(el_str_concat(EL_STR("pending_tool_"), session_id));
@@ -29732,12 +29814,12 @@ el_val_t handle_session_approve(el_val_t session_id, el_val_t body) {
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_611 = 0; if (str_eq(action, EL_STR("always"))) { el_val_t new_always = ({ el_val_t _if_result_612 = 0; if (str_eq(always_list, EL_STR(""))) { _if_result_612 = (tool_name); } else { _if_result_612 = (el_str_concat(el_str_concat(always_list, EL_STR(",")), tool_name)); } _if_result_612; }); (void)(state_set(always_key, new_always)); _if_result_611 = (1); } else { _if_result_611 = (0); } _if_result_611; });
el_val_t discard_always2 = ({ el_val_t _if_result_615 = 0; if (str_eq(action, EL_STR("always"))) { el_val_t new_always = ({ el_val_t _if_result_616 = 0; if (str_eq(always_list, EL_STR(""))) { _if_result_616 = (tool_name); } else { _if_result_616 = (el_str_concat(el_str_concat(always_list, EL_STR(",")), tool_name)); } _if_result_616; }); (void)(state_set(always_key, new_always)); _if_result_615 = (1); } else { _if_result_615 = (0); } _if_result_615; });
state_set(el_str_concat(EL_STR("pending_tool_"), session_id), EL_STR(""));
el_val_t tool_result = ({ el_val_t _if_result_613 = 0; if (str_eq(eff_action, EL_STR("allow"))) { el_val_t raw = dispatch_tool(tool_name, tool_input); _if_result_613 = (({ el_val_t _if_result_614 = 0; if ((str_len(raw) > 6000)) { _if_result_614 = (el_str_concat(str_slice(raw, 0, 6000), EL_STR("...[truncated]"))); } else { _if_result_614 = (raw); } _if_result_614; })); } else { _if_result_613 = (EL_STR("{\"error\":\"User denied this tool call\"}")); } _if_result_613; });
el_val_t tool_result = ({ el_val_t _if_result_617 = 0; if (str_eq(eff_action, EL_STR("allow"))) { el_val_t raw = dispatch_tool(tool_name, tool_input); _if_result_617 = (({ el_val_t _if_result_618 = 0; if ((str_len(raw) > 6000)) { _if_result_618 = (el_str_concat(str_slice(raw, 0, 6000), EL_STR("...[truncated]"))); } else { _if_result_618 = (raw); } _if_result_618; })); } else { _if_result_617 = (EL_STR("{\"error\":\"User denied this tool call\"}")); } _if_result_617; });
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_615 = 0; if (str_eq(stored_variant, EL_STR("web"))) { _if_result_615 = (agentic_tools_with_web()); } else { _if_result_615 = (({ el_val_t _if_result_616 = 0; if (str_eq(stored_variant, EL_STR("all"))) { _if_result_616 = (agentic_tools_all()); } else { _if_result_616 = (agentic_tools_literal()); } _if_result_616; })); } _if_result_615; });
el_val_t tools_json = ({ el_val_t _if_result_619 = 0; if (str_eq(stored_variant, EL_STR("web"))) { _if_result_619 = (agentic_tools_with_web()); } else { _if_result_619 = (({ el_val_t _if_result_620 = 0; if (str_eq(stored_variant, EL_STR("all"))) { _if_result_620 = (agentic_tools_all()); } else { _if_result_620 = (agentic_tools_literal()); } _if_result_620; })); } _if_result_619; });
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);
@@ -29754,24 +29836,24 @@ el_val_t rate_limit_check(el_val_t ip, el_val_t path) {
return EL_STR("");
}
el_val_t limit_str = state_get(EL_STR("soul_rate_limit"));
el_val_t limit = ({ el_val_t _if_result_617 = 0; if (str_eq(limit_str, EL_STR(""))) { _if_result_617 = (60); } else { _if_result_617 = (str_to_int(limit_str)); } _if_result_617; });
el_val_t limit = ({ el_val_t _if_result_621 = 0; if (str_eq(limit_str, EL_STR(""))) { _if_result_621 = (60); } else { _if_result_621 = (str_to_int(limit_str)); } _if_result_621; });
el_val_t now = time_now();
el_val_t window_key = el_str_concat(el_str_concat(EL_STR("rl:"), ip), EL_STR(":window"));
el_val_t count_key = el_str_concat(el_str_concat(EL_STR("rl:"), ip), EL_STR(":count"));
el_val_t win_str = state_get(window_key);
el_val_t win_start = ({ el_val_t _if_result_618 = 0; if (str_eq(win_str, EL_STR(""))) { _if_result_618 = (now); } else { _if_result_618 = (str_to_int(win_str)); } _if_result_618; });
el_val_t win_start = ({ el_val_t _if_result_622 = 0; if (str_eq(win_str, EL_STR(""))) { _if_result_622 = (now); } else { _if_result_622 = (str_to_int(win_str)); } _if_result_622; });
el_val_t elapsed = (now - win_start);
el_val_t in_window = (elapsed < 60);
el_val_t prev_count_str = state_get(count_key);
el_val_t prev_count = ({ el_val_t _if_result_619 = 0; if (str_eq(prev_count_str, EL_STR(""))) { _if_result_619 = (0); } else { _if_result_619 = (str_to_int(prev_count_str)); } _if_result_619; });
el_val_t eff_count = ({ el_val_t _if_result_620 = 0; if (in_window) { _if_result_620 = (prev_count); } else { _if_result_620 = (0); } _if_result_620; });
el_val_t eff_win = ({ el_val_t _if_result_621 = 0; if (in_window) { _if_result_621 = (win_start); } else { _if_result_621 = (now); } _if_result_621; });
el_val_t prev_count = ({ el_val_t _if_result_623 = 0; if (str_eq(prev_count_str, EL_STR(""))) { _if_result_623 = (0); } else { _if_result_623 = (str_to_int(prev_count_str)); } _if_result_623; });
el_val_t eff_count = ({ el_val_t _if_result_624 = 0; if (in_window) { _if_result_624 = (prev_count); } else { _if_result_624 = (0); } _if_result_624; });
el_val_t eff_win = ({ el_val_t _if_result_625 = 0; if (in_window) { _if_result_625 = (win_start); } else { _if_result_625 = (now); } _if_result_625; });
el_val_t new_count = (eff_count + 1);
state_set(count_key, int_to_str(new_count));
state_set(window_key, int_to_str(eff_win));
if (new_count > limit) {
el_val_t retry_after = (60 - (now - eff_win));
el_val_t eff_retry = ({ el_val_t _if_result_622 = 0; if ((retry_after < 0)) { _if_result_622 = (0); } else { _if_result_622 = (retry_after); } _if_result_622; });
el_val_t eff_retry = ({ el_val_t _if_result_626 = 0; if ((retry_after < 0)) { _if_result_626 = (0); } else { _if_result_626 = (retry_after); } _if_result_626; });
return el_str_concat(el_str_concat(EL_STR("{\"__status__\":429,\"error\":\"rate limit exceeded\",\"code\":\"rate_limited\",\"retry_after_secs\":"), int_to_str(eff_retry)), EL_STR("}"));
}
return EL_STR("");
@@ -29800,18 +29882,18 @@ el_val_t err_405(el_val_t method, el_val_t path) {
el_val_t route_health(void) {
el_val_t cgi_id = state_get(EL_STR("soul_cgi_id"));
el_val_t boot = state_get(EL_STR("soul_boot_count"));
el_val_t boot_num = ({ el_val_t _if_result_623 = 0; if (str_eq(boot, EL_STR(""))) { _if_result_623 = (EL_STR("0")); } else { _if_result_623 = (boot); } _if_result_623; });
el_val_t boot_num = ({ el_val_t _if_result_627 = 0; if (str_eq(boot, EL_STR(""))) { _if_result_627 = (EL_STR("0")); } else { _if_result_627 = (boot); } _if_result_627; });
el_val_t node_ct = engram_node_count();
el_val_t edge_ct = engram_edge_count();
el_val_t pulse = state_get(EL_STR("soul.pulse"));
el_val_t pulse_num = ({ el_val_t _if_result_624 = 0; if (str_eq(pulse, EL_STR(""))) { _if_result_624 = (EL_STR("0")); } else { _if_result_624 = (pulse); } _if_result_624; });
el_val_t pulse_num = ({ el_val_t _if_result_628 = 0; if (str_eq(pulse, EL_STR(""))) { _if_result_628 = (EL_STR("0")); } else { _if_result_628 = (pulse); } _if_result_628; });
el_val_t boot_ts_str = state_get(EL_STR("soul_boot_ts"));
el_val_t uptime_secs = ({ el_val_t _if_result_625 = 0; if (str_eq(boot_ts_str, EL_STR(""))) { _if_result_625 = ((-1)); } else { _if_result_625 = ((time_now() - str_to_int(boot_ts_str))); } _if_result_625; });
el_val_t uptime_secs = ({ el_val_t _if_result_629 = 0; if (str_eq(boot_ts_str, EL_STR(""))) { _if_result_629 = ((-1)); } else { _if_result_629 = ((time_now() - str_to_int(boot_ts_str))); } _if_result_629; });
el_val_t model = state_get(EL_STR("soul_model"));
el_val_t eff_model = ({ el_val_t _if_result_626 = 0; if (str_eq(model, EL_STR(""))) { _if_result_626 = (EL_STR("claude-sonnet-4-5")); } else { _if_result_626 = (model); } _if_result_626; });
el_val_t eff_model = ({ el_val_t _if_result_630 = 0; if (str_eq(model, EL_STR(""))) { _if_result_630 = (EL_STR("claude-sonnet-4-5")); } else { _if_result_630 = (model); } _if_result_630; });
el_val_t llm_probe = llm_call_system(eff_model, EL_STR("You are a health probe. Reply with the single word: ok"), EL_STR("ping"));
el_val_t llm_ok = (((!str_eq(llm_probe, EL_STR("")) && !str_starts_with(llm_probe, EL_STR("{\"error\""))) && !str_starts_with(llm_probe, EL_STR("{\"type\":\"error\""))) && !str_contains(llm_probe, EL_STR("authentication_error")));
el_val_t llm_status = ({ el_val_t _if_result_627 = 0; if (llm_ok) { _if_result_627 = (EL_STR("ok")); } else { _if_result_627 = (EL_STR("unreachable")); } _if_result_627; });
el_val_t llm_status = ({ el_val_t _if_result_631 = 0; if (llm_ok) { _if_result_631 = (EL_STR("ok")); } else { _if_result_631 = (EL_STR("unreachable")); } _if_result_631; });
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_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"status\":\"alive\""), EL_STR(",\"cgi_id\":\"")), cgi_id), EL_STR("\"")), EL_STR(",\"boot\":")), boot_num), EL_STR(",\"uptime_secs\":")), int_to_str(uptime_secs)), EL_STR(",\"node_count\":")), int_to_str(node_ct)), EL_STR(",\"edge_count\":")), int_to_str(edge_ct)), EL_STR(",\"pulse\":")), pulse_num), EL_STR(",\"llm\":\"")), llm_status), EL_STR("\"")), EL_STR(",\"layers\":{\"l0\":\"core\",\"l1\":\"safety\",\"l2\":\"stewardship\",\"l3\":\"")), imprint_current()), EL_STR("\"}}"));
return 0;
}
@@ -29881,30 +29963,30 @@ el_val_t handle_dharma_recv(el_val_t body) {
el_val_t from_id = json_get(body, EL_STR("from"));
el_val_t event_type = json_get(content_raw, EL_STR("event_type"));
el_val_t payload = json_get(content_raw, EL_STR("payload"));
el_val_t eff_event = ({ el_val_t _if_result_628 = 0; if (str_eq(event_type, EL_STR(""))) { _if_result_628 = (EL_STR("chat")); } else { _if_result_628 = (event_type); } _if_result_628; });
el_val_t eff_payload = ({ el_val_t _if_result_629 = 0; if (str_eq(payload, EL_STR(""))) { _if_result_629 = (content_raw); } else { _if_result_629 = (payload); } _if_result_629; });
el_val_t eff_event = ({ el_val_t _if_result_632 = 0; if (str_eq(event_type, EL_STR(""))) { _if_result_632 = (EL_STR("chat")); } else { _if_result_632 = (event_type); } _if_result_632; });
el_val_t eff_payload = ({ el_val_t _if_result_633 = 0; if (str_eq(payload, EL_STR(""))) { _if_result_633 = (content_raw); } else { _if_result_633 = (payload); } _if_result_633; });
if (str_eq(eff_event, EL_STR("chat"))) {
el_val_t msg = json_get(eff_payload, EL_STR("message"));
el_val_t chat_body = ({ el_val_t _if_result_630 = 0; if (str_eq(msg, EL_STR(""))) { _if_result_630 = (el_str_concat(el_str_concat(EL_STR("{\"message\":\""), str_replace(str_replace(eff_payload, EL_STR("\\"), EL_STR("\\\\")), EL_STR("\""), EL_STR("\\\""))), EL_STR("\"}"))); } else { _if_result_630 = (eff_payload); } _if_result_630; });
el_val_t chat_body = ({ el_val_t _if_result_634 = 0; if (str_eq(msg, EL_STR(""))) { _if_result_634 = (el_str_concat(el_str_concat(EL_STR("{\"message\":\""), str_replace(str_replace(eff_payload, EL_STR("\\"), EL_STR("\\\\")), EL_STR("\""), EL_STR("\\\""))), EL_STR("\"}"))); } else { _if_result_634 = (eff_payload); } _if_result_634; });
el_val_t agentic_flag = json_get_bool(eff_payload, EL_STR("agentic"));
el_val_t raw_msg = json_get(chat_body, EL_STR("message"));
el_val_t req_mode = json_get(chat_body, EL_STR("mode"));
el_val_t reply = ({ el_val_t _if_result_631 = 0; if (str_eq(req_mode, EL_STR("plan"))) { _if_result_631 = (handle_chat_plan(chat_body)); } else { _if_result_631 = (({ el_val_t _if_result_632 = 0; if (agentic_flag) { _if_result_632 = (handle_chat_agentic(chat_body)); } else { el_val_t screened_reply = layered_cycle(raw_msg); _if_result_632 = (screened_reply); } _if_result_632; })); } _if_result_631; });
el_val_t reply = ({ el_val_t _if_result_635 = 0; if (str_eq(req_mode, EL_STR("plan"))) { _if_result_635 = (handle_chat_plan(chat_body)); } else { _if_result_635 = (({ el_val_t _if_result_636 = 0; if (agentic_flag) { _if_result_636 = (handle_chat_agentic(chat_body)); } else { el_val_t screened_reply = layered_cycle(raw_msg); _if_result_636 = (screened_reply); } _if_result_636; })); } _if_result_635; });
auto_persist(chat_body, reply);
return reply;
}
if (str_eq(eff_event, EL_STR("memory"))) {
el_val_t query = json_get(eff_payload, EL_STR("query"));
el_val_t limit_str = json_get(eff_payload, EL_STR("limit"));
el_val_t limit = ({ el_val_t _if_result_633 = 0; if (str_eq(limit_str, EL_STR(""))) { _if_result_633 = (20); } else { _if_result_633 = (str_to_int(limit_str)); } _if_result_633; });
el_val_t q = ({ el_val_t _if_result_634 = 0; if (str_eq(query, EL_STR(""))) { _if_result_634 = (eff_payload); } else { _if_result_634 = (query); } _if_result_634; });
el_val_t limit = ({ el_val_t _if_result_637 = 0; if (str_eq(limit_str, EL_STR(""))) { _if_result_637 = (20); } else { _if_result_637 = (str_to_int(limit_str)); } _if_result_637; });
el_val_t q = ({ el_val_t _if_result_638 = 0; if (str_eq(query, EL_STR(""))) { _if_result_638 = (eff_payload); } else { _if_result_638 = (query); } _if_result_638; });
return engram_search_json(q, limit);
}
if (str_eq(eff_event, EL_STR("tool"))) {
el_val_t path_field = json_get(eff_payload, EL_STR("path"));
el_val_t method_field = json_get(eff_payload, EL_STR("method"));
el_val_t tool_body = json_get(eff_payload, EL_STR("body"));
el_val_t eff_method = ({ el_val_t _if_result_635 = 0; if (str_eq(method_field, EL_STR(""))) { _if_result_635 = (EL_STR("POST")); } else { _if_result_635 = (method_field); } _if_result_635; });
el_val_t eff_method = ({ el_val_t _if_result_639 = 0; if (str_eq(method_field, EL_STR(""))) { _if_result_639 = (EL_STR("POST")); } else { _if_result_639 = (method_field); } _if_result_639; });
return handle_tool(path_field, eff_method, tool_body);
}
if (str_eq(eff_event, EL_STR("see"))) {
@@ -29939,7 +30021,7 @@ el_val_t connectd_get(el_val_t suffix) {
}
el_val_t connectd_post(el_val_t suffix, el_val_t body) {
el_val_t eff = ({ el_val_t _if_result_636 = 0; if (str_eq(body, EL_STR(""))) { _if_result_636 = (EL_STR("{}")); } else { _if_result_636 = (body); } _if_result_636; });
el_val_t eff = ({ el_val_t _if_result_640 = 0; if (str_eq(body, EL_STR(""))) { _if_result_640 = (EL_STR("{}")); } else { _if_result_640 = (body); } _if_result_640; });
el_val_t tmp = el_str_concat(el_str_concat(EL_STR("/tmp/neuron-connectors-req-"), int_to_str(time_now())), EL_STR(".json"));
fs_write(tmp, eff);
el_val_t out = exec_capture(el_str_concat(el_str_concat(el_str_concat(EL_STR("curl -s --max-time 20 -X POST http://127.0.0.1:7771"), suffix), EL_STR(" -H 'Content-Type: application/json' -d @")), tmp));
@@ -30006,17 +30088,17 @@ el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body) {
engram_save(snap_path);
el_val_t snap = fs_read(snap_path);
el_val_t edges_raw = json_get_raw(snap, EL_STR("edges"));
return ({ el_val_t _if_result_637 = 0; if (str_eq(edges_raw, EL_STR(""))) { _if_result_637 = (EL_STR("[]")); } else { _if_result_637 = (edges_raw); } _if_result_637; });
return ({ el_val_t _if_result_641 = 0; if (str_eq(edges_raw, EL_STR(""))) { _if_result_641 = (EL_STR("[]")); } else { _if_result_641 = (edges_raw); } _if_result_641; });
}
if (str_eq(clean, EL_STR("/api/chat"))) {
el_val_t raw_msg = json_get(body, EL_STR("message"));
el_val_t eff_msg = ({ el_val_t _if_result_638 = 0; if (str_eq(raw_msg, EL_STR(""))) { _if_result_638 = (body); } else { _if_result_638 = (raw_msg); } _if_result_638; });
el_val_t eff_msg = ({ el_val_t _if_result_642 = 0; if (str_eq(raw_msg, EL_STR(""))) { _if_result_642 = (body); } else { _if_result_642 = (raw_msg); } _if_result_642; });
if (str_eq(eff_msg, EL_STR(""))) {
return EL_STR("{\"error\":\"message is required\",\"code\":\"missing_param\"}");
}
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_639 = 0; if (str_eq(req_mode, EL_STR("plan"))) { _if_result_639 = (handle_chat_plan(body)); } else { _if_result_639 = (({ el_val_t _if_result_640 = 0; if (agentic_flag) { _if_result_640 = (handle_chat_agentic(body)); } else { el_val_t screened_reply = layered_cycle(eff_msg); _if_result_640 = (screened_reply); } _if_result_640; })); } _if_result_639; });
el_val_t reply = ({ el_val_t _if_result_643 = 0; if (str_eq(req_mode, EL_STR("plan"))) { _if_result_643 = (handle_chat_plan(body)); } else { _if_result_643 = (({ el_val_t _if_result_644 = 0; if (agentic_flag) { _if_result_644 = (handle_chat_agentic(body)); } else { el_val_t screened_reply = layered_cycle(eff_msg); _if_result_644 = (screened_reply); } _if_result_644; })); } _if_result_643; });
auto_persist(body, reply);
return reply;
}
@@ -30097,7 +30179,7 @@ el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body) {
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_641 = 0; if (str_eq(rp_raw, EL_STR(""))) { _if_result_641 = (EL_STR("[]")); } else { _if_result_641 = (el_str_concat(el_str_concat(EL_STR("["), rp_raw), EL_STR("]"))); } _if_result_641; });
el_val_t rp_arr = ({ el_val_t _if_result_645 = 0; if (str_eq(rp_raw, EL_STR(""))) { _if_result_645 = (EL_STR("[]")); } else { _if_result_645 = (el_str_concat(el_str_concat(EL_STR("["), rp_raw), EL_STR("]"))); } _if_result_645; });
return el_str_concat(el_str_concat(EL_STR("{\"progress\":"), rp_arr), EL_STR("}"));
}
}
@@ -30107,7 +30189,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 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_642 = 0; if ((gs_slash < 0)) { _if_result_642 = (gs_after); } else { _if_result_642 = (str_slice(gs_after, 0, gs_slash)); } _if_result_642; });
el_val_t gs_id = ({ el_val_t _if_result_646 = 0; if ((gs_slash < 0)) { _if_result_646 = (gs_after); } else { _if_result_646 = (str_slice(gs_after, 0, gs_slash)); } _if_result_646; });
if (!str_eq(gs_id, EL_STR(""))) {
return session_get(gs_id);
}
@@ -30121,14 +30203,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_643 = 0; if ((slash < 0)) { _if_result_643 = (after); } else { _if_result_643 = (str_slice(after, 0, slash)); } _if_result_643; });
el_val_t session_id = ({ el_val_t _if_result_647 = 0; if ((slash < 0)) { _if_result_647 = (after); } else { _if_result_647 = (str_slice(after, 0, slash)); } _if_result_647; });
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_644 = 0; if ((sess_slash < 0)) { _if_result_644 = (sess_after); } else { _if_result_644 = (str_slice(sess_after, 0, sess_slash)); } _if_result_644; });
el_val_t sess_sub = ({ el_val_t _if_result_645 = 0; if ((sess_slash < 0)) { _if_result_645 = (EL_STR("")); } else { _if_result_645 = (str_slice(sess_after, (sess_slash + 1), str_len(sess_after))); } _if_result_645; });
el_val_t sess_id = ({ el_val_t _if_result_648 = 0; if ((sess_slash < 0)) { _if_result_648 = (sess_after); } else { _if_result_648 = (str_slice(sess_after, 0, sess_slash)); } _if_result_648; });
el_val_t sess_sub = ({ el_val_t _if_result_649 = 0; if ((sess_slash < 0)) { _if_result_649 = (EL_STR("")); } else { _if_result_649 = (str_slice(sess_after, (sess_slash + 1), str_len(sess_after))); } _if_result_649; });
if (!str_eq(sess_id, EL_STR("")) && str_eq(sess_sub, EL_STR("approve"))) {
return handle_session_approve(sess_id, body);
}
@@ -30152,7 +30234,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_646 = 0; if (str_eq(req_mode, EL_STR("plan"))) { _if_result_646 = (handle_chat_plan(body)); } else { _if_result_646 = (({ el_val_t _if_result_647 = 0; if (agentic_flag) { _if_result_647 = (handle_chat_agentic(body)); } else { el_val_t screened_reply = layered_cycle(raw_msg); _if_result_647 = (screened_reply); } _if_result_647; })); } _if_result_646; });
el_val_t reply = ({ el_val_t _if_result_650 = 0; if (str_eq(req_mode, EL_STR("plan"))) { _if_result_650 = (handle_chat_plan(body)); } else { _if_result_650 = (({ el_val_t _if_result_651 = 0; if (agentic_flag) { _if_result_651 = (handle_chat_agentic(body)); } else { el_val_t screened_reply = layered_cycle(raw_msg); _if_result_651 = (screened_reply); } _if_result_651; })); } _if_result_650; });
auto_persist(body, reply);
return reply;
}
@@ -30276,7 +30358,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_648 = 0; if ((del_slash < 0)) { _if_result_648 = (del_after); } else { _if_result_648 = (str_slice(del_after, 0, del_slash)); } _if_result_648; });
el_val_t del_id = ({ el_val_t _if_result_652 = 0; if ((del_slash < 0)) { _if_result_652 = (del_after); } else { _if_result_652 = (str_slice(del_after, 0, del_slash)); } _if_result_652; });
if (!str_eq(del_id, EL_STR(""))) {
return session_delete(del_id);
}
@@ -30287,7 +30369,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_649 = 0; if ((patch_slash < 0)) { _if_result_649 = (patch_after); } else { _if_result_649 = (str_slice(patch_after, 0, patch_slash)); } _if_result_649; });
el_val_t patch_id = ({ el_val_t _if_result_653 = 0; if ((patch_slash < 0)) { _if_result_653 = (patch_after); } else { _if_result_653 = (str_slice(patch_after, 0, patch_slash)); } _if_result_653; });
if (!str_eq(patch_id, EL_STR(""))) {
return session_update_patch(patch_id, body);
}
@@ -30413,8 +30495,8 @@ el_val_t aff_try_slot(el_val_t slot_json, el_val_t aff_7d_ts, el_val_t acc_key)
}
}
el_val_t bn_ts_raw = state_get(EL_STR("_ats_ts_raw"));
el_val_t bn_ts = ({ el_val_t _if_result_650 = 0; if (str_eq(bn_ts_raw, EL_STR(""))) { _if_result_650 = (0); } else { _if_result_650 = (str_to_int(bn_ts_raw)); } _if_result_650; });
el_val_t snip = ({ el_val_t _if_result_651 = 0; if ((str_len(bn_c) > 200)) { _if_result_651 = (str_slice(bn_c, 0, 200)); } else { _if_result_651 = (bn_c); } _if_result_651; });
el_val_t bn_ts = ({ el_val_t _if_result_654 = 0; if (str_eq(bn_ts_raw, EL_STR(""))) { _if_result_654 = (0); } else { _if_result_654 = (str_to_int(bn_ts_raw)); } _if_result_654; });
el_val_t snip = ({ el_val_t _if_result_655 = 0; if ((str_len(bn_c) > 200)) { _if_result_655 = (str_slice(bn_c, 0, 200)); } else { _if_result_655 = (bn_c); } _if_result_655; });
if ((bn_ts >= aff_7d_ts) && !str_eq(snip, EL_STR(""))) {
el_val_t cur_acc = state_get(acc_key);
if (str_eq(cur_acc, EL_STR(""))) {
@@ -30435,21 +30517,21 @@ el_val_t load_identity_context(void) {
el_val_t intel_ok = (!str_eq(node_intel, EL_STR("")) && !str_eq(node_intel, EL_STR("null")));
el_val_t values_ok = (!str_eq(node_values, EL_STR("")) && !str_eq(node_values, EL_STR("null")));
el_val_t mem_ok = (!str_eq(node_mem_phil, EL_STR("")) && !str_eq(node_mem_phil, EL_STR("null")));
el_val_t intel_content = ({ el_val_t _if_result_652 = 0; if (intel_ok) { _if_result_652 = (json_get(node_intel, EL_STR("content"))); } else { _if_result_652 = (EL_STR("")); } _if_result_652; });
el_val_t values_content = ({ el_val_t _if_result_653 = 0; if (values_ok) { _if_result_653 = (json_get(node_values, EL_STR("content"))); } else { _if_result_653 = (EL_STR("")); } _if_result_653; });
el_val_t mem_content = ({ el_val_t _if_result_654 = 0; if (mem_ok) { _if_result_654 = (json_get(node_mem_phil, EL_STR("content"))); } else { _if_result_654 = (EL_STR("")); } _if_result_654; });
el_val_t intel_short = ({ el_val_t _if_result_655 = 0; if ((str_len(intel_content) > 2000)) { _if_result_655 = (str_slice(intel_content, 0, 2000)); } else { _if_result_655 = (intel_content); } _if_result_655; });
el_val_t values_short = ({ el_val_t _if_result_656 = 0; if ((str_len(values_content) > 2000)) { _if_result_656 = (str_slice(values_content, 0, 2000)); } else { _if_result_656 = (values_content); } _if_result_656; });
el_val_t mem_short = ({ el_val_t _if_result_657 = 0; if ((str_len(mem_content) > 2000)) { _if_result_657 = (str_slice(mem_content, 0, 2000)); } else { _if_result_657 = (mem_content); } _if_result_657; });
el_val_t intel_content = ({ el_val_t _if_result_656 = 0; if (intel_ok) { _if_result_656 = (json_get(node_intel, EL_STR("content"))); } else { _if_result_656 = (EL_STR("")); } _if_result_656; });
el_val_t values_content = ({ el_val_t _if_result_657 = 0; if (values_ok) { _if_result_657 = (json_get(node_values, EL_STR("content"))); } else { _if_result_657 = (EL_STR("")); } _if_result_657; });
el_val_t mem_content = ({ el_val_t _if_result_658 = 0; if (mem_ok) { _if_result_658 = (json_get(node_mem_phil, EL_STR("content"))); } else { _if_result_658 = (EL_STR("")); } _if_result_658; });
el_val_t intel_short = ({ el_val_t _if_result_659 = 0; if ((str_len(intel_content) > 2000)) { _if_result_659 = (str_slice(intel_content, 0, 2000)); } else { _if_result_659 = (intel_content); } _if_result_659; });
el_val_t values_short = ({ el_val_t _if_result_660 = 0; if ((str_len(values_content) > 2000)) { _if_result_660 = (str_slice(values_content, 0, 2000)); } else { _if_result_660 = (values_content); } _if_result_660; });
el_val_t mem_short = ({ el_val_t _if_result_661 = 0; if ((str_len(mem_content) > 2000)) { _if_result_661 = (str_slice(mem_content, 0, 2000)); } else { _if_result_661 = (mem_content); } _if_result_661; });
el_val_t parts_count = 0;
parts_count = ({ el_val_t _if_result_658 = 0; if (intel_ok) { _if_result_658 = ((parts_count + 1)); } else { _if_result_658 = (parts_count); } _if_result_658; });
parts_count = ({ el_val_t _if_result_659 = 0; if (values_ok) { _if_result_659 = ((parts_count + 1)); } else { _if_result_659 = (parts_count); } _if_result_659; });
parts_count = ({ el_val_t _if_result_660 = 0; if (mem_ok) { _if_result_660 = ((parts_count + 1)); } else { _if_result_660 = (parts_count); } _if_result_660; });
parts_count = ({ el_val_t _if_result_662 = 0; if (intel_ok) { _if_result_662 = ((parts_count + 1)); } else { _if_result_662 = (parts_count); } _if_result_662; });
parts_count = ({ el_val_t _if_result_663 = 0; if (values_ok) { _if_result_663 = ((parts_count + 1)); } else { _if_result_663 = (parts_count); } _if_result_663; });
parts_count = ({ el_val_t _if_result_664 = 0; if (mem_ok) { _if_result_664 = ((parts_count + 1)); } else { _if_result_664 = (parts_count); } _if_result_664; });
if (parts_count > 0) {
el_val_t ctx = EL_STR("");
ctx = ({ el_val_t _if_result_661 = 0; if (intel_ok) { _if_result_661 = (el_str_concat(el_str_concat(el_str_concat(ctx, EL_STR("[INTELLECTUAL-DNA]\n")), intel_short), EL_STR("\n\n"))); } else { _if_result_661 = (ctx); } _if_result_661; });
ctx = ({ el_val_t _if_result_662 = 0; if (values_ok) { _if_result_662 = (el_str_concat(el_str_concat(el_str_concat(ctx, EL_STR("[VALUES]\n")), values_short), EL_STR("\n\n"))); } else { _if_result_662 = (ctx); } _if_result_662; });
ctx = ({ el_val_t _if_result_663 = 0; if (mem_ok) { _if_result_663 = (el_str_concat(el_str_concat(ctx, EL_STR("[MEMORY-PHILOSOPHY]\n")), mem_short)); } else { _if_result_663 = (ctx); } _if_result_663; });
ctx = ({ el_val_t _if_result_665 = 0; if (intel_ok) { _if_result_665 = (el_str_concat(el_str_concat(el_str_concat(ctx, EL_STR("[INTELLECTUAL-DNA]\n")), intel_short), EL_STR("\n\n"))); } else { _if_result_665 = (ctx); } _if_result_665; });
ctx = ({ el_val_t _if_result_666 = 0; if (values_ok) { _if_result_666 = (el_str_concat(el_str_concat(el_str_concat(ctx, EL_STR("[VALUES]\n")), values_short), EL_STR("\n\n"))); } else { _if_result_666 = (ctx); } _if_result_666; });
ctx = ({ el_val_t _if_result_667 = 0; if (mem_ok) { _if_result_667 = (el_str_concat(el_str_concat(ctx, EL_STR("[MEMORY-PHILOSOPHY]\n")), mem_short)); } else { _if_result_667 = (ctx); } _if_result_667; });
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)")));
}
@@ -30472,10 +30554,10 @@ el_val_t load_identity_context(void) {
el_val_t bell_raw = engram_search_json(EL_STR("bell:soft bell:hard BellEvent affective"), 3);
el_val_t bell_aff_ok = (!str_eq(bell_raw, EL_STR("")) && !str_eq(bell_raw, EL_STR("[]")));
el_val_t aff_ctx = EL_STR("");
aff_ctx = ({ el_val_t _if_result_664 = 0; if (bell_aff_ok) { (void)(state_set(EL_STR("_bell_acc"), EL_STR(""))); (void)(aff_try_slot(json_array_get(bell_raw, 0), aff_7d, EL_STR("_bell_acc"))); (void)(aff_try_slot(json_array_get(bell_raw, 1), aff_7d, EL_STR("_bell_acc"))); (void)(aff_try_slot(json_array_get(bell_raw, 2), aff_7d, EL_STR("_bell_acc"))); _if_result_664 = (state_get(EL_STR("_bell_acc"))); } else { _if_result_664 = (EL_STR("")); } _if_result_664; });
aff_ctx = ({ el_val_t _if_result_668 = 0; if (bell_aff_ok) { (void)(state_set(EL_STR("_bell_acc"), EL_STR(""))); (void)(aff_try_slot(json_array_get(bell_raw, 0), aff_7d, EL_STR("_bell_acc"))); (void)(aff_try_slot(json_array_get(bell_raw, 1), aff_7d, EL_STR("_bell_acc"))); (void)(aff_try_slot(json_array_get(bell_raw, 2), aff_7d, EL_STR("_bell_acc"))); _if_result_668 = (state_get(EL_STR("_bell_acc"))); } else { _if_result_668 = (EL_STR("")); } _if_result_668; });
el_val_t pos_raw = engram_search_json(EL_STR("PositiveEvent joy:high joy:low affective"), 3);
el_val_t pos_aff_ok = (!str_eq(pos_raw, EL_STR("")) && !str_eq(pos_raw, EL_STR("[]")));
aff_ctx = ({ el_val_t _if_result_665 = 0; if (pos_aff_ok) { (void)(state_set(EL_STR("_pos_acc"), aff_ctx)); (void)(aff_try_slot(json_array_get(pos_raw, 0), aff_7d, EL_STR("_pos_acc"))); (void)(aff_try_slot(json_array_get(pos_raw, 1), aff_7d, EL_STR("_pos_acc"))); (void)(aff_try_slot(json_array_get(pos_raw, 2), aff_7d, EL_STR("_pos_acc"))); _if_result_665 = (state_get(EL_STR("_pos_acc"))); } else { _if_result_665 = (aff_ctx); } _if_result_665; });
aff_ctx = ({ el_val_t _if_result_669 = 0; if (pos_aff_ok) { (void)(state_set(EL_STR("_pos_acc"), aff_ctx)); (void)(aff_try_slot(json_array_get(pos_raw, 0), aff_7d, EL_STR("_pos_acc"))); (void)(aff_try_slot(json_array_get(pos_raw, 1), aff_7d, EL_STR("_pos_acc"))); (void)(aff_try_slot(json_array_get(pos_raw, 2), aff_7d, EL_STR("_pos_acc"))); _if_result_669 = (state_get(EL_STR("_pos_acc"))); } else { _if_result_669 = (aff_ctx); } _if_result_669; });
if (!str_eq(aff_ctx, EL_STR(""))) {
state_set(EL_STR("soul_affective_context"), aff_ctx);
println(el_str_concat(el_str_concat(EL_STR("[soul] affective context loaded ("), int_to_str(str_len(aff_ctx))), EL_STR(" chars)")));
@@ -30521,19 +30603,19 @@ el_val_t seed_persona_from_env(void) {
el_val_t emit_session_start_event(void) {
el_val_t boot = state_get(EL_STR("soul_boot_count"));
el_val_t boot_num = ({ el_val_t _if_result_666 = 0; if (str_eq(boot, EL_STR(""))) { _if_result_666 = (EL_STR("0")); } else { _if_result_666 = (boot); } _if_result_666; });
el_val_t boot_num = ({ el_val_t _if_result_670 = 0; if (str_eq(boot, EL_STR(""))) { _if_result_670 = (EL_STR("0")); } else { _if_result_670 = (boot); } _if_result_670; });
el_val_t node_ct = engram_node_count();
el_val_t edge_ct = engram_edge_count();
el_val_t id_ctx = state_get(EL_STR("soul_identity_context"));
el_val_t has_identity = ({ el_val_t _if_result_667 = 0; if (str_eq(id_ctx, EL_STR(""))) { _if_result_667 = (EL_STR("false")); } else { _if_result_667 = (EL_STR("true")); } _if_result_667; });
el_val_t has_identity = ({ el_val_t _if_result_671 = 0; if (str_eq(id_ctx, EL_STR(""))) { _if_result_671 = (EL_STR("false")); } else { _if_result_671 = (EL_STR("true")); } _if_result_671; });
el_val_t cgi_from_state = state_get(EL_STR("soul_cgi_id"));
el_val_t cgi_from_env = env(EL_STR("SOUL_CGI_ID"));
el_val_t eff_cgi = ({ el_val_t _if_result_668 = 0; if (!str_eq(cgi_from_state, EL_STR(""))) { _if_result_668 = (cgi_from_state); } else { _if_result_668 = (({ el_val_t _if_result_669 = 0; if (!str_eq(cgi_from_env, EL_STR(""))) { _if_result_669 = (cgi_from_env); } else { _if_result_669 = (EL_STR("ntn-genesis")); } _if_result_669; })); } _if_result_668; });
el_val_t eff_cgi = ({ el_val_t _if_result_672 = 0; if (!str_eq(cgi_from_state, EL_STR(""))) { _if_result_672 = (cgi_from_state); } else { _if_result_672 = (({ el_val_t _if_result_673 = 0; if (!str_eq(cgi_from_env, EL_STR(""))) { _if_result_673 = (cgi_from_env); } else { _if_result_673 = (EL_STR("ntn-genesis")); } _if_result_673; })); } _if_result_672; });
el_val_t ts = time_now();
el_val_t prev_sum_node = engram_get_node_by_label(EL_STR("session:summary"));
el_val_t prev_sum_ok = (!str_eq(prev_sum_node, EL_STR("")) && !str_eq(prev_sum_node, EL_STR("null")));
el_val_t prev_sum_content = ({ el_val_t _if_result_670 = 0; if (prev_sum_ok) { _if_result_670 = (json_get(prev_sum_node, EL_STR("content"))); } else { el_val_t sum_search = engram_search_json(EL_STR("SessionSummary session:summary previous-session"), 2); el_val_t sum_srch_ok = (!str_eq(sum_search, EL_STR("")) && !str_eq(sum_search, EL_STR("[]"))); _if_result_670 = (({ el_val_t _if_result_671 = 0; if (sum_srch_ok) { el_val_t sn = json_array_get(sum_search, 0); el_val_t stype = json_get(sn, EL_STR("node_type")); el_val_t scontent = json_get(sn, EL_STR("content")); _if_result_671 = (({ el_val_t _if_result_672 = 0; if ((str_eq(stype, EL_STR("SessionSummary")) && !str_eq(scontent, EL_STR("")))) { _if_result_672 = (scontent); } else { _if_result_672 = (EL_STR("")); } _if_result_672; })); } else { _if_result_671 = (EL_STR("")); } _if_result_671; })); } _if_result_670; });
el_val_t has_prev_sum = ({ el_val_t _if_result_673 = 0; if (str_eq(prev_sum_content, EL_STR(""))) { _if_result_673 = (EL_STR("false")); } else { _if_result_673 = (EL_STR("true")); } _if_result_673; });
el_val_t prev_sum_content = ({ el_val_t _if_result_674 = 0; if (prev_sum_ok) { _if_result_674 = (json_get(prev_sum_node, EL_STR("content"))); } else { el_val_t sum_search = engram_search_json(EL_STR("SessionSummary session:summary previous-session"), 2); el_val_t sum_srch_ok = (!str_eq(sum_search, EL_STR("")) && !str_eq(sum_search, EL_STR("[]"))); _if_result_674 = (({ el_val_t _if_result_675 = 0; if (sum_srch_ok) { el_val_t sn = json_array_get(sum_search, 0); el_val_t stype = json_get(sn, EL_STR("node_type")); el_val_t scontent = json_get(sn, EL_STR("content")); _if_result_675 = (({ el_val_t _if_result_676 = 0; if ((str_eq(stype, EL_STR("SessionSummary")) && !str_eq(scontent, EL_STR("")))) { _if_result_676 = (scontent); } else { _if_result_676 = (EL_STR("")); } _if_result_676; })); } else { _if_result_675 = (EL_STR("")); } _if_result_675; })); } _if_result_674; });
el_val_t has_prev_sum = ({ el_val_t _if_result_677 = 0; if (str_eq(prev_sum_content, EL_STR(""))) { _if_result_677 = (EL_STR("false")); } else { _if_result_677 = (EL_STR("true")); } _if_result_677; });
if (!str_eq(prev_sum_content, EL_STR(""))) {
state_set(EL_STR("soul_prev_session_summary"), prev_sum_content);
println(el_str_concat(el_str_concat(EL_STR("[soul] previous session summary loaded ("), int_to_str(str_len(prev_sum_content))), EL_STR(" chars)")));
@@ -30580,23 +30662,23 @@ el_val_t layered_cycle(el_val_t raw_input) {
el_val_t continuity = steward_session_check(screened, session_id);
el_val_t cont_status = json_get(continuity, EL_STR("status"));
el_val_t cont_action = json_get(continuity, EL_STR("action"));
el_val_t cont_key = ({ el_val_t _if_result_674 = 0; if (str_eq(session_id, EL_STR(""))) { _if_result_674 = (EL_STR("session_continuity")); } else { _if_result_674 = (el_str_concat(EL_STR("session_continuity:"), session_id)); } _if_result_674; });
el_val_t cont_key = ({ el_val_t _if_result_678 = 0; if (str_eq(session_id, EL_STR(""))) { _if_result_678 = (EL_STR("session_continuity")); } else { _if_result_678 = (el_str_concat(EL_STR("session_continuity:"), session_id)); } _if_result_678; });
state_set(cont_key, cont_status);
el_val_t guided = ({ el_val_t _if_result_675 = 0; if (str_eq(cont_action, EL_STR("identity_check"))) { _if_result_675 = (el_str_concat(screened, EL_STR(" [steward:identity_check]"))); } else { _if_result_675 = (({ el_val_t _if_result_676 = 0; if (str_eq(cont_action, EL_STR("soft_check"))) { _if_result_676 = (el_str_concat(screened, EL_STR(" [steward:continuity_concern]"))); } else { _if_result_676 = (screened); } _if_result_676; })); } _if_result_675; });
el_val_t guided = ({ el_val_t _if_result_679 = 0; if (str_eq(cont_action, EL_STR("identity_check"))) { _if_result_679 = (el_str_concat(screened, EL_STR(" [steward:identity_check]"))); } else { _if_result_679 = (({ el_val_t _if_result_680 = 0; if (str_eq(cont_action, EL_STR("soft_check"))) { _if_result_680 = (el_str_concat(screened, EL_STR(" [steward:continuity_concern]"))); } else { _if_result_680 = (screened); } _if_result_680; })); } _if_result_679; });
el_val_t imprint_id = imprint_current();
el_val_t steward_result = steward_align(guided, imprint_id);
el_val_t steward_action = json_get(steward_result, EL_STR("action"));
el_val_t aligned = ({ el_val_t _if_result_677 = 0; if (str_eq(steward_action, EL_STR("pass"))) { _if_result_677 = (json_get(steward_result, EL_STR("content"))); } else { _if_result_677 = (json_get(steward_result, EL_STR("redirect_to"))); } _if_result_677; });
el_val_t aligned = ({ el_val_t _if_result_681 = 0; if (str_eq(steward_action, EL_STR("pass"))) { _if_result_681 = (json_get(steward_result, EL_STR("content"))); } else { _if_result_681 = (json_get(steward_result, EL_STR("redirect_to"))); } _if_result_681; });
el_val_t lc_aff_cutoff = (time_now() - 259200);
el_val_t lc_bell_nodes = engram_search_json(EL_STR("bell:soft bell:hard BellEvent affective"), 2);
el_val_t lc_has_bell = (!str_eq(lc_bell_nodes, EL_STR("")) && !str_eq(lc_bell_nodes, EL_STR("[]")));
el_val_t lc_bell_note = ({ el_val_t _if_result_678 = 0; if (lc_has_bell) { el_val_t lb0 = json_array_get(lc_bell_nodes, 0); el_val_t lb_c = json_get(lb0, EL_STR("content")); el_val_t lbm = EL_STR(" | ts:"); el_val_t lbmp = str_index_of(lb_c, lbm); el_val_t lb_ts_raw = ({ el_val_t _if_result_679 = 0; if ((lbmp >= 0)) { el_val_t lbs = el_str_concat(lbmp, str_len(lbm)); el_val_t lbr = str_slice(lb_c, lbs, str_len(lb_c)); el_val_t lbn = str_index_of(lbr, EL_STR(" | ")); _if_result_679 = (({ el_val_t _if_result_680 = 0; if ((lbn < 0)) { _if_result_680 = (lbr); } else { _if_result_680 = (str_slice(lbr, 0, lbn)); } _if_result_680; })); } else { el_val_t lbca = json_get(lb0, EL_STR("created_at")); _if_result_679 = (({ el_val_t _if_result_681 = 0; if (str_eq(lbca, EL_STR(""))) { _if_result_681 = (json_get(lb0, EL_STR("updated_at"))); } else { _if_result_681 = (lbca); } _if_result_681; })); } _if_result_679; }); el_val_t lb_ts = ({ el_val_t _if_result_682 = 0; if (str_eq(lb_ts_raw, EL_STR(""))) { _if_result_682 = (0); } else { _if_result_682 = (str_to_int(lb_ts_raw)); } _if_result_682; }); _if_result_678 = (({ el_val_t _if_result_683 = 0; if ((lb_ts > lc_aff_cutoff)) { _if_result_683 = (EL_STR("[AFFECTIVE NOTE: User was in distress in a recent session.]")); } else { _if_result_683 = (EL_STR("")); } _if_result_683; })); } else { _if_result_678 = (EL_STR("")); } _if_result_678; });
el_val_t lc_bell_note = ({ el_val_t _if_result_682 = 0; if (lc_has_bell) { el_val_t lb0 = json_array_get(lc_bell_nodes, 0); el_val_t lb_c = json_get(lb0, EL_STR("content")); el_val_t lbm = EL_STR(" | ts:"); el_val_t lbmp = str_index_of(lb_c, lbm); el_val_t lb_ts_raw = ({ el_val_t _if_result_683 = 0; if ((lbmp >= 0)) { el_val_t lbs = el_str_concat(lbmp, str_len(lbm)); el_val_t lbr = str_slice(lb_c, lbs, str_len(lb_c)); el_val_t lbn = str_index_of(lbr, EL_STR(" | ")); _if_result_683 = (({ el_val_t _if_result_684 = 0; if ((lbn < 0)) { _if_result_684 = (lbr); } else { _if_result_684 = (str_slice(lbr, 0, lbn)); } _if_result_684; })); } else { el_val_t lbca = json_get(lb0, EL_STR("created_at")); _if_result_683 = (({ el_val_t _if_result_685 = 0; if (str_eq(lbca, EL_STR(""))) { _if_result_685 = (json_get(lb0, EL_STR("updated_at"))); } else { _if_result_685 = (lbca); } _if_result_685; })); } _if_result_683; }); el_val_t lb_ts = ({ el_val_t _if_result_686 = 0; if (str_eq(lb_ts_raw, EL_STR(""))) { _if_result_686 = (0); } else { _if_result_686 = (str_to_int(lb_ts_raw)); } _if_result_686; }); _if_result_682 = (({ el_val_t _if_result_687 = 0; if ((lb_ts > lc_aff_cutoff)) { _if_result_687 = (EL_STR("[AFFECTIVE NOTE: User was in distress in a recent session.]")); } else { _if_result_687 = (EL_STR("")); } _if_result_687; })); } else { _if_result_682 = (EL_STR("")); } _if_result_682; });
el_val_t lc_pos_nodes = engram_search_json(EL_STR("PositiveEvent joy:high joy:low affective"), 2);
el_val_t lc_has_pos = (!str_eq(lc_pos_nodes, EL_STR("")) && !str_eq(lc_pos_nodes, EL_STR("[]")));
el_val_t lc_pos_note = ({ el_val_t _if_result_684 = 0; if ((lc_has_pos && str_eq(lc_bell_note, EL_STR("")))) { el_val_t lp0 = json_array_get(lc_pos_nodes, 0); el_val_t lp_c = json_get(lp0, EL_STR("content")); el_val_t lpm = EL_STR(" | ts:"); el_val_t lpmp = str_index_of(lp_c, lpm); el_val_t lp_ts_raw = ({ el_val_t _if_result_685 = 0; if ((lpmp >= 0)) { el_val_t lps = el_str_concat(lpmp, str_len(lpm)); el_val_t lpr = str_slice(lp_c, lps, str_len(lp_c)); el_val_t lpn = str_index_of(lpr, EL_STR(" | ")); _if_result_685 = (({ el_val_t _if_result_686 = 0; if ((lpn < 0)) { _if_result_686 = (lpr); } else { _if_result_686 = (str_slice(lpr, 0, lpn)); } _if_result_686; })); } else { el_val_t lpca = json_get(lp0, EL_STR("created_at")); _if_result_685 = (({ el_val_t _if_result_687 = 0; if (str_eq(lpca, EL_STR(""))) { _if_result_687 = (json_get(lp0, EL_STR("updated_at"))); } else { _if_result_687 = (lpca); } _if_result_687; })); } _if_result_685; }); el_val_t lp_ts = ({ el_val_t _if_result_688 = 0; if (str_eq(lp_ts_raw, EL_STR(""))) { _if_result_688 = (0); } else { _if_result_688 = (str_to_int(lp_ts_raw)); } _if_result_688; }); _if_result_684 = (({ el_val_t _if_result_689 = 0; if ((lp_ts > lc_aff_cutoff)) { _if_result_689 = (EL_STR("[AFFECTIVE NOTE: User shared positive news in a recent session.]")); } else { _if_result_689 = (EL_STR("")); } _if_result_689; })); } else { _if_result_684 = (EL_STR("")); } _if_result_684; });
el_val_t lc_affective_note = ({ el_val_t _if_result_690 = 0; if (!str_eq(lc_bell_note, EL_STR(""))) { _if_result_690 = (lc_bell_note); } else { _if_result_690 = (lc_pos_note); } _if_result_690; });
el_val_t lc_pos_note = ({ el_val_t _if_result_688 = 0; if ((lc_has_pos && str_eq(lc_bell_note, EL_STR("")))) { el_val_t lp0 = json_array_get(lc_pos_nodes, 0); el_val_t lp_c = json_get(lp0, EL_STR("content")); el_val_t lpm = EL_STR(" | ts:"); el_val_t lpmp = str_index_of(lp_c, lpm); el_val_t lp_ts_raw = ({ el_val_t _if_result_689 = 0; if ((lpmp >= 0)) { el_val_t lps = el_str_concat(lpmp, str_len(lpm)); el_val_t lpr = str_slice(lp_c, lps, str_len(lp_c)); el_val_t lpn = str_index_of(lpr, EL_STR(" | ")); _if_result_689 = (({ el_val_t _if_result_690 = 0; if ((lpn < 0)) { _if_result_690 = (lpr); } else { _if_result_690 = (str_slice(lpr, 0, lpn)); } _if_result_690; })); } else { el_val_t lpca = json_get(lp0, EL_STR("created_at")); _if_result_689 = (({ el_val_t _if_result_691 = 0; if (str_eq(lpca, EL_STR(""))) { _if_result_691 = (json_get(lp0, EL_STR("updated_at"))); } else { _if_result_691 = (lpca); } _if_result_691; })); } _if_result_689; }); el_val_t lp_ts = ({ el_val_t _if_result_692 = 0; if (str_eq(lp_ts_raw, EL_STR(""))) { _if_result_692 = (0); } else { _if_result_692 = (str_to_int(lp_ts_raw)); } _if_result_692; }); _if_result_688 = (({ el_val_t _if_result_693 = 0; if ((lp_ts > lc_aff_cutoff)) { _if_result_693 = (EL_STR("[AFFECTIVE NOTE: User shared positive news in a recent session.]")); } else { _if_result_693 = (EL_STR("")); } _if_result_693; })); } else { _if_result_688 = (EL_STR("")); } _if_result_688; });
el_val_t lc_affective_note = ({ el_val_t _if_result_694 = 0; if (!str_eq(lc_bell_note, EL_STR(""))) { _if_result_694 = (lc_bell_note); } else { _if_result_694 = (lc_pos_note); } _if_result_694; });
el_val_t augmented_addendum = safety_augment_system(EL_STR(""), raw_input);
augmented_addendum = ({ el_val_t _if_result_691 = 0; if (str_eq(lc_affective_note, EL_STR(""))) { _if_result_691 = (augmented_addendum); } else { _if_result_691 = (({ el_val_t _if_result_692 = 0; if (str_eq(augmented_addendum, EL_STR(""))) { _if_result_692 = (lc_affective_note); } else { _if_result_692 = (el_str_concat(el_str_concat(lc_affective_note, EL_STR("\n")), augmented_addendum)); } _if_result_692; })); } _if_result_691; });
augmented_addendum = ({ el_val_t _if_result_695 = 0; if (str_eq(lc_affective_note, EL_STR(""))) { _if_result_695 = (augmented_addendum); } else { _if_result_695 = (({ el_val_t _if_result_696 = 0; if (str_eq(augmented_addendum, EL_STR(""))) { _if_result_696 = (lc_affective_note); } else { _if_result_696 = (el_str_concat(el_str_concat(lc_affective_note, EL_STR("\n")), augmented_addendum)); } _if_result_696; })); } _if_result_695; });
state_set(EL_STR("layered_cycle_safety_system_addendum"), augmented_addendum);
el_val_t output = imprint_respond(aligned, imprint_id);
return safety_validate(output, screen_action);
@@ -30606,17 +30688,17 @@ el_val_t layered_cycle(el_val_t raw_input) {
int main(int _argc, char** _argv) {
el_runtime_init_args(_argc, _argv);
soul_cgi_id_raw = env(EL_STR("SOUL_CGI_ID"));
soul_cgi_id = ({ el_val_t _if_result_693 = 0; if (str_eq(soul_cgi_id_raw, EL_STR(""))) { _if_result_693 = (EL_STR("ntn-genesis")); } else { _if_result_693 = (soul_cgi_id_raw); } _if_result_693; });
soul_cgi_id = ({ el_val_t _if_result_697 = 0; if (str_eq(soul_cgi_id_raw, EL_STR(""))) { _if_result_697 = (EL_STR("ntn-genesis")); } else { _if_result_697 = (soul_cgi_id_raw); } _if_result_697; });
port_raw = env(EL_STR("NEURON_PORT"));
port = ({ el_val_t _if_result_694 = 0; if (str_eq(port_raw, EL_STR(""))) { _if_result_694 = (7770); } else { _if_result_694 = (str_to_int(port_raw)); } _if_result_694; });
port = ({ el_val_t _if_result_698 = 0; if (str_eq(port_raw, EL_STR(""))) { _if_result_698 = (7770); } else { _if_result_698 = (str_to_int(port_raw)); } _if_result_698; });
engram_url_raw = env(EL_STR("ENGRAM_URL"));
engram_api_key_raw = env(EL_STR("ENGRAM_API_KEY"));
snapshot_raw = env(EL_STR("SOUL_ENGRAM_PATH"));
snapshot = ({ el_val_t _if_result_695 = 0; if (str_eq(snapshot_raw, EL_STR(""))) { _if_result_695 = (el_str_concat(env(EL_STR("HOME")), EL_STR("/.neuron/engram/snapshot.json"))); } else { _if_result_695 = (snapshot_raw); } _if_result_695; });
snapshot = ({ el_val_t _if_result_699 = 0; if (str_eq(snapshot_raw, EL_STR(""))) { _if_result_699 = (el_str_concat(env(EL_STR("HOME")), EL_STR("/.neuron/engram/snapshot.json"))); } else { _if_result_699 = (snapshot_raw); } _if_result_699; });
axon_raw = env(EL_STR("NEURON_API_URL"));
axon_base = ({ el_val_t _if_result_696 = 0; if (str_eq(axon_raw, EL_STR(""))) { _if_result_696 = (EL_STR("http://localhost:7771")); } else { _if_result_696 = (axon_raw); } _if_result_696; });
axon_base = ({ el_val_t _if_result_700 = 0; if (str_eq(axon_raw, EL_STR(""))) { _if_result_700 = (EL_STR("http://localhost:7771")); } else { _if_result_700 = (axon_raw); } _if_result_700; });
studio_dir_raw = env(EL_STR("SOUL_STUDIO_DIR"));
studio_dir = ({ el_val_t _if_result_697 = 0; if (str_eq(studio_dir_raw, EL_STR(""))) { _if_result_697 = (EL_STR("/Users/will/Development/neuron-technologies/products/cgi-studio/el-daemon")); } else { _if_result_697 = (studio_dir_raw); } _if_result_697; });
studio_dir = ({ el_val_t _if_result_701 = 0; if (str_eq(studio_dir_raw, EL_STR(""))) { _if_result_701 = (EL_STR("/Users/will/Development/neuron-technologies/products/cgi-studio/el-daemon")); } else { _if_result_701 = (studio_dir_raw); } _if_result_701; });
println(el_str_concat(el_str_concat(el_str_concat(EL_STR("[soul] boot - cgi="), soul_cgi_id), EL_STR(" port=")), int_to_str(port)));
using_http_engram = !str_eq(engram_url_raw, EL_STR(""));
engram_load(snapshot);
@@ -30626,8 +30708,8 @@ int main(int _argc, char** _argv) {
println(el_str_concat(el_str_concat(EL_STR("[soul] engram -> HTTP "), engram_url_raw), EL_STR(" (no local snapshot, first boot)")));
el_val_t nodes_json = http_get(el_str_concat(engram_url_raw, EL_STR("/api/nodes?limit=10000")));
el_val_t edges_json = http_get(el_str_concat(engram_url_raw, EL_STR("/api/edges")));
el_val_t nodes_part = ({ el_val_t _if_result_698 = 0; if (str_eq(nodes_json, EL_STR(""))) { _if_result_698 = (EL_STR("[]")); } else { _if_result_698 = (nodes_json); } _if_result_698; });
el_val_t edges_part = ({ el_val_t _if_result_699 = 0; if (str_eq(edges_json, EL_STR(""))) { _if_result_699 = (EL_STR("[]")); } else { _if_result_699 = (edges_json); } _if_result_699; });
el_val_t nodes_part = ({ el_val_t _if_result_702 = 0; if (str_eq(nodes_json, EL_STR(""))) { _if_result_702 = (EL_STR("[]")); } else { _if_result_702 = (nodes_json); } _if_result_702; });
el_val_t edges_part = ({ el_val_t _if_result_703 = 0; if (str_eq(edges_json, EL_STR(""))) { _if_result_703 = (EL_STR("[]")); } else { _if_result_703 = (edges_json); } _if_result_703; });
el_val_t snapshot_data = el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"nodes\":"), nodes_part), EL_STR(",\"edges\":")), edges_part), EL_STR("}"));
el_val_t tmp_path = el_str_concat(el_str_concat(EL_STR("/tmp/soul-engram-"), soul_cgi_id), EL_STR(".json"));
fs_write(tmp_path, snapshot_data);
@@ -30651,7 +30733,7 @@ int main(int _argc, char** _argv) {
state_set(EL_STR("soul_engram_api_key"), engram_api_key_raw);
state_set(EL_STR("soul.running"), EL_STR("true"));
is_genesis = str_eq(soul_cgi_id, EL_STR("ntn-genesis"));
guard_disk = ({ el_val_t _if_result_700 = 0; if (str_eq(engram_url_raw, EL_STR(""))) { _if_result_700 = (fs_read(snapshot)); } else { _if_result_700 = (EL_STR("")); } _if_result_700; });
guard_disk = ({ el_val_t _if_result_704 = 0; if (str_eq(engram_url_raw, EL_STR(""))) { _if_result_704 = (fs_read(snapshot)); } else { _if_result_704 = (EL_STR("")); } _if_result_704; });
guard_disk_len = str_len(guard_disk);
safe_to_seed = (!using_http_engram && !((guard_disk_len > 200000) && ((engram_node_count() * 16000) < guard_disk_len)));
if (is_genesis && !safe_to_seed) {