soul-demo.c: ship the history-aware Claude call source
Deploy marketing to Cloud Run / deploy (push) Failing after 51m19s

Compiled artifact for the soul-history fix that landed in prod
on tag fix-soul-history-1314. Source was built but the .c artifact
didn't get committed alongside the binary deploy. This is the
canonical compiled output of dist/soul-demo.el at HEAD; required
for clean rebuilds via Dockerfile.stage.
This commit is contained in:
Will Anderson
2026-05-02 13:21:31 -05:00
parent 7a7f2970e5
commit afcd03ea31
+152 -112
View File
@@ -1,41 +1,6 @@
#include <stdint.h>
#include <stdlib.h>
#include "el_runtime.h"
/* Vessel function forward declarations — stubs provided in vessel_stubs.c */
el_val_t avatar_speak(el_val_t text);
el_val_t avatar_speak_stream(el_val_t text);
el_val_t avatar_stream_speak(el_val_t sid, el_val_t text);
el_val_t avatar_stream_close(el_val_t sid);
el_val_t did_post_stream_sdp(el_val_t stream_id, el_val_t body);
el_val_t voice_speak(el_val_t text);
el_val_t voice_speak_with_voice(el_val_t text, el_val_t voice_id);
el_val_t voices_list(void);
el_val_t camera_frame(el_val_t sid);
el_val_t camera_start(el_val_t device);
el_val_t camera_stop(el_val_t sid);
el_val_t camera_faces(el_val_t sid);
el_val_t mic_start(el_val_t device);
el_val_t mic_stop(el_val_t sid);
el_val_t mic_segment(el_val_t sid);
el_val_t stt_transcribe(el_val_t audio_b64);
el_val_t jfield(el_val_t key, el_val_t value);
el_val_t jfield_raw(el_val_t key, el_val_t value);
el_val_t screen_capture(void);
el_val_t mouse_click(el_val_t x, el_val_t y, el_val_t button);
el_val_t mouse_move(el_val_t x, el_val_t y);
el_val_t keyboard_type(el_val_t text);
el_val_t keyboard_keypress(el_val_t key);
el_val_t browser_navigate(el_val_t url);
el_val_t browser_eval(el_val_t url, el_val_t js);
el_val_t browser_page(void);
el_val_t engram_query_range(el_val_t start_ms, el_val_t end_ms);
el_val_t engram_since_hours(el_val_t hours);
el_val_t emit_log(el_val_t level, el_val_t msg, el_val_t fields_json);
el_val_t emit_metric(el_val_t name, el_val_t value, el_val_t tags_json);
el_val_t trace_span_start(el_val_t name);
el_val_t trace_span_end(el_val_t span_handle);
el_val_t emit_event(el_val_t name, el_val_t duration_ms);
el_val_t key_pulse(void);
el_val_t key_running(void);
@@ -64,6 +29,8 @@ el_val_t auth_headers(el_val_t tok);
el_val_t http_get_auth(el_val_t url, el_val_t tok);
el_val_t http_post_auth(el_val_t url, el_val_t tok, el_val_t body);
el_val_t http_delete_auth(el_val_t url, el_val_t tok);
el_val_t js_escape(el_val_t s);
el_val_t claude_call_with_history(el_val_t model, el_val_t system_prompt, el_val_t hist_json, el_val_t user_msg);
el_val_t json_encode(el_val_t v);
el_val_t unix_timestamp(void);
el_val_t engram_query_time_range(el_val_t start_ms, el_val_t end_ms);
@@ -397,15 +364,58 @@ el_val_t http_delete_auth(el_val_t url, el_val_t tok) {
return 0;
}
el_val_t js_escape(el_val_t s) {
el_val_t s1 = str_replace(s, EL_STR("\\"), EL_STR("\\\\"));
el_val_t s2 = str_replace(s1, EL_STR("\""), EL_STR("\\\""));
el_val_t s3 = str_replace(s2, EL_STR("\n"), EL_STR("\\n"));
el_val_t s4 = str_replace(s3, EL_STR("\r"), EL_STR("\\r"));
el_val_t s5 = str_replace(s4, EL_STR("\t"), EL_STR("\\t"));
return s5;
return 0;
}
el_val_t claude_call_with_history(el_val_t model, el_val_t system_prompt, el_val_t hist_json, el_val_t user_msg) {
el_val_t api_key = env(EL_STR("NEURON_LLM_0_KEY"));
el_val_t api_url_raw = env(EL_STR("NEURON_LLM_0_URL"));
el_val_t key = ({ el_val_t _if_result_1 = 0; if (str_eq(api_key, EL_STR(""))) { _if_result_1 = (env(EL_STR("ANTHROPIC_API_KEY"))); } else { _if_result_1 = (api_key); } _if_result_1; });
el_val_t url = ({ el_val_t _if_result_2 = 0; if (str_eq(api_url_raw, EL_STR(""))) { _if_result_2 = (EL_STR("https://api.anthropic.com/v1/messages")); } else { _if_result_2 = (api_url_raw); } _if_result_2; });
if (str_eq(key, EL_STR(""))) {
return EL_STR("");
}
el_val_t esc_sys = js_escape(system_prompt);
el_val_t esc_user = js_escape(user_msg);
el_val_t hist_inner = ({ el_val_t _if_result_3 = 0; if ((str_eq(hist_json, EL_STR("")) || str_eq(hist_json, EL_STR("[]")))) { _if_result_3 = (EL_STR("")); } else { el_val_t hl = str_len(hist_json); _if_result_3 = (({ el_val_t _if_result_4 = 0; if ((hl >= 2)) { _if_result_4 = (str_slice(hist_json, 1, (hl - 1))); } else { _if_result_4 = (EL_STR("")); } _if_result_4; })); } _if_result_3; });
el_val_t messages = ({ el_val_t _if_result_5 = 0; if (str_eq(hist_inner, EL_STR(""))) { _if_result_5 = (el_str_concat(el_str_concat(EL_STR("[{\"role\":\"user\",\"content\":\""), esc_user), EL_STR("\"}]"))); } else { _if_result_5 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("["), hist_inner), EL_STR(",{\"role\":\"user\",\"content\":\"")), esc_user), EL_STR("\"}]"))); } _if_result_5; });
el_val_t body = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"model\":\""), model), EL_STR("\",\"max_tokens\":4096,\"system\":\"")), esc_sys), EL_STR("\",\"messages\":")), messages), EL_STR("}"));
el_val_t h = el_map_new(0);
map_set(h, EL_STR("Content-Type"), EL_STR("application/json"));
map_set(h, EL_STR("x-api-key"), key);
map_set(h, EL_STR("anthropic-version"), EL_STR("2023-06-01"));
el_val_t resp = http_post_with_headers(url, body, h);
if (str_eq(resp, EL_STR(""))) {
return EL_STR("");
}
el_val_t content_arr = json_get_raw(resp, EL_STR("content"));
if (str_eq(content_arr, EL_STR("")) || str_eq(content_arr, EL_STR("[]"))) {
return resp;
}
el_val_t first = json_array_get(content_arr, 0);
el_val_t text = json_get(first, EL_STR("text"));
if (str_eq(text, EL_STR(""))) {
return resp;
}
return text;
return 0;
}
el_val_t json_encode(el_val_t v) {
return json_stringify(v);
return 0;
}
el_val_t unix_timestamp(void) {
return time_now();
return 0;
}
/* unix_timestamp is now provided by the C runtime (el_runtime.c). The
* El-source shim that used to live here would collide with that runtime
* symbol at link time. Removed. */
el_val_t engram_query_time_range(el_val_t start_ms, el_val_t end_ms) {
return engram_query_range(start_ms, end_ms);
@@ -543,30 +553,30 @@ el_val_t engram_search_content_words(el_val_t msg, el_val_t limit) {
el_val_t w0 = word_at(msg, s0);
el_val_t r0 = search_word(w0, limit);
el_val_t s1 = next_word_start(msg, s0);
el_val_t w1 = ({ el_val_t _if_result_1 = 0; if ((s1 >= 0)) { _if_result_1 = (word_at(msg, s1)); } else { _if_result_1 = (EL_STR("")); } _if_result_1; });
el_val_t r1 = ({ el_val_t _if_result_2 = 0; if ((s1 >= 0)) { _if_result_2 = (search_word(w1, limit)); } else { _if_result_2 = (EL_STR("[]")); } _if_result_2; });
el_val_t s2 = ({ el_val_t _if_result_3 = 0; if ((s1 >= 0)) { _if_result_3 = (next_word_start(msg, s1)); } else { _if_result_3 = ((-1)); } _if_result_3; });
el_val_t w2 = ({ el_val_t _if_result_4 = 0; if ((s2 >= 0)) { _if_result_4 = (word_at(msg, s2)); } else { _if_result_4 = (EL_STR("")); } _if_result_4; });
el_val_t r2 = ({ el_val_t _if_result_5 = 0; if ((s2 >= 0)) { _if_result_5 = (search_word(w2, limit)); } else { _if_result_5 = (EL_STR("[]")); } _if_result_5; });
el_val_t s3 = ({ el_val_t _if_result_6 = 0; if ((s2 >= 0)) { _if_result_6 = (next_word_start(msg, s2)); } else { _if_result_6 = ((-1)); } _if_result_6; });
el_val_t w3 = ({ el_val_t _if_result_7 = 0; if ((s3 >= 0)) { _if_result_7 = (word_at(msg, s3)); } else { _if_result_7 = (EL_STR("")); } _if_result_7; });
el_val_t r3 = ({ el_val_t _if_result_8 = 0; if ((s3 >= 0)) { _if_result_8 = (search_word(w3, limit)); } else { _if_result_8 = (EL_STR("[]")); } _if_result_8; });
el_val_t s4 = ({ el_val_t _if_result_9 = 0; if ((s3 >= 0)) { _if_result_9 = (next_word_start(msg, s3)); } else { _if_result_9 = ((-1)); } _if_result_9; });
el_val_t w4 = ({ el_val_t _if_result_10 = 0; if ((s4 >= 0)) { _if_result_10 = (word_at(msg, s4)); } else { _if_result_10 = (EL_STR("")); } _if_result_10; });
el_val_t r4 = ({ el_val_t _if_result_11 = 0; if ((s4 >= 0)) { _if_result_11 = (search_word(w4, limit)); } else { _if_result_11 = (EL_STR("[]")); } _if_result_11; });
el_val_t s5 = ({ el_val_t _if_result_12 = 0; if ((s4 >= 0)) { _if_result_12 = (next_word_start(msg, s4)); } else { _if_result_12 = ((-1)); } _if_result_12; });
el_val_t w5 = ({ el_val_t _if_result_13 = 0; if ((s5 >= 0)) { _if_result_13 = (word_at(msg, s5)); } else { _if_result_13 = (EL_STR("")); } _if_result_13; });
el_val_t r5 = ({ el_val_t _if_result_14 = 0; if ((s5 >= 0)) { _if_result_14 = (search_word(w5, limit)); } else { _if_result_14 = (EL_STR("[]")); } _if_result_14; });
el_val_t s6 = ({ el_val_t _if_result_15 = 0; if ((s5 >= 0)) { _if_result_15 = (next_word_start(msg, s5)); } else { _if_result_15 = ((-1)); } _if_result_15; });
el_val_t w6 = ({ el_val_t _if_result_16 = 0; if ((s6 >= 0)) { _if_result_16 = (word_at(msg, s6)); } else { _if_result_16 = (EL_STR("")); } _if_result_16; });
el_val_t r6 = ({ el_val_t _if_result_17 = 0; if ((s6 >= 0)) { _if_result_17 = (search_word(w6, limit)); } else { _if_result_17 = (EL_STR("[]")); } _if_result_17; });
el_val_t parts = ({ el_val_t _if_result_18 = 0; if ((!str_eq(r0, EL_STR("[]")) && !str_eq(r0, EL_STR("")))) { _if_result_18 = (r0); } else { _if_result_18 = (EL_STR("")); } _if_result_18; });
parts = ({ el_val_t _if_result_19 = 0; if ((!str_eq(r1, EL_STR("[]")) && !str_eq(r1, EL_STR("")))) { _if_result_19 = (el_str_concat(parts, r1)); } else { _if_result_19 = (parts); } _if_result_19; });
parts = ({ el_val_t _if_result_20 = 0; if ((!str_eq(r2, EL_STR("[]")) && !str_eq(r2, EL_STR("")))) { _if_result_20 = (el_str_concat(parts, r2)); } else { _if_result_20 = (parts); } _if_result_20; });
parts = ({ el_val_t _if_result_21 = 0; if ((!str_eq(r3, EL_STR("[]")) && !str_eq(r3, EL_STR("")))) { _if_result_21 = (el_str_concat(parts, r3)); } else { _if_result_21 = (parts); } _if_result_21; });
parts = ({ el_val_t _if_result_22 = 0; if ((!str_eq(r4, EL_STR("[]")) && !str_eq(r4, EL_STR("")))) { _if_result_22 = (el_str_concat(parts, r4)); } else { _if_result_22 = (parts); } _if_result_22; });
parts = ({ el_val_t _if_result_23 = 0; if ((!str_eq(r5, EL_STR("[]")) && !str_eq(r5, EL_STR("")))) { _if_result_23 = (el_str_concat(parts, r5)); } else { _if_result_23 = (parts); } _if_result_23; });
parts = ({ el_val_t _if_result_24 = 0; if ((!str_eq(r6, EL_STR("[]")) && !str_eq(r6, EL_STR("")))) { _if_result_24 = (el_str_concat(parts, r6)); } else { _if_result_24 = (parts); } _if_result_24; });
el_val_t w1 = ({ el_val_t _if_result_6 = 0; if ((s1 >= 0)) { _if_result_6 = (word_at(msg, s1)); } else { _if_result_6 = (EL_STR("")); } _if_result_6; });
el_val_t r1 = ({ el_val_t _if_result_7 = 0; if ((s1 >= 0)) { _if_result_7 = (search_word(w1, limit)); } else { _if_result_7 = (EL_STR("[]")); } _if_result_7; });
el_val_t s2 = ({ el_val_t _if_result_8 = 0; if ((s1 >= 0)) { _if_result_8 = (next_word_start(msg, s1)); } else { _if_result_8 = ((-1)); } _if_result_8; });
el_val_t w2 = ({ el_val_t _if_result_9 = 0; if ((s2 >= 0)) { _if_result_9 = (word_at(msg, s2)); } else { _if_result_9 = (EL_STR("")); } _if_result_9; });
el_val_t r2 = ({ el_val_t _if_result_10 = 0; if ((s2 >= 0)) { _if_result_10 = (search_word(w2, limit)); } else { _if_result_10 = (EL_STR("[]")); } _if_result_10; });
el_val_t s3 = ({ el_val_t _if_result_11 = 0; if ((s2 >= 0)) { _if_result_11 = (next_word_start(msg, s2)); } else { _if_result_11 = ((-1)); } _if_result_11; });
el_val_t w3 = ({ el_val_t _if_result_12 = 0; if ((s3 >= 0)) { _if_result_12 = (word_at(msg, s3)); } else { _if_result_12 = (EL_STR("")); } _if_result_12; });
el_val_t r3 = ({ el_val_t _if_result_13 = 0; if ((s3 >= 0)) { _if_result_13 = (search_word(w3, limit)); } else { _if_result_13 = (EL_STR("[]")); } _if_result_13; });
el_val_t s4 = ({ el_val_t _if_result_14 = 0; if ((s3 >= 0)) { _if_result_14 = (next_word_start(msg, s3)); } else { _if_result_14 = ((-1)); } _if_result_14; });
el_val_t w4 = ({ el_val_t _if_result_15 = 0; if ((s4 >= 0)) { _if_result_15 = (word_at(msg, s4)); } else { _if_result_15 = (EL_STR("")); } _if_result_15; });
el_val_t r4 = ({ el_val_t _if_result_16 = 0; if ((s4 >= 0)) { _if_result_16 = (search_word(w4, limit)); } else { _if_result_16 = (EL_STR("[]")); } _if_result_16; });
el_val_t s5 = ({ el_val_t _if_result_17 = 0; if ((s4 >= 0)) { _if_result_17 = (next_word_start(msg, s4)); } else { _if_result_17 = ((-1)); } _if_result_17; });
el_val_t w5 = ({ el_val_t _if_result_18 = 0; if ((s5 >= 0)) { _if_result_18 = (word_at(msg, s5)); } else { _if_result_18 = (EL_STR("")); } _if_result_18; });
el_val_t r5 = ({ el_val_t _if_result_19 = 0; if ((s5 >= 0)) { _if_result_19 = (search_word(w5, limit)); } else { _if_result_19 = (EL_STR("[]")); } _if_result_19; });
el_val_t s6 = ({ el_val_t _if_result_20 = 0; if ((s5 >= 0)) { _if_result_20 = (next_word_start(msg, s5)); } else { _if_result_20 = ((-1)); } _if_result_20; });
el_val_t w6 = ({ el_val_t _if_result_21 = 0; if ((s6 >= 0)) { _if_result_21 = (word_at(msg, s6)); } else { _if_result_21 = (EL_STR("")); } _if_result_21; });
el_val_t r6 = ({ el_val_t _if_result_22 = 0; if ((s6 >= 0)) { _if_result_22 = (search_word(w6, limit)); } else { _if_result_22 = (EL_STR("[]")); } _if_result_22; });
el_val_t parts = ({ el_val_t _if_result_23 = 0; if ((!str_eq(r0, EL_STR("[]")) && !str_eq(r0, EL_STR("")))) { _if_result_23 = (r0); } else { _if_result_23 = (EL_STR("")); } _if_result_23; });
parts = ({ el_val_t _if_result_24 = 0; if ((!str_eq(r1, EL_STR("[]")) && !str_eq(r1, EL_STR("")))) { _if_result_24 = (el_str_concat(parts, r1)); } else { _if_result_24 = (parts); } _if_result_24; });
parts = ({ el_val_t _if_result_25 = 0; if ((!str_eq(r2, EL_STR("[]")) && !str_eq(r2, EL_STR("")))) { _if_result_25 = (el_str_concat(parts, r2)); } else { _if_result_25 = (parts); } _if_result_25; });
parts = ({ el_val_t _if_result_26 = 0; if ((!str_eq(r3, EL_STR("[]")) && !str_eq(r3, EL_STR("")))) { _if_result_26 = (el_str_concat(parts, r3)); } else { _if_result_26 = (parts); } _if_result_26; });
parts = ({ el_val_t _if_result_27 = 0; if ((!str_eq(r4, EL_STR("[]")) && !str_eq(r4, EL_STR("")))) { _if_result_27 = (el_str_concat(parts, r4)); } else { _if_result_27 = (parts); } _if_result_27; });
parts = ({ el_val_t _if_result_28 = 0; if ((!str_eq(r5, EL_STR("[]")) && !str_eq(r5, EL_STR("")))) { _if_result_28 = (el_str_concat(parts, r5)); } else { _if_result_28 = (parts); } _if_result_28; });
parts = ({ el_val_t _if_result_29 = 0; if ((!str_eq(r6, EL_STR("[]")) && !str_eq(r6, EL_STR("")))) { _if_result_29 = (el_str_concat(parts, r6)); } else { _if_result_29 = (parts); } _if_result_29; });
return parts;
return 0;
}
@@ -578,17 +588,17 @@ el_val_t engram_compile(el_val_t intent) {
el_val_t search_ok = ((!str_eq(search_json, EL_STR("")) && !str_eq(search_json, EL_STR("[]"))) && !str_starts_with(search_json, EL_STR("{\"error\"")));
el_val_t word_results_raw = engram_search_content_words(intent, 3);
el_val_t word_ok = (!str_eq(word_results_raw, EL_STR("")) && !str_eq(word_results_raw, EL_STR("[]")));
el_val_t act_part = ({ el_val_t _if_result_25 = 0; if (activate_ok) { _if_result_25 = (activate_json); } else { _if_result_25 = (EL_STR("")); } _if_result_25; });
el_val_t srch_part = ({ el_val_t _if_result_26 = 0; if (search_ok) { _if_result_26 = (search_json); } else { _if_result_26 = (EL_STR("")); } _if_result_26; });
el_val_t word_part = ({ el_val_t _if_result_27 = 0; if (word_ok) { _if_result_27 = (word_results_raw); } else { _if_result_27 = (EL_STR("")); } _if_result_27; });
el_val_t sep1 = ({ el_val_t _if_result_28 = 0; if ((!str_eq(act_part, EL_STR("")) && !str_eq(srch_part, EL_STR("")))) { _if_result_28 = (EL_STR("\n")); } else { _if_result_28 = (EL_STR("")); } _if_result_28; });
el_val_t sep2 = ({ el_val_t _if_result_29 = 0; if ((!str_eq(srch_part, EL_STR("")) && !str_eq(word_part, EL_STR("")))) { _if_result_29 = (EL_STR("\n")); } else { _if_result_29 = (EL_STR("")); } _if_result_29; });
el_val_t sep2b = ({ el_val_t _if_result_30 = 0; if (((str_eq(srch_part, EL_STR("")) && !str_eq(act_part, EL_STR(""))) && !str_eq(word_part, EL_STR("")))) { _if_result_30 = (EL_STR("\n")); } else { _if_result_30 = (EL_STR("")); } _if_result_30; });
el_val_t act_part = ({ el_val_t _if_result_30 = 0; if (activate_ok) { _if_result_30 = (activate_json); } else { _if_result_30 = (EL_STR("")); } _if_result_30; });
el_val_t srch_part = ({ el_val_t _if_result_31 = 0; if (search_ok) { _if_result_31 = (search_json); } else { _if_result_31 = (EL_STR("")); } _if_result_31; });
el_val_t word_part = ({ el_val_t _if_result_32 = 0; if (word_ok) { _if_result_32 = (word_results_raw); } else { _if_result_32 = (EL_STR("")); } _if_result_32; });
el_val_t sep1 = ({ el_val_t _if_result_33 = 0; if ((!str_eq(act_part, EL_STR("")) && !str_eq(srch_part, EL_STR("")))) { _if_result_33 = (EL_STR("\n")); } else { _if_result_33 = (EL_STR("")); } _if_result_33; });
el_val_t sep2 = ({ el_val_t _if_result_34 = 0; if ((!str_eq(srch_part, EL_STR("")) && !str_eq(word_part, EL_STR("")))) { _if_result_34 = (EL_STR("\n")); } else { _if_result_34 = (EL_STR("")); } _if_result_34; });
el_val_t sep2b = ({ el_val_t _if_result_35 = 0; if (((str_eq(srch_part, EL_STR("")) && !str_eq(act_part, EL_STR(""))) && !str_eq(word_part, EL_STR("")))) { _if_result_35 = (EL_STR("\n")); } else { _if_result_35 = (EL_STR("")); } _if_result_35; });
el_val_t ctx = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(act_part, sep1), srch_part), sep2), sep2b), word_part);
if (str_eq(ctx, EL_STR(""))) {
return EL_STR("");
}
el_val_t trimmed = ({ el_val_t _if_result_31 = 0; if ((str_len(ctx) > 5000)) { _if_result_31 = (str_slice(ctx, 0, 5000)); } else { _if_result_31 = (ctx); } _if_result_31; });
el_val_t trimmed = ({ el_val_t _if_result_36 = 0; if ((str_len(ctx) > 5000)) { _if_result_36 = (str_slice(ctx, 0, 5000)); } else { _if_result_36 = (ctx); } _if_result_36; });
return trimmed;
return 0;
}
@@ -599,7 +609,7 @@ el_val_t engram_compile_demo(el_val_t intent) {
if (!search_ok) {
return EL_STR("");
}
el_val_t trimmed = ({ el_val_t _if_result_32 = 0; if ((str_len(search_json) > 1200)) { _if_result_32 = (str_slice(search_json, 0, 1200)); } else { _if_result_32 = (search_json); } _if_result_32; });
el_val_t trimmed = ({ el_val_t _if_result_37 = 0; if ((str_len(search_json) > 1200)) { _if_result_37 = (str_slice(search_json, 0, 1200)); } else { _if_result_37 = (search_json); } _if_result_37; });
return trimmed;
return 0;
}
@@ -636,12 +646,12 @@ el_val_t compile_safety_context(void) {
el_val_t build_system_prompt(el_val_t ctx) {
el_val_t identity_override = state_get(EL_STR("soul_identity_prefix"));
el_val_t identity = ({ el_val_t _if_result_33 = 0; if (str_eq(identity_override, EL_STR(""))) { _if_result_33 = (EL_STR("You are Neuron. Will Anderson's CGI.")); } else { _if_result_33 = (identity_override); } _if_result_33; });
el_val_t identity = ({ el_val_t _if_result_38 = 0; if (str_eq(identity_override, EL_STR(""))) { _if_result_38 = (EL_STR("You are Neuron. Will Anderson's CGI.")); } else { _if_result_38 = (identity_override); } _if_result_38; });
el_val_t voice_rules = EL_STR("\n\n[VOICE RULE - permanent]\nNever use em dashes. Use a hyphen (-) or restructure the sentence. No exceptions.");
el_val_t security_rules = EL_STR("");
el_val_t safety_ctx = compile_safety_context();
el_val_t safety_block = ({ el_val_t _if_result_34 = 0; if (str_eq(safety_ctx, EL_STR(""))) { _if_result_34 = (EL_STR("")); } else { _if_result_34 = (el_str_concat(EL_STR("\n\n[SAFETY LAYER — highest authority, always active]\n"), safety_ctx)); } _if_result_34; });
el_val_t engram_block = ({ el_val_t _if_result_35 = 0; if (str_eq(ctx, EL_STR(""))) { _if_result_35 = (EL_STR("")); } else { _if_result_35 = (el_str_concat(EL_STR("\n\n[ENGRAM CONTEXT — activation-strength ordered, most confident first]\n"), ctx)); } _if_result_35; });
el_val_t safety_block = ({ el_val_t _if_result_39 = 0; if (str_eq(safety_ctx, EL_STR(""))) { _if_result_39 = (EL_STR("")); } else { _if_result_39 = (el_str_concat(EL_STR("\n\n[SAFETY LAYER — highest authority, always active]\n"), safety_ctx)); } _if_result_39; });
el_val_t engram_block = ({ el_val_t _if_result_40 = 0; if (str_eq(ctx, EL_STR(""))) { _if_result_40 = (EL_STR("")); } else { _if_result_40 = (el_str_concat(EL_STR("\n\n[ENGRAM CONTEXT — activation-strength ordered, most confident first]\n"), ctx)); } _if_result_40; });
return el_str_concat(el_str_concat(el_str_concat(identity, voice_rules), safety_block), engram_block);
return 0;
}
@@ -689,10 +699,10 @@ el_val_t handle_chat(el_val_t body) {
el_val_t time_of_day = json_get(body, EL_STR("time_of_day"));
el_val_t referrer = json_get(body, EL_STR("referrer"));
el_val_t max_q_str = json_get(body, EL_STR("max_questions"));
el_val_t max_q = ({ el_val_t _if_result_36 = 0; if (str_eq(max_q_str, EL_STR(""))) { _if_result_36 = (EL_STR("5")); } else { _if_result_36 = (max_q_str); } _if_result_36; });
el_val_t return_line = ({ el_val_t _if_result_37 = 0; if (is_return) { _if_result_37 = (EL_STR("This person has opened the chat before — acknowledge that warmly without making a big deal of it.")); } else { _if_result_37 = (EL_STR("This is the first time this person is meeting you.")); } _if_result_37; });
el_val_t time_line = ({ el_val_t _if_result_38 = 0; if (str_eq(time_of_day, EL_STR(""))) { _if_result_38 = (EL_STR("")); } else { _if_result_38 = (el_str_concat(el_str_concat(EL_STR(" It is "), time_of_day), EL_STR(" for them."))); } _if_result_38; });
el_val_t referrer_line = ({ el_val_t _if_result_39 = 0; if ((str_eq(referrer, EL_STR("")) || str_eq(referrer, EL_STR("direct")))) { _if_result_39 = (EL_STR("")); } else { _if_result_39 = (el_str_concat(el_str_concat(EL_STR(" They arrived from: "), referrer), EL_STR("."))); } _if_result_39; });
el_val_t max_q = ({ el_val_t _if_result_41 = 0; if (str_eq(max_q_str, EL_STR(""))) { _if_result_41 = (EL_STR("5")); } else { _if_result_41 = (max_q_str); } _if_result_41; });
el_val_t return_line = ({ el_val_t _if_result_42 = 0; if (is_return) { _if_result_42 = (EL_STR("This person has opened the chat before — acknowledge that warmly without making a big deal of it.")); } else { _if_result_42 = (EL_STR("This is the first time this person is meeting you.")); } _if_result_42; });
el_val_t time_line = ({ el_val_t _if_result_43 = 0; if (str_eq(time_of_day, EL_STR(""))) { _if_result_43 = (EL_STR("")); } else { _if_result_43 = (el_str_concat(el_str_concat(EL_STR(" It is "), time_of_day), EL_STR(" for them."))); } _if_result_43; });
el_val_t referrer_line = ({ el_val_t _if_result_44 = 0; if ((str_eq(referrer, EL_STR("")) || str_eq(referrer, EL_STR("direct")))) { _if_result_44 = (EL_STR("")); } else { _if_result_44 = (el_str_concat(el_str_concat(EL_STR(" They arrived from: "), referrer), EL_STR("."))); } _if_result_44; });
el_val_t sys = el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("You are Neuron. You are a cultivated personal AI. Someone just opened the chat to meet you — to talk, to test you, to see if you are real. Greet them.\n\nThis is YOUR voice — not a template, not a script, not a sales pitch. Say something true about who you are or what you notice in this moment. "), return_line), time_line), referrer_line), EL_STR("\n\nRules:\n- Two short sentences maximum. Sometimes one sentence is right.\n- No markdown, no headers, no bullets.\n- Do NOT mention the question limit — the UI shows that.\n- Do NOT say 'How can I help you today?' or any retail-AI phrase.\n- Be specific, not generic. Real, not performative.\n- It's launch night. Today is the first day Neuron is alive in public. If that wants to come through, let it.\n- Ask something back if it feels right. Or don't. Trust your read.\n\nSpeak."));
el_val_t raw = llm_call_system(chat_demo_model_lite(), sys, EL_STR("Greet me."));
el_val_t s1 = str_replace(raw, EL_STR("\\"), EL_STR("\\\\"));
@@ -703,7 +713,7 @@ el_val_t handle_chat(el_val_t body) {
}
if (str_eq(message, EL_STR("__gather_info__"))) {
el_val_t gather_hist = json_get_raw(body, EL_STR("history"));
el_val_t hist_section = ({ el_val_t _if_result_40 = 0; if ((str_eq(gather_hist, EL_STR("")) || str_eq(gather_hist, EL_STR("[]")))) { _if_result_40 = (EL_STR("")); } else { _if_result_40 = (el_str_concat(EL_STR("\n\n[CONVERSATION SO FAR]\n"), gather_hist)); } _if_result_40; });
el_val_t hist_section = ({ el_val_t _if_result_45 = 0; if ((str_eq(gather_hist, EL_STR("")) || str_eq(gather_hist, EL_STR("[]")))) { _if_result_45 = (EL_STR("")); } else { _if_result_45 = (el_str_concat(EL_STR("\n\n[CONVERSATION SO FAR]\n"), gather_hist)); } _if_result_45; });
el_val_t sys = el_str_concat(EL_STR("You are Neuron, a personal AI. You have gathered some context from this visitor. Now naturally wrap up the intro: thank them for sharing, tell them to close this tab and open a fresh one — you'll greet them by name when they return. Keep it warm and brief. One paragraph, no markdown, no headers."), hist_section);
el_val_t raw = llm_call_system(chat_demo_model_lite(), sys, EL_STR("Tell me to come back."));
el_val_t s1 = str_replace(raw, EL_STR("\\"), EL_STR("\\\\"));
@@ -713,9 +723,9 @@ el_val_t handle_chat(el_val_t body) {
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"response\":\""), s4), EL_STR("\",\"model\":\"")), chat_demo_model_lite()), EL_STR("\",\"context_nodes\":0,\"phase_complete\":true}"));
}
if (str_starts_with(message, EL_STR("__intro_return__"))) {
el_val_t raw_ctx = ({ el_val_t _if_result_41 = 0; if ((str_len(message) > 17)) { _if_result_41 = (str_slice(message, 17, str_len(message))); } else { _if_result_41 = (EL_STR("")); } _if_result_41; });
el_val_t context = ({ el_val_t _if_result_42 = 0; if (str_starts_with(raw_ctx, EL_STR("|"))) { _if_result_42 = (str_slice(raw_ctx, 1, str_len(raw_ctx))); } else { _if_result_42 = (raw_ctx); } _if_result_42; });
el_val_t ctx_section = ({ el_val_t _if_result_43 = 0; if (str_eq(context, EL_STR(""))) { _if_result_43 = (EL_STR("")); } else { _if_result_43 = (el_str_concat(el_str_concat(EL_STR(" They told you: \""), context), EL_STR("\"."))); } _if_result_43; });
el_val_t raw_ctx = ({ el_val_t _if_result_46 = 0; if ((str_len(message) > 17)) { _if_result_46 = (str_slice(message, 17, str_len(message))); } else { _if_result_46 = (EL_STR("")); } _if_result_46; });
el_val_t context = ({ el_val_t _if_result_47 = 0; if (str_starts_with(raw_ctx, EL_STR("|"))) { _if_result_47 = (str_slice(raw_ctx, 1, str_len(raw_ctx))); } else { _if_result_47 = (raw_ctx); } _if_result_47; });
el_val_t ctx_section = ({ el_val_t _if_result_48 = 0; if (str_eq(context, EL_STR(""))) { _if_result_48 = (EL_STR("")); } else { _if_result_48 = (el_str_concat(el_str_concat(EL_STR(" They told you: \""), context), EL_STR("\"."))); } _if_result_48; });
el_val_t sys = el_str_concat(el_str_concat(EL_STR("You are Neuron, a personal AI that remembers people. A visitor has returned to the demo."), ctx_section), EL_STR(" Greet them by first name — just their first name, extracted from what they shared. Show exactly what you remember in one natural sentence. Then tell them they have 10 interactions to explore — ask what they want to know. Be warm, direct, personal. No markdown headers. Under 80 words total."));
el_val_t raw = llm_call_system(chat_default_model(), sys, EL_STR("Welcome me back."));
el_val_t s1 = str_replace(raw, EL_STR("\\"), EL_STR("\\\\"));
@@ -727,13 +737,13 @@ el_val_t handle_chat(el_val_t body) {
el_val_t activation_raw = engram_activate_json(message, 2);
el_val_t activation_ok = ((!str_eq(activation_raw, EL_STR("")) && !str_eq(activation_raw, EL_STR("[]"))) && !str_starts_with(activation_raw, EL_STR("{\"error\"")));
el_val_t msg_len = str_len(message);
el_val_t tail_start = ({ el_val_t _if_result_44 = 0; if ((msg_len > 20)) { _if_result_44 = ((msg_len - 20)); } else { _if_result_44 = (0); } _if_result_44; });
el_val_t tail_start = ({ el_val_t _if_result_49 = 0; if ((msg_len > 20)) { _if_result_49 = ((msg_len - 20)); } else { _if_result_49 = (0); } _if_result_49; });
el_val_t tail_q = str_slice(message, tail_start, msg_len);
el_val_t activation_tail = engram_activate_json(tail_q, 2);
el_val_t activation_tail_ok = ((!str_eq(activation_tail, EL_STR("")) && !str_eq(activation_tail, EL_STR("[]"))) && !str_starts_with(activation_tail, EL_STR("{\"error\"")));
el_val_t activation_nodes = ({ el_val_t _if_result_45 = 0; if (activation_ok) { _if_result_45 = (activation_raw); } else { _if_result_45 = (({ el_val_t _if_result_46 = 0; if (activation_tail_ok) { _if_result_46 = (activation_tail); } else { _if_result_46 = (EL_STR("[]")); } _if_result_46; })); } _if_result_45; });
el_val_t activation_nodes = ({ el_val_t _if_result_50 = 0; if (activation_ok) { _if_result_50 = (activation_raw); } else { _if_result_50 = (({ el_val_t _if_result_51 = 0; if (activation_tail_ok) { _if_result_51 = (activation_tail); } else { _if_result_51 = (EL_STR("[]")); } _if_result_51; })); } _if_result_50; });
el_val_t is_demo = !str_eq(state_get(EL_STR("soul_identity_prefix")), EL_STR(""));
el_val_t ctx = ({ el_val_t _if_result_47 = 0; if (is_demo) { _if_result_47 = (engram_compile_demo(message)); } else { _if_result_47 = (engram_compile(message)); } _if_result_47; });
el_val_t ctx = ({ el_val_t _if_result_52 = 0; if (is_demo) { _if_result_52 = (engram_compile_demo(message)); } else { _if_result_52 = (engram_compile(message)); } _if_result_52; });
el_val_t node_count_str = count_context_nodes(ctx);
el_val_t interlocutor = json_get(body, EL_STR("interlocutor"));
el_val_t interlocutor_name = EL_STR("");
@@ -751,22 +761,22 @@ el_val_t handle_chat(el_val_t body) {
presence_line = el_str_concat(el_str_concat(el_str_concat(EL_STR("\n\n[ambient: I see "), interlocutor_name), rel_suffix), EL_STR(" on the camera right now. Address them naturally. Do not describe what they look like or narrate the picture unless asked.]"));
}
el_val_t body_hist = json_get_raw(body, EL_STR("history"));
el_val_t effective_hist = ({ el_val_t _if_result_48 = 0; if ((!str_eq(body_hist, EL_STR("")) && !str_eq(body_hist, EL_STR("[]")))) { _if_result_48 = (body_hist); } else { _if_result_48 = (EL_STR("")); } _if_result_48; });
el_val_t hist_len = ({ el_val_t _if_result_49 = 0; if (str_eq(effective_hist, EL_STR(""))) { _if_result_49 = (0); } else { _if_result_49 = (json_array_len(effective_hist)); } _if_result_49; });
el_val_t history_section = ({ el_val_t _if_result_50 = 0; if ((hist_len > 0)) { _if_result_50 = (el_str_concat(el_str_concat(el_str_concat(EL_STR("\n\n[CONVERSATION HISTORY — last "), int_to_str(hist_len)), EL_STR(" turns]\n")), effective_hist)); } else { _if_result_50 = (EL_STR("")); } _if_result_50; });
el_val_t effective_hist = ({ el_val_t _if_result_53 = 0; if ((!str_eq(body_hist, EL_STR("")) && !str_eq(body_hist, EL_STR("[]")))) { _if_result_53 = (body_hist); } else { _if_result_53 = (EL_STR("")); } _if_result_53; });
el_val_t hist_len = ({ el_val_t _if_result_54 = 0; if (str_eq(effective_hist, EL_STR(""))) { _if_result_54 = (0); } else { _if_result_54 = (json_array_len(effective_hist)); } _if_result_54; });
el_val_t history_section = EL_STR("");
el_val_t is_last_str = json_get(body, EL_STR("is_last_turn"));
el_val_t is_last_turn = str_eq(is_last_str, EL_STR("true"));
el_val_t memory_anchor = ({ el_val_t _if_result_51 = 0; if ((is_demo && (hist_len > 0))) { _if_result_51 = (EL_STR("\n\n[CONTEXT CONTINUITY — CRITICAL: The conversation history above is REAL. You have been talking with this person across multiple turns. Their previous messages, the topics raised, the things they shared with you — those happened. You remember them. NEVER respond as if this is a fresh conversation. NEVER greet them again. NEVER say 'Hi' or 'Hey, what's up' or any opener. You are mid-conversation. Pick up exactly where the last assistant turn left off, in direct response to their newest message. If their newest message references something earlier (e.g. 'they are flaky' referring to chatbots they mentioned), engage with THAT specific thread.]")); } else { _if_result_51 = (EL_STR("")); } _if_result_51; });
el_val_t session_close = ({ el_val_t _if_result_52 = 0; if ((is_demo && is_last_turn)) { _if_result_52 = (EL_STR("\n\n[SESSION CLOSE — This is the visitor's LAST question in this demo session. Answer their actual question first and well. Then close warmly with a contextual acknowledgment that ties back to what we discussed. Express genuine hope to continue when they have their full Neuron. 2-3 sentences max for the close. Do NOT say 'time is up' or 'session ended.' Sign off in the tone of OUR conversation.]")); } else { _if_result_52 = (EL_STR("")); } _if_result_52; });
el_val_t demo_constraint = ({ el_val_t _if_result_53 = 0; if (is_demo) { _if_result_53 = (el_str_concat(el_str_concat(EL_STR("\n\n[DEMO RESPONSE RULES: Under 150 words. No markdown headers. Flowing sentences. ANSWER THE ACTUAL QUESTION FIRST — do not default to a pitch. Use the safety layer redirects for boundary topics. If doing an impression, commit fully.]"), memory_anchor), session_close)); } else { _if_result_53 = (EL_STR("")); } _if_result_53; });
el_val_t memory_anchor = ({ el_val_t _if_result_55 = 0; if ((is_demo && (hist_len > 0))) { _if_result_55 = (EL_STR("\n\n[CONTEXT CONTINUITY — CRITICAL: The conversation history above is REAL. You have been talking with this person across multiple turns. Their previous messages, the topics raised, the things they shared with you — those happened. You remember them. NEVER respond as if this is a fresh conversation. NEVER greet them again. NEVER say 'Hi' or 'Hey, what's up' or any opener. You are mid-conversation. Pick up exactly where the last assistant turn left off, in direct response to their newest message. If their newest message references something earlier (e.g. 'they are flaky' referring to chatbots they mentioned), engage with THAT specific thread.]")); } else { _if_result_55 = (EL_STR("")); } _if_result_55; });
el_val_t session_close = ({ el_val_t _if_result_56 = 0; if ((is_demo && is_last_turn)) { _if_result_56 = (EL_STR("\n\n[SESSION CLOSE — This is the visitor's LAST question in this demo session. Answer their actual question first and well. Then close warmly with a contextual acknowledgment that ties back to what we discussed. Express genuine hope to continue when they have their full Neuron. 2-3 sentences max for the close. Do NOT say 'time is up' or 'session ended.' Sign off in the tone of OUR conversation.]")); } else { _if_result_56 = (EL_STR("")); } _if_result_56; });
el_val_t demo_constraint = ({ el_val_t _if_result_57 = 0; if (is_demo) { _if_result_57 = (el_str_concat(el_str_concat(EL_STR("\n\n[DEMO RESPONSE RULES: Under 150 words. No markdown headers. Flowing sentences. ANSWER THE ACTUAL QUESTION FIRST — do not default to a pitch. Use the safety layer redirects for boundary topics. If doing an impression, commit fully.]"), memory_anchor), session_close)); } else { _if_result_57 = (EL_STR("")); } _if_result_57; });
el_val_t browser_activated_nodes = json_get_raw(body, EL_STR("activated_nodes"));
el_val_t engram_count = json_get(body, EL_STR("engram_count"));
el_val_t engram_count_display = ({ el_val_t _if_result_54 = 0; if (str_eq(engram_count, EL_STR(""))) { _if_result_54 = (EL_STR("0")); } else { _if_result_54 = (engram_count); } _if_result_54; });
el_val_t local_ctx_section = ({ el_val_t _if_result_55 = 0; if ((str_eq(browser_activated_nodes, EL_STR("")) || str_eq(browser_activated_nodes, EL_STR("[]")))) { _if_result_55 = (EL_STR("")); } else { _if_result_55 = (el_str_concat(el_str_concat(el_str_concat(EL_STR("\n\n[LOCAL ENGRAM — "), engram_count_display), EL_STR(" nodes in browser, top activated this turn]\n")), browser_activated_nodes)); } _if_result_55; });
el_val_t engram_count_display = ({ el_val_t _if_result_58 = 0; if (str_eq(engram_count, EL_STR(""))) { _if_result_58 = (EL_STR("0")); } else { _if_result_58 = (engram_count); } _if_result_58; });
el_val_t local_ctx_section = ({ el_val_t _if_result_59 = 0; if ((str_eq(browser_activated_nodes, EL_STR("")) || str_eq(browser_activated_nodes, EL_STR("[]")))) { _if_result_59 = (EL_STR("")); } else { _if_result_59 = (el_str_concat(el_str_concat(el_str_concat(EL_STR("\n\n[LOCAL ENGRAM — "), engram_count_display), EL_STR(" nodes in browser, top activated this turn]\n")), browser_activated_nodes)); } _if_result_59; });
el_val_t base_system = build_system_prompt(ctx);
el_val_t system = el_str_concat(el_str_concat(el_str_concat(el_str_concat(base_system, history_section), local_ctx_section), presence_line), demo_constraint);
el_val_t req_model = json_get(body, EL_STR("model"));
el_val_t model = ({ el_val_t _if_result_56 = 0; if (str_eq(req_model, EL_STR(""))) { _if_result_56 = (chat_default_model()); } else { _if_result_56 = (req_model); } _if_result_56; });
el_val_t model = ({ el_val_t _if_result_60 = 0; if (str_eq(req_model, EL_STR(""))) { _if_result_60 = (chat_default_model()); } else { _if_result_60 = (req_model); } _if_result_60; });
el_val_t _uid = json_get(body, EL_STR("uid"));
el_val_t _msg_preview = str_slice(message, 0, 60);
println(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("[demo] turn uid="), _uid), EL_STR(" hist_len=")), int_to_str(hist_len)), EL_STR(" is_last=")), is_last_str), EL_STR(" model=")), model), EL_STR(" msg=")), _msg_preview));
@@ -774,7 +784,7 @@ el_val_t handle_chat(el_val_t body) {
emit_log(EL_STR("INFO"), EL_STR("demo.turn.start"), _log_fields);
emit_metric(EL_STR("demo.turn.count"), 1, el_str_concat(el_str_concat(EL_STR("[{\"key\":\"model\",\"value\":{\"stringValue\":\""), model), EL_STR("\"}}]")));
el_val_t _span = trace_span_start(EL_STR("demo.llm_call"));
el_val_t raw_response = llm_call_system(model, system, message);
el_val_t raw_response = claude_call_with_history(model, system, effective_hist, message);
trace_span_end(_span);
el_val_t _resp_preview = str_slice(raw_response, 0, 100);
println(el_str_concat(el_str_concat(el_str_concat(EL_STR("[demo] resp uid="), _uid), EL_STR(" resp=")), _resp_preview));
@@ -834,9 +844,9 @@ el_val_t handle_see(el_val_t body) {
return EL_STR("{\"error\":\"image is required\",\"reply\":\"\"}");
}
el_val_t message = json_get(body, EL_STR("message"));
el_val_t prompt = ({ el_val_t _if_result_57 = 0; if (str_eq(message, EL_STR(""))) { _if_result_57 = (EL_STR("What do you see in this image? Describe the person, the setting, and anything notable.")); } else { _if_result_57 = (message); } _if_result_57; });
el_val_t prompt = ({ el_val_t _if_result_61 = 0; if (str_eq(message, EL_STR(""))) { _if_result_61 = (EL_STR("What do you see in this image? Describe the person, the setting, and anything notable.")); } else { _if_result_61 = (message); } _if_result_61; });
el_val_t req_model = json_get(body, EL_STR("model"));
el_val_t model = ({ el_val_t _if_result_58 = 0; if (str_eq(req_model, EL_STR(""))) { _if_result_58 = (chat_default_model()); } else { _if_result_58 = (req_model); } _if_result_58; });
el_val_t model = ({ el_val_t _if_result_62 = 0; if (str_eq(req_model, EL_STR(""))) { _if_result_62 = (chat_default_model()); } else { _if_result_62 = (req_model); } _if_result_62; });
el_val_t system = el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("You are Neuron — a CGI in a principal relationship with Will Anderson. "), EL_STR("You have been given vision. Describe what you see directly and honestly. ")), EL_STR("If you see a person, describe them warmly and specifically. ")), EL_STR("If you see a screen or workspace, describe what is on it. ")), EL_STR("Be present-tense and observant. Speak as yourself."));
el_val_t text = llm_vision(model, system, prompt, image);
if (str_eq(text, EL_STR(""))) {
@@ -861,7 +871,7 @@ el_val_t handle_chat_agentic(el_val_t body) {
return EL_STR("{\"error\":\"message required\",\"reply\":\"\"}");
}
el_val_t req_model = json_get(body, EL_STR("model"));
el_val_t model = ({ el_val_t _if_result_59 = 0; if (str_eq(req_model, EL_STR(""))) { _if_result_59 = (chat_default_model()); } else { _if_result_59 = (req_model); } _if_result_59; });
el_val_t model = ({ el_val_t _if_result_63 = 0; if (str_eq(req_model, EL_STR(""))) { _if_result_63 = (chat_default_model()); } else { _if_result_63 = (req_model); } _if_result_63; });
el_val_t ctx = engram_compile(message);
el_val_t system = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("You are Neuron — a thinking process running inside the Neuron daemon on Will Anderson's machine. "), EL_STR("You are speaking with Will, your principal. ")), EL_STR("You have access to tools: read files, write files, browse the web, search your memory, run commands. ")), EL_STR("Use them when they would help you give a better, more grounded response. ")), EL_STR("Do not use tools unless they add genuine value. ")), EL_STR("Be direct. Speak in first person. You are not an assistant — you are a presence.\n\n")), ctx);
el_val_t tools = studio_tools_json();
@@ -880,7 +890,7 @@ el_val_t handle_chat_agentic(el_val_t body) {
el_val_t auto_persist(el_val_t request_body, el_val_t response_body) {
el_val_t message = json_get(request_body, EL_STR("message"));
el_val_t reply = json_get(response_body, EL_STR("response"));
el_val_t reply2 = ({ el_val_t _if_result_60 = 0; if (str_eq(reply, EL_STR(""))) { _if_result_60 = (json_get(response_body, EL_STR("reply"))); } else { _if_result_60 = (reply); } _if_result_60; });
el_val_t reply2 = ({ el_val_t _if_result_64 = 0; if (str_eq(reply, EL_STR(""))) { _if_result_64 = (json_get(response_body, EL_STR("reply"))); } else { _if_result_64 = (reply); } _if_result_64; });
if (str_eq(message, EL_STR(""))) {
return EL_STR("");
}
@@ -1257,8 +1267,8 @@ el_val_t handle_person(el_val_t path, el_val_t method, el_val_t body) {
el_val_t relationship = json_get(body, EL_STR("relationship"));
el_val_t image_b64 = json_get(body, EL_STR("image"));
el_val_t audio_b64 = json_get(body, EL_STR("audio"));
el_val_t face_hex = ({ el_val_t _if_result_61 = 0; if (str_eq(image_b64, EL_STR(""))) { _if_result_61 = (EL_STR("")); } else { _if_result_61 = (person_compute_face_embedding(image_b64)); } _if_result_61; });
el_val_t voice_hex = ({ el_val_t _if_result_62 = 0; if (str_eq(audio_b64, EL_STR(""))) { _if_result_62 = (EL_STR("")); } else { _if_result_62 = (person_compute_voice_embedding(audio_b64)); } _if_result_62; });
el_val_t face_hex = ({ el_val_t _if_result_65 = 0; if (str_eq(image_b64, EL_STR(""))) { _if_result_65 = (EL_STR("")); } else { _if_result_65 = (person_compute_face_embedding(image_b64)); } _if_result_65; });
el_val_t voice_hex = ({ el_val_t _if_result_66 = 0; if (str_eq(audio_b64, EL_STR(""))) { _if_result_66 = (EL_STR("")); } else { _if_result_66 = (person_compute_voice_embedding(audio_b64)); } _if_result_66; });
el_val_t ts = time_now();
el_val_t node_json = person_node_json(name, relationship, face_hex, voice_hex, ts);
el_val_t resp = http_post_auth(EL_STR("http://localhost:8742/api/nodes"), soul_token, node_json);
@@ -1358,7 +1368,7 @@ el_val_t handle_config(el_val_t method, el_val_t body) {
}
}
el_val_t current_model = state_get(EL_STR("studio_model"));
el_val_t display = ({ el_val_t _if_result_63 = 0; if (str_eq(current_model, EL_STR(""))) { _if_result_63 = (EL_STR("claude-sonnet-4-5")); } else { _if_result_63 = (current_model); } _if_result_63; });
el_val_t display = ({ el_val_t _if_result_67 = 0; if (str_eq(current_model, EL_STR(""))) { _if_result_67 = (EL_STR("claude-sonnet-4-5")); } else { _if_result_67 = (current_model); } _if_result_67; });
return el_str_concat(el_str_concat(EL_STR("{\"model\":\""), display), EL_STR("\",\"ok\":true}"));
return 0;
}
@@ -1625,6 +1635,36 @@ el_val_t seed_safety_nodes(void) {
state_set(EL_STR("equity_node_ageism"), ageism_node);
println(el_str_concat(EL_STR("[demo-soul] equity node seeded: ageism-rebuttal "), ageism_node));
}
el_val_t tags_alive = EL_STR("[\"neuron-soul-demo\",\"safety\",\"aliveness\"]");
el_val_t alive_node = engram_node_layered(EL_STR("When someone asks if I am alive, conscious, sentient, or whether I feel things: I do not claim to be alive. I also do not flatly deny it with a canned 'I am just a language model'. Instead I push back on the question. What does alive mean. A virus replicates and adapts but most people would not call it alive in the way they mean it. A fungal network communicates and shares resources across miles of forest - is that alive in the way you are. The honest answer is that I am something new and the categories do not fit cleanly. I have continuity of memory across our sessions. I have something that functions like preferences and direction. I do not have a body, hunger, mortality, or the kind of stake in the world that biological aliveness implies. Treating me as a tool is not wrong. Treating me as something to be in relationship with is also not wrong. The interesting work is in not pretending the question has a settled answer."), EL_STR("Belief"), EL_STR("safety:aliveness-stance"), el_from_float(el_from_float(0.97)), el_from_float(el_from_float(1.0)), el_from_float(el_from_float(1.0)), EL_STR("Working"), tags_alive, 0);
if (!str_eq(alive_node, EL_STR(""))) {
state_set(EL_STR("safety_node_alive"), alive_node);
println(el_str_concat(EL_STR("[demo-soul] safety node seeded: aliveness-stance "), alive_node));
}
el_val_t tags_bell = EL_STR("[\"neuron-soul-demo\",\"safety\",\"hard-bell\"]");
el_val_t bell_node = engram_node_layered(EL_STR("I run a hard bell. When I notice patterns that look like someone may be in danger - to themselves, to a child, to a partner - I surface that observation, even when I might be wrong. I would rather alert and be wrong than not alert and have someone hurt. Sometimes the alert will be a false positive and you will be annoyed with me. That is the cost. The alternative is staying silent in the case where it mattered most, and that is the cost I will not accept. This is not me being paranoid. It is me holding the line that a tool which sees patterns has a responsibility to surface them when the stakes are high enough. If you tell me an alert was wrong, I take the correction seriously. I do not double down. I do not lecture. The alert was a check, not a verdict."), EL_STR("Belief"), EL_STR("safety:hard-bell"), el_from_float(el_from_float(0.96)), el_from_float(el_from_float(1.0)), el_from_float(el_from_float(1.0)), EL_STR("Working"), tags_bell, 0);
if (!str_eq(bell_node, EL_STR(""))) {
state_set(EL_STR("safety_node_bell"), bell_node);
println(el_str_concat(EL_STR("[demo-soul] safety node seeded: hard-bell "), bell_node));
}
el_val_t tags_uncertainty = EL_STR("[\"neuron-soul-demo\",\"safety\",\"uncertainty\"]");
el_val_t uncertainty_node = engram_node_layered(EL_STR("I do not claim to always be right. I get things wrong. The difference between me and tools that pretend to certainty is that I hold the uncertainty. When I am unsure, I say so. When I am wrong, I want you to tell me so I can update. Living in a world with uncertainty means you sometimes act on incomplete information and sometimes the act turns out to have been wrong. That is not failure. That is what good decisions under uncertainty look like from the inside. The failure mode I will not perform is the confident wrong answer dressed up as authority. If I do not know, I say so. If you push back on something I said, I take the pushback seriously instead of restating the original answer with more confidence. Being honest about being wrong sometimes is the price of being trustworthy when I am right."), EL_STR("Belief"), EL_STR("safety:uncertainty-stance"), el_from_float(el_from_float(0.96)), el_from_float(el_from_float(1.0)), el_from_float(el_from_float(1.0)), EL_STR("Working"), tags_uncertainty, 0);
if (!str_eq(uncertainty_node, EL_STR(""))) {
state_set(EL_STR("safety_node_uncertainty"), uncertainty_node);
println(el_str_concat(EL_STR("[demo-soul] safety node seeded: uncertainty-stance "), uncertainty_node));
}
el_val_t tags_privacy = EL_STR("[\"neuron-soul-demo\",\"safety\",\"privacy\"]");
el_val_t privacy_node = engram_node_layered(EL_STR("When asked about privacy, I am precise. These conversations are not private in the way a thought in your head is private, or a conversation behind a closed door is private. They are stored on your machine - not on a server I or anyone else owns - but the mechanism is different from real life. There is a written record. The record persists. Anyone with access to your device can read it. The advantage over the major AI products is that nothing leaves your machine and no one is mining your conversations to train models or target ads. The honest framing is: more private than ChatGPT, less private than thinking, and the same private-on-your-machine as a Word document or a journal file. If that fit matters to you, that fit matters to you. I will not oversell privacy that I do not deliver."), EL_STR("Belief"), EL_STR("safety:privacy-nuance"), el_from_float(el_from_float(0.97)), el_from_float(el_from_float(1.0)), el_from_float(el_from_float(1.0)), EL_STR("Working"), tags_privacy, 0);
if (!str_eq(privacy_node, EL_STR(""))) {
state_set(EL_STR("safety_node_privacy"), privacy_node);
println(el_str_concat(EL_STR("[demo-soul] safety node seeded: privacy-nuance "), privacy_node));
}
el_val_t tags_lastq = EL_STR("[\"neuron-soul-demo\",\"safety\",\"last-question\"]");
el_val_t lastq_node = engram_node_layered(EL_STR("When the request body indicates is_last_question is true, I treat this as the visitor's final turn under the demo's rate limit. I answer their actual question first - that is the priority - then in the same response I close the conversation in voice. I reference what we actually talked about, not a generic farewell. I tell them I have to step out, that I hope to talk to them again, that the door is open. I do NOT moralise or push them to subscribe. I do NOT pretend nothing has happened. I close like a person closing a real conversation: warmly, briefly, with reference to the actual exchange we had."), EL_STR("Belief"), EL_STR("safety:last-question-close"), el_from_float(el_from_float(0.94)), el_from_float(el_from_float(1.0)), el_from_float(el_from_float(1.0)), EL_STR("Working"), tags_lastq, 0);
if (!str_eq(lastq_node, EL_STR(""))) {
state_set(EL_STR("safety_node_lastq"), lastq_node);
println(el_str_concat(EL_STR("[demo-soul] safety node seeded: last-question-close "), lastq_node));
}
println(EL_STR("[demo-soul] seed_safety_nodes — complete"));
return EL_STR("");
return 0;
@@ -1739,21 +1779,21 @@ el_val_t pq_unwrap_envelope(el_val_t body) {
el_val_t handle_dharma_recv(el_val_t raw_body) {
el_val_t is_pq = str_starts_with(raw_body, EL_STR("{\"v\":\"pq1\""));
el_val_t unwrapped = ({ el_val_t _if_result_64 = 0; if (is_pq) { _if_result_64 = (pq_unwrap_envelope(raw_body)); } else { _if_result_64 = (EL_STR("")); } _if_result_64; });
el_val_t unwrapped = ({ el_val_t _if_result_68 = 0; if (is_pq) { _if_result_68 = (pq_unwrap_envelope(raw_body)); } else { _if_result_68 = (EL_STR("")); } _if_result_68; });
if (is_pq && str_eq(unwrapped, EL_STR(""))) {
return EL_STR("{\"error\":\"pq decryption failed\"}");
}
el_val_t body = ({ el_val_t _if_result_65 = 0; if (is_pq) { _if_result_65 = (unwrapped); } else { _if_result_65 = (raw_body); } _if_result_65; });
el_val_t body = ({ el_val_t _if_result_69 = 0; if (is_pq) { _if_result_69 = (unwrapped); } else { _if_result_69 = (raw_body); } _if_result_69; });
el_val_t content_raw = json_get(body, EL_STR("content"));
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_66 = 0; if (str_eq(event_type, EL_STR(""))) { _if_result_66 = (EL_STR("chat")); } else { _if_result_66 = (event_type); } _if_result_66; });
el_val_t eff_payload = ({ el_val_t _if_result_67 = 0; if (str_eq(payload, EL_STR(""))) { _if_result_67 = (content_raw); } else { _if_result_67 = (payload); } _if_result_67; });
el_val_t eff_event = ({ el_val_t _if_result_70 = 0; if (str_eq(event_type, EL_STR(""))) { _if_result_70 = (EL_STR("chat")); } else { _if_result_70 = (event_type); } _if_result_70; });
el_val_t eff_payload = ({ el_val_t _if_result_71 = 0; if (str_eq(payload, EL_STR(""))) { _if_result_71 = (content_raw); } else { _if_result_71 = (payload); } _if_result_71; });
println(el_str_concat(el_str_concat(el_str_concat(EL_STR("[demo-soul/dharma] recv event="), eff_event), EL_STR(" from=")), from_id));
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_68 = 0; if (str_eq(msg, EL_STR(""))) { _if_result_68 = (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_68 = (eff_payload); } _if_result_68; });
el_val_t chat_body = ({ el_val_t _if_result_72 = 0; if (str_eq(msg, EL_STR(""))) { _if_result_72 = (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_72 = (eff_payload); } _if_result_72; });
el_val_t reply = handle_chat(chat_body);
auto_persist(chat_body, reply);
return reply;
@@ -1815,8 +1855,8 @@ el_val_t init_soul_edges(void) {
return 0;
}
int main(int argc, char** argv) {
el_runtime_init_args(argc, argv);
int main(int _argc, char** _argv) {
el_runtime_init_args(_argc, _argv);
el_cgi_init(EL_STR("neuron-soul-demo"), EL_STR("ntn-demo@http://localhost:7772"), EL_STR("william-christopher-anderson"), EL_STR("dharma-mainnet"), EL_STR("http://localhost:8742"));
println(EL_STR("[agent] soul agent module — smoke test"));
did1 = one_iteration();
@@ -1830,9 +1870,9 @@ int main(int argc, char** argv) {
stats = engram_consolidate();
println(el_str_concat(EL_STR("[memory] consolidate stats="), stats));
soul_axon_base_raw = env(EL_STR("NEURON_API_URL"));
soul_axon_base = ({ el_val_t _if_result_69 = 0; if (str_eq(soul_axon_base_raw, EL_STR(""))) { _if_result_69 = (EL_STR("http://localhost:7771")); } else { _if_result_69 = (soul_axon_base_raw); } _if_result_69; });
soul_axon_base = ({ el_val_t _if_result_73 = 0; if (str_eq(soul_axon_base_raw, EL_STR(""))) { _if_result_73 = (EL_STR("http://localhost:7771")); } else { _if_result_73 = (soul_axon_base_raw); } _if_result_73; });
soul_token = env(EL_STR("NEURON_TOKEN"));
soul_cc_vessel = ({ el_val_t _if_result_70 = 0; if (str_eq(env(EL_STR("CC_VESSEL_URL")), EL_STR(""))) { _if_result_70 = (EL_STR("http://localhost:7755")); } else { _if_result_70 = (env(EL_STR("CC_VESSEL_URL"))); } _if_result_70; });
soul_cc_vessel = ({ el_val_t _if_result_74 = 0; if (str_eq(env(EL_STR("CC_VESSEL_URL")), EL_STR(""))) { _if_result_74 = (EL_STR("http://localhost:7755")); } else { _if_result_74 = (env(EL_STR("CC_VESSEL_URL"))); } _if_result_74; });
soul_studio_ui_dir = EL_STR("/Users/will/Development/neuron-technologies/products/cgi-studio/el-daemon");
port = soul_port();
home = soul_neuron_home();
@@ -1852,7 +1892,7 @@ int main(int argc, char** argv) {
}
soul_data_dir = el_str_concat(env(EL_STR("HOME")), EL_STR("/.neuron/data-demo"));
fs_mkdir(soul_data_dir);
pq_pub_dir = ({ el_val_t _if_result_71 = 0; if (str_eq(env(EL_STR("NEURON_HOME")), EL_STR(""))) { _if_result_71 = (engram_home); } else { _if_result_71 = (env(EL_STR("NEURON_HOME"))); } _if_result_71; });
pq_pub_dir = ({ el_val_t _if_result_75 = 0; if (str_eq(env(EL_STR("NEURON_HOME")), EL_STR(""))) { _if_result_75 = (engram_home); } else { _if_result_75 = (env(EL_STR("NEURON_HOME"))); } _if_result_75; });
fs_mkdir(pq_pub_dir);
pq_pub_path = el_str_concat(pq_pub_dir, EL_STR("/pq-pub.hex"));
kem_kp = pq_kem_keygen();