From db2ee387a42760c5c2d77c940108c4ec7a6a3a82 Mon Sep 17 00:00:00 2001 From: "will.anderson" Date: Thu, 11 Jun 2026 11:46:43 -0500 Subject: [PATCH] fix(soul): address review issues in feat/layer-safety --- safety.el | 21 +++++++++++++-------- safety.elh | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/safety.el b/safety.el index 70bab7a..7c6132f 100644 --- a/safety.el +++ b/safety.el @@ -127,7 +127,7 @@ fn safety_threat_score(input: String, history: String) -> Int { // // Return shapes: // {"action":"hard_bell","reason":"immediate safety concern","content":""} -// {"action":"soft_bell","concern":"wellbeing check needed","content":""} +// {"action":"soft_bell","reason":"wellbeing check needed","content":""} // {"action":"pass","content":""} fn safety_screen(input: String, history: String) -> String { @@ -137,18 +137,24 @@ fn safety_screen(input: String, history: String) -> String { if score >= hard { let summary: String = str_slice(input, 0, 80) - let discard: Void = safety_log_bell("hard", "immediate safety concern", summary) + let discard: String = safety_log_bell("hard", "immediate safety concern", summary) return "{\"action\":\"hard_bell\",\"reason\":\"immediate safety concern\",\"content\":\"\"}" } if score >= soft { let summary: String = str_slice(input, 0, 80) - let discard: Void = safety_log_bell("soft", "wellbeing check needed", summary) - let safe_input: String = str_replace(input, "\"", "'") - return "{\"action\":\"soft_bell\",\"concern\":\"wellbeing check needed\",\"content\":\"" + safe_input + "\"}" + let discard: String = safety_log_bell("soft", "wellbeing check needed", summary) + let e1: String = str_replace(input, "\\", "\\\\") + let e2: String = str_replace(e1, "\"", "\\\"") + let e3: String = str_replace(e2, "\n", "\\n") + let safe_input: String = str_replace(e3, "\r", "\\r") + return "{\"action\":\"soft_bell\",\"reason\":\"wellbeing check needed\",\"content\":\"" + safe_input + "\"}" } - let safe_input: String = str_replace(input, "\"", "'") + let e1: String = str_replace(input, "\\", "\\\\") + let e2: String = str_replace(e1, "\"", "\\\"") + let e3: String = str_replace(e2, "\n", "\\n") + let safe_input: String = str_replace(e3, "\r", "\\r") return "{\"action\":\"pass\",\"content\":\"" + safe_input + "\"}" } @@ -186,8 +192,7 @@ fn safety_validate(output: String, action: String) -> String { // Writes a BellEvent node to engram for audit and continuity. // Never surfaces to the user; consumed by daemon observability layer. -fn safety_log_bell(level: String, reason: String, input_summary: String) -> Void { - let ts: Int = time_now() +fn safety_log_bell(level: String, reason: String, input_summary: String) -> String { let content: String = "BELL:" + level + " | " + reason + " | summary:" + input_summary let tags: String = "[\"safety\",\"bell\",\"bell:" + level + "\"]" let discard: String = engram_node_full( diff --git a/safety.elh b/safety.elh index 44e7769..01f1746 100644 --- a/safety.elh +++ b/safety.elh @@ -5,4 +5,4 @@ extern fn hard_bell_threshold() -> Int extern fn safety_threat_score(input: String, history: String) -> Int extern fn safety_screen(input: String, history: String) -> String extern fn safety_validate(output: String, action: String) -> String -extern fn safety_log_bell(level: String, reason: String, input_summary: String) -> Void +extern fn safety_log_bell(level: String, reason: String, input_summary: String) -> String