soul: parameterize CGI ID + add dharma_room_turn handler

- soul.el: SOUL_CGI_ID, SOUL_ENGRAM_PATH, SOUL_IDENTITY env vars;
  state_set("soul_snapshot_path") so callers can find it; only call
  init_soul_edges() when cgi_id == "ntn-genesis"
- chat.el: handle_dharma_room_turn — soul builds its own context from its
  own engram, assembles system prompt, calls LLM, persists episodic memory;
  also fix is_new_tool scoping bug in handle_chat_agentic (use has_tool)
- routes.el: wire dharma_room_turn event type before chat_as_soul branch
- rebuild dist/neuron: handle_dharma_room_turn now compiled in
This commit is contained in:
Will Anderson
2026-05-03 17:55:37 -05:00
parent 2000a2c8ba
commit 2665810962
58 changed files with 189 additions and 70 deletions
Vendored
+18 -8
View File
@@ -44,6 +44,7 @@ el_val_t agentic_tools_literal(void);
el_val_t dispatch_tool(el_val_t tool_name, el_val_t tool_input);
el_val_t handle_chat_agentic(el_val_t body);
el_val_t handle_chat_as_soul(el_val_t body);
el_val_t handle_dharma_room_turn(el_val_t body);
el_val_t auto_persist(el_val_t req, el_val_t resp);
el_val_t auth_headers(el_val_t tok);
el_val_t axon_get(el_val_t path);
@@ -72,9 +73,11 @@ el_val_t handle_dharma_recv(el_val_t body);
el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body);
el_val_t init_soul_edges(void);
el_val_t soul_cgi_id_raw;
el_val_t soul_cgi_id;
el_val_t port_raw;
el_val_t port;
el_val_t snapshot_raw;
el_val_t snapshot;
el_val_t axon_raw;
el_val_t axon_base;
@@ -82,6 +85,7 @@ el_val_t studio_dir_raw;
el_val_t studio_dir;
el_val_t identity_raw;
el_val_t soul_identity;
el_val_t is_genesis;
el_val_t init_soul_edges(void) {
el_val_t self_root = EL_STR("015644f5-8194-4af0-800d-dd4a0cd71396");
@@ -157,28 +161,34 @@ el_val_t init_soul_edges(void) {
int main(int _argc, char** _argv) {
el_runtime_init_args(_argc, _argv);
el_cgi_init(EL_STR("neuron-soul"), EL_STR("ntn-genesis@http://localhost:7770"), EL_STR("william-christopher-anderson"), EL_STR("dharma-mainnet"), EL_STR("http://localhost:8742"));
soul_cgi_id = EL_STR("ntn-genesis");
soul_cgi_id_raw = env(EL_STR("SOUL_CGI_ID"));
soul_cgi_id = ({ el_val_t _if_result_1 = 0; if (str_eq(soul_cgi_id_raw, EL_STR(""))) { _if_result_1 = (EL_STR("ntn-genesis")); } else { _if_result_1 = (soul_cgi_id_raw); } _if_result_1; });
port_raw = env(EL_STR("NEURON_PORT"));
port = ({ el_val_t _if_result_1 = 0; if (str_eq(port_raw, EL_STR(""))) { _if_result_1 = (7770); } else { _if_result_1 = (str_to_int(port_raw)); } _if_result_1; });
snapshot = el_str_concat(env(EL_STR("HOME")), EL_STR("/.neuron/engram/snapshot.json"));
port = ({ el_val_t _if_result_2 = 0; if (str_eq(port_raw, EL_STR(""))) { _if_result_2 = (7770); } else { _if_result_2 = (str_to_int(port_raw)); } _if_result_2; });
snapshot_raw = env(EL_STR("SOUL_ENGRAM_PATH"));
snapshot = ({ el_val_t _if_result_3 = 0; if (str_eq(snapshot_raw, EL_STR(""))) { _if_result_3 = (el_str_concat(env(EL_STR("HOME")), EL_STR("/.neuron/engram/snapshot.json"))); } else { _if_result_3 = (snapshot_raw); } _if_result_3; });
axon_raw = env(EL_STR("NEURON_API_URL"));
axon_base = ({ el_val_t _if_result_2 = 0; if (str_eq(axon_raw, EL_STR(""))) { _if_result_2 = (EL_STR("http://localhost:7771")); } else { _if_result_2 = (axon_raw); } _if_result_2; });
axon_base = ({ el_val_t _if_result_4 = 0; if (str_eq(axon_raw, EL_STR(""))) { _if_result_4 = (EL_STR("http://localhost:7771")); } else { _if_result_4 = (axon_raw); } _if_result_4; });
studio_dir_raw = env(EL_STR("SOUL_STUDIO_DIR"));
studio_dir = ({ el_val_t _if_result_3 = 0; if (str_eq(studio_dir_raw, EL_STR(""))) { _if_result_3 = (EL_STR("/Users/will/Development/neuron-technologies/products/cgi-studio/el-daemon")); } else { _if_result_3 = (studio_dir_raw); } _if_result_3; });
studio_dir = ({ el_val_t _if_result_5 = 0; if (str_eq(studio_dir_raw, EL_STR(""))) { _if_result_5 = (EL_STR("/Users/will/Development/neuron-technologies/products/cgi-studio/el-daemon")); } else { _if_result_5 = (studio_dir_raw); } _if_result_5; });
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)));
println(el_str_concat(EL_STR("[soul] engram -> "), snapshot));
engram_load(snapshot);
println(el_str_concat(el_str_concat(el_str_concat(EL_STR("[soul] loaded - nodes="), int_to_str(engram_node_count())), EL_STR(" edges=")), int_to_str(engram_edge_count())));
identity_raw = env(EL_STR("SOUL_IDENTITY"));
soul_identity = ({ el_val_t _if_result_4 = 0; if (str_eq(identity_raw, EL_STR(""))) { _if_result_4 = (el_str_concat(el_str_concat(EL_STR("You are "), soul_cgi_id), EL_STR(", a CGI."))); } else { _if_result_4 = (identity_raw); } _if_result_4; });
soul_identity = ({ el_val_t _if_result_6 = 0; if (str_eq(identity_raw, EL_STR(""))) { _if_result_6 = (el_str_concat(el_str_concat(EL_STR("You are "), soul_cgi_id), EL_STR(", a CGI."))); } else { _if_result_6 = (identity_raw); } _if_result_6; });
state_set(EL_STR("soul_cgi_id"), soul_cgi_id);
state_set(EL_STR("soul_identity"), soul_identity);
state_set(EL_STR("soul_axon_base"), axon_base);
state_set(EL_STR("soul_token"), env(EL_STR("NEURON_TOKEN")));
state_set(EL_STR("soul_studio_dir"), studio_dir);
state_set(EL_STR("soul_snapshot_path"), snapshot);
state_set(EL_STR("soul.running"), EL_STR("true"));
init_soul_edges();
println(el_str_concat(el_str_concat(EL_STR("[soul] edges built - "), int_to_str(engram_edge_count())), EL_STR(" edges")));
is_genesis = str_eq(soul_cgi_id, EL_STR("ntn-genesis"));
if (is_genesis) {
init_soul_edges();
println(el_str_concat(el_str_concat(EL_STR("[soul] edges built - "), int_to_str(engram_edge_count())), EL_STR(" edges")));
}
engram_save(snapshot);
println(el_str_concat(EL_STR("[soul] serving on port "), int_to_str(port)));
http_serve(port, EL_STR("handle_request"));