Files
neuron/safety.el
T
will.anderson bebf1f8c86
Neuron Soul CI / build (pull_request) Failing after 6m5s
fix(soul): address review issues in feat/layer-composition
- Add stub implementations of safety.el, stewardship.el, and imprint.el
  with their .elh headers so the branch compiles without the dependency
  branches (feat/layer-safety, feat/layer-stewardship, feat/layer-imprint).
  Each stub documents the layer contract it must satisfy when replaced.

- Fix GET /api/chat bypass: update the GET branch in handle_request to
  call layered_cycle() consistently with the POST branch, rather than
  calling handle_chat() directly and skipping the consciousness stack.

- Export layered_cycle() from soul.elh (and dist/soul.elh) so routes.el
  can resolve the symbol via the header import.

- Fix steward_action else branch: add explicit handling for "block"
  (returns safe refusal immediately, skips L3) and "redirect" (uses
  redirect_to field). Unknown actions now log a warning and fall back to
  the screened input rather than silently passing an empty string to
  imprint_respond().

- Document hard_bell path: clarify that omitting auto_persist/history
  update is intentional security isolation, and document the safety_validate
  second-param sentinel contract ("hard_bell" vs screen_action).
2026-06-11 11:47:45 -05:00

34 lines
1.7 KiB
EmacsLisp

// safety.el L1 Safety layer (stub full implementation in feat/layer-safety)
// Provides safety screening and validation for the consciousness stack.
// This stub allows soul.el to compile while feat/layer-safety is pending merge.
//
// Contract for safety_screen(input, history) -> String (JSON):
// {"action": "pass" | "hard_bell", "content": "<screened input>", "reason": "<if hard_bell>"}
//
// Contract for safety_validate(output, screen_action) -> String:
// Second param is the original screen_action ("pass") or the sentinel "hard_bell".
// Returns the validated output string, or a safe refusal if validation fails.
//
// Contract for safety_log_bell(severity, reason, excerpt) -> Void:
// Logs a bell event to engram. severity = "hard" | "soft". Hard bell events are
// intentionally NOT added to conversation_history (security isolation by design).
fn safety_screen(input: String, history: String) -> String {
return "{\"action\":\"pass\",\"content\":\"" + json_safe(input) + "\"}"
}
fn safety_validate(output: String, screen_action: String) -> String {
return output
}
fn safety_log_bell(severity: String, reason: String, excerpt: String) -> Void {
let tags: String = "[\"safety\",\"bell\",\"" + severity + "-bell\"]"
let payload: String = "{\"severity\":\"" + severity + "\",\"reason\":\"" + json_safe(reason) + "\",\"excerpt\":\"" + json_safe(excerpt) + "\"}"
let discard: String = engram_node_full(
payload, "InternalStateEvent", "safety:bell",
el_from_float(0.95), el_from_float(0.95), el_from_float(1.0),
"Episodic", tags
)
println("[safety] bell logged severity=" + severity + " reason=" + reason)
}