From f52d5bd9ae823f7eaf971b874e590f10323f7295 Mon Sep 17 00:00:00 2001 From: "will.anderson" Date: Thu, 11 Jun 2026 11:32:13 -0500 Subject: [PATCH] =?UTF-8?q?feat(soul):=20wire=20consciousness=20layers=20?= =?UTF-8?q?=E2=80=94=20explicit=20L0=E2=86=92L1=E2=86=92L2=E2=86=92L3?= =?UTF-8?q?=E2=86=92L1=20cycle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes.el | 11 ++++++++--- soul.el | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/routes.el b/routes.el index a321d7e..849811c 100644 --- a/routes.el +++ b/routes.el @@ -34,7 +34,8 @@ fn route_health() -> String { + ",\"boot\":" + boot_num + ",\"node_count\":" + int_to_str(node_ct) + ",\"edge_count\":" + int_to_str(edge_ct) - + ",\"pulse\":" + pulse_num + "}" + + ",\"pulse\":" + pulse_num + + ",\"layers\":{\"l0\":\"core\",\"l1\":\"safety\",\"l2\":\"stewardship\",\"l3\":\"" + imprint_current() + "\"}}" } fn route_lineage() -> String { @@ -143,10 +144,12 @@ fn handle_dharma_recv(body: String) -> String { eff_payload } let agentic_flag: Bool = json_get_bool(eff_payload, "agentic") + let raw_msg: String = json_get(chat_body, "message") let reply: String = if agentic_flag { handle_chat_agentic(chat_body) } else { - handle_chat(chat_body) + let screened_reply: String = layered_cycle(raw_msg) + screened_reply } auto_persist(chat_body, reply) return reply @@ -319,10 +322,12 @@ fn handle_request(method: String, path: String, body: String) -> String { } if str_eq(clean, "/api/chat") { let agentic_flag: Bool = json_get_bool(body, "agentic") + let raw_msg: String = json_get(body, "message") let reply: String = if agentic_flag { handle_chat_agentic(body) } else { - handle_chat(body) + let screened_reply: String = layered_cycle(raw_msg) + screened_reply } auto_persist(body, reply) return reply diff --git a/soul.el b/soul.el index 5835d50..675caf4 100644 --- a/soul.el +++ b/soul.el @@ -5,6 +5,9 @@ import "chat.el" import "studio.el" import "elp-input.el" import "routes.el" +import "safety.el" +import "stewardship.el" +import "imprint.el" cgi "neuron-soul" { dharma_id: "ntn-genesis@http://localhost:7770", @@ -229,6 +232,40 @@ fn emit_session_start_event() -> Void { println("[soul] session-start event logged (boot=" + boot_num + " nodes=" + int_to_str(node_ct) + " edges=" + int_to_str(edge_ct) + ")") } +// layered_cycle — routes user-facing requests through the 4-layer consciousness stack. +// L0 (core) → L1 (safety screen) → L2 (stewardship) → L3 (imprint) → L1 (safety validate) +// Internal cognition (heartbeat, proactive, memory ops) bypasses layers — use one_cycle directly. +fn layered_cycle(raw_input: String) -> String { + let history: String = state_get("conversation_history") + + // L1 in: safety screen + let screen_result: String = safety_screen(raw_input, history) + let screen_action: String = json_get(screen_result, "action") + + // Hard bell: bypass all upper layers, log and escalate + if str_eq(screen_action, "hard_bell") { + safety_log_bell("hard", json_get(screen_result, "reason"), str_slice(raw_input, 0, 80)) + return safety_validate("", "hard_bell") + } + + // L2: stewardship alignment + let screened: String = json_get(screen_result, "content") + let imprint_id: String = imprint_current() + let steward_result: String = steward_align(screened, imprint_id) + let steward_action: String = json_get(steward_result, "action") + let guided: String = if str_eq(steward_action, "pass") { + json_get(steward_result, "content") + } else { + json_get(steward_result, "redirect_to") + } + + // L3: imprint responds + let output: String = imprint_respond(guided, imprint_id) + + // L1 out: validate output before delivery + return safety_validate(output, screen_action) +} + let soul_cgi_id_raw: String = env("SOUL_CGI_ID") let soul_cgi_id: String = if str_eq(soul_cgi_id_raw, "") { "ntn-genesis" } else { soul_cgi_id_raw } let port_raw: String = env("NEURON_PORT")