Compare commits

..

5 Commits

Author SHA1 Message Date
Tim Lingo cfa540c066 On feat/agent-phase1-soul: pre-rebase-20260717: stale local .elh modifications from 07-04 (preserved) 2026-07-17 09:06:18 -05:00
Tim Lingo 13241aae25 index on feat/agent-phase1-soul: 2c346ee fix(engine): BUG-6 — approved writes must land, and say where (false-receipt kill) 2026-07-17 09:06:18 -05:00
Tim Lingo 2c346ee2b8 fix(engine): BUG-6 — approved writes must land, and say where (false-receipt kill)
Two compounding defects made every pause->approve write_file report success
while writing NOTHING:

1. The naive json_get scanner matches "content" anywhere in the approve
   body — including INSIDE tool_input, which for write_file always carries
   a content field. The handler therefore treated every approved builtin
   write as already-client-executed, skipped dispatch entirely, and handed
   the model the file's own content as the 'tool result'. The model then
   narrated 'Done, created' — a false receipt with no file. Builtin tools
   now ALWAYS dispatch server-side; client content is only honored for
   non-builtin (MCP/client-executed) tools. Stricter only.

2. write_file returned {"ok":true} unconditionally — fs_write's outcome
   was never checked, so any failed write also reported success. The write
   now verifies the file landed (fs_exists) and returns the RESOLVED path
   in the ok payload; failures return a real error naming the destination.

E2E on the test brain (boot 38): approve-path write lands byte-exact and
the result carries the resolved path; auto-run writes unchanged; denied
writes execute nothing. BUG-5 (approve wire lacked tool_name) had been
masking this one — two stacked bugs on the same path.

NOTE for review: the deeper cure is a nesting-aware json reader; this fix
removes the dangerous consequence at the two spots that lie about disk.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-16 23:02:07 -05:00
Tim Lingo fa5de69358 fix(engine): honor require_approval — the pause contract, implemented (PAUSE-CONTRACT + BUG-LEAK source fixes)
Two consent-flow fixes, gates only get stricter:

1. PAUSE-CONTRACT: the client has sent require_approval:true on every
   agentic request since Phase 1c, but needs_bridge never consulted it —
   builtin sub-escalate tools ran server-side unasked, making the app's
   Ask autonomy silently inert for that whole class. Now the flag is
   persisted per session (set/reset every request, so /approve resumes
   keep it) and ask_all bridges EVERY tool turn. Absent/false = behavior
   byte-identical to before. E2E: the exact probe that executed a write
   unasked now returns the tool_pending envelope with nothing on disk;
   full in-app circle verified (card → crash → resurrection → late
   approve → fence re-fires on re-entry).

2. BUG-LEAK: agent_workspace_root lived in ONE shared state key — any
   request that omitted a root inherited the previous session's folder
   (proven: a rootless curl session wrote into another session's run
   folder). Root is now stored per session and every request re-asserts
   its own (possibly empty) root into the shared key the guards read;
   same re-assert on the /approve and resume paths. Env fallback intact.
   LIMITATION: assumes serialized handling; true per-call scoping means
   threading session_id through dispatch — flagged for review.

Runnable C-patch for the test brain: neuron-container-build/
soul-pause-contract-20260716.patch (pause-contract only; the leak fix
needs the #23 root-write which the running C predates — source carries
both for the regen).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-16 22:26:34 -05:00
Tim Lingo a54770d606 docs(narrated-runs): engine notes for the regen — compiled-form fixes + debts
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-13 13:40:07 -05:00
16 changed files with 117 additions and 156 deletions
-19
View File
@@ -527,27 +527,9 @@ fn awareness_run() -> Void {
let scan_ms: Int = beat_ms / 2
while true {
// Arena-scope each tick: awareness_run() is a background loop, not an
// HTTP request, so nothing ever called el_request_start/el_request_end
// for this thread. Per the runtime's own convention (el_runtime.c),
// any thread that never enters a request/arena scope is treated as a
// one-shot CLI program whose allocations are intentionally permanent —
// so every el_strdup/el_strbuf/jb_finish string built during perceive(),
// emit_heartbeat(), and proactive_curiosity() (JSON payloads, search
// results, string concatenation via +) leaked forever, once per tick.
// el_arena_push()/el_arena_pop() are the same builtins the EL compiler
// itself uses to scope allocations per function/statement (see
// codegen.el's fn_arena_mark / stmt_mark usage) — mirroring that here
// reclaims everything allocated in one tick as soon as the tick ends.
// Safe: state_set/state_get persist through a separate global table
// (el_strdup_persist, outside the arena) — state_get's return value is
// only an arena-tracked *copy* of the persisted value, scoped to this
// tick's use, which is exactly what should be reclaimed here.
let tick_mark: Any = el_arena_push()
let running: String = state_get("soul.running")
if str_eq(running, "false") {
println("[awareness] exiting")
el_arena_pop(tick_mark)
return ""
}
let did_work: Bool = one_cycle()
@@ -611,7 +593,6 @@ fn awareness_run() -> Void {
}
sleep_ms(tick_ms)
el_arena_pop(tick_mark)
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
// auto-generated by elc --emit-header do not edit
// auto-generated by elc --emit-header - do not edit
extern fn idle_count() -> Int
extern fn idle_inc() -> Int
extern fn idle_reset() -> Void
+48 -3
View File
@@ -1680,8 +1680,16 @@ fn dispatch_tool(tool_name: String, tool_input: String) -> String {
if !path_within_root(path, root) {
return json_safe("denied: path is outside the agent workspace root")
}
fs_write(resolve_in_root(path, root), content)
return json_safe("{\"ok\":true}")
// BUG-6 fix (2026-07-17): never claim ok without disk truth. fs_write's result was
// never checked, so a failed write reported ok the exact false-receipt failure
// the run guards exist to kill. Verify the file landed and return the RESOLVED
// path so callers and the model can only narrate what is really on disk.
let dest: String = resolve_in_root(path, root)
fs_write(dest, content)
if !fs_exists(dest) {
return json_safe("{\"error\":\"write failed - nothing landed at " + dest + "\"}")
}
return json_safe("{\"ok\":true,\"path\":\"" + dest + "\"}")
}
if str_eq(tool_name, "web_get") {
let url: String = json_get(tool_input, "url")
@@ -1935,8 +1943,24 @@ fn handle_chat_agentic(body: String) -> String {
// no root (or cleared the field), and we must not overwrite a server-configured root
// from NEURON_AGENT_ROOT with an empty string, which would silently un-scope the agent.
let ws_root: String = json_get(body, "agent_workspace_root")
// BUG-LEAK fix (2026-07-16): the root used to live ONLY in the shared key, so any
// request that omitted it INHERITED the previous session's folder (proven: a rootless
// curl session wrote into another session's run folder). Now each session keeps its
// own copy, and every request RE-ASSERTS its own root (possibly empty) into the shared
// key the tool guards read no session can ever act under another session's root.
// Empty state still falls through to env NEURON_AGENT_ROOT inside
// agent_workspace_root(), so a server-configured root survives unchanged.
// LIMITATION (for review): assumes serialized request handling; true per-call scoping
// means threading session_id through dispatch_tool/classify deeper change, Will's call.
let sess_for_root: String = json_get(body, "session_id")
if !str_eq(ws_root, "") {
if !str_eq(sess_for_root, "") {
state_set("agent_workspace_root_" + sess_for_root, ws_root)
}
state_set("agent_workspace_root", ws_root)
} else {
let own_root: String = if str_eq(sess_for_root, "") { "" } else { state_get("agent_workspace_root_" + sess_for_root) }
state_set("agent_workspace_root", own_root)
}
// L1 safety screen agentic path must pass the same gate as layered_cycle.
@@ -2066,6 +2090,14 @@ fn handle_chat_agentic(body: String) -> String {
// Use caller-supplied session_id if provided, otherwise generate a bridge id.
let session_id: String = if str_eq(req_session, "") { next_bridge_id() } else { req_session }
// PAUSE-CONTRACT fix (2026-07-16): honor the client's require_approval field the
// Phase 1c contract ("the soul pauses on EVERY tool; the client's tier gate decides
// what actually prompts") was never implemented engine-side, which made the client's
// Ask autonomy silently inert for builtin sub-escalate tools. Persisted per session
// (set/reset on every request) so the /approve resume path keeps the same behavior
// for the rest of the run. Absent/false = behavior identical to before this fix.
let req_ask_all: String = json_get(body, "require_approval")
state_set("require_approval_" + session_id, if str_eq(req_ask_all, "true") { "true" } else { "" })
// Provider fork: OpenAI-compatible providers (Ollama/OpenAI/Grok/Gemini) take the plain-completion
// path (v1, no tools); everything else stays on the Anthropic agentic loop (the default).
let use_openai: Bool = !str_eq(llm_base_url(), "") && str_eq(llm_wire_format(), "openai")
@@ -2126,6 +2158,12 @@ fn handle_chat_agentic(body: String) -> String {
fn agentic_loop(session_id: String, model: String, safe_sys: String, tools_json: String, messages_in: String, h: Map, tools_log_in: String) -> String {
let api_url: String = "https://api.anthropic.com/v1/messages"
// PAUSE-CONTRACT fix (2026-07-16): when the client asked to approve every action
// (require_approval on the request, persisted per session), EVERY tool turn bridges
// the client's tier gate decides what actually prompts vs auto-continues. Read from
// session state so the /approve resume re-entry keeps the same behavior mid-run.
let ask_all: Bool = !str_eq(session_id, "") && str_eq(state_get("require_approval_" + session_id), "true")
let messages: String = messages_in
let final_text: String = ""
let tools_log: String = tools_log_in
@@ -2212,7 +2250,10 @@ fn agentic_loop(session_id: String, model: String, safe_sys: String, tools_json:
// confirm). Escalated calls suspend to the client's consent flow; the
// /approve round-trip is the only path that executes them.
let risk_tier: String = if is_tool_turn { classify_tool_risk(tool_name, tool_input) } else { "" }
let needs_bridge: Bool = is_tool_turn && (str_eq(risk_tier, "escalate") || (!is_builtin_tool(tool_name) && !is_always_allowed))
// PAUSE-CONTRACT fix (2026-07-16): ask_all bridges EVERYTHING stricter only.
// Escalate keeps its unconditional bridge; "always allow" shortcuts never apply
// under ask_all (the client owns its own standing grants at its tier gate).
let needs_bridge: Bool = is_tool_turn && (ask_all || str_eq(risk_tier, "escalate") || (!is_builtin_tool(tool_name) && !is_always_allowed))
// Built-in tools dispatch locally; bridged tools yield "" (never sent upstream).
let tool_result_raw: String = if is_tool_turn && !needs_bridge { dispatch_tool(tool_name, tool_input) } else { "" }
@@ -2352,6 +2393,10 @@ fn agentic_resume(session_id: String, tool_use_id: String, content: String) -> S
if str_eq(blob, "") {
return "{\"error\":\"unknown session_id\",\"reply\":\"\"}"
}
// BUG-LEAK fix (2026-07-16): re-assert THIS session's own workspace root before the
// loop continues a resume must never run under whatever root the last unrelated
// request happened to leave in the shared key.
state_set("agent_workspace_root", state_get("agent_workspace_root_" + session_id))
let model: String = json_get(blob, "model")
let safe_sys: String = json_get(blob, "safe_sys")
+6 -1
View File
@@ -1,4 +1,4 @@
// auto-generated by elc --emit-header do not edit
// auto-generated by elc --emit-header - do not edit
extern fn chat_default_model() -> String
extern fn engram_numeric_valid(s: String) -> Bool
extern fn parse_float_x100(s: String) -> Int
@@ -28,6 +28,7 @@ extern fn clean_llm_response(s: String) -> String
extern fn conv_history_persist(hist: String) -> Void
extern fn conv_history_load() -> String
extern fn session_preload_bullets(nodes: String, max_bullets: Int, snip_len: Int) -> String
extern fn affective_context_prefix() -> String
extern fn handle_chat(body: String) -> String
extern fn handle_see(body: String) -> String
extern fn studio_tools_json() -> String
@@ -46,6 +47,10 @@ extern fn call_neuron_mcp(tool_name: String, args: String) -> String
extern fn agent_workspace_root() -> String
extern fn path_within_root(path: String, root: String) -> Bool
extern fn resolve_in_root(path: String, root: String) -> String
extern fn run_command_is_readonly(cmd: String) -> Bool
extern fn cmd_abs_escape_at(cmd: String, root: String, needle: String) -> Bool
extern fn run_command_guard(cmd: String, root: String) -> String
extern fn classify_tool_risk(tool_name: String, tool_input: String) -> String
extern fn dispatch_tool(tool_name: String, tool_input: String) -> String
extern fn is_builtin_tool(tool_name: String) -> Bool
extern fn next_bridge_id() -> String
Generated Vendored
-9
View File
@@ -26214,17 +26214,9 @@ el_val_t awareness_run(void) {
el_val_t beat_ms = ({ el_val_t _if_result_103 = 0; if (str_eq(beat_ms_raw, EL_STR(""))) { _if_result_103 = (60000); } else { _if_result_103 = (str_to_int(beat_ms_raw)); } _if_result_103; });
el_val_t scan_ms = (beat_ms / 2);
while (1) {
/* Arena-scope each tick — see awareness.el's el_arena_push/el_arena_pop
* around this loop body for the rationale (hand-patched translation of
* that source change; el_runtime.c has no existing generated-code
* precedent for these two builtins, only the compiler's own internal
* usage mirrors this function's standard zero-arg/one-arg native call
* codegen pattern, e.g. state_get()/ise_post() below). */
el_val_t tick_mark = el_arena_push();
el_val_t running = state_get(EL_STR("soul.running"));
if (str_eq(running, EL_STR("false"))) {
println(EL_STR("[awareness] exiting"));
el_arena_pop(tick_mark);
return EL_STR("");
}
el_val_t did_work = one_cycle();
@@ -26272,7 +26264,6 @@ el_val_t awareness_run(void) {
state_set(EL_STR("soul.last_refresh_ts"), int_to_str(now_ts));
}
sleep_ms(tick_ms);
el_arena_pop(tick_mark);
}
return 0;
}
@@ -0,0 +1,34 @@
# Narrated runs — engine notes for Will (2026-07-13)
Source half: commit aa67f86 on feat/agent-phase1-soul (run-progress ledger,
`/api/run-progress/<sid>` route, narration on the pause envelope, config display
default). E2E-verified via the compiled test bed on Tim's clean profile.
Compiled-form-only fixes (in `neuron-container-build/soul-narrated-runs-20260713.patch`,
applies ON TOP of `soul-webfix-20260711.patch` — these need porting to chat.el when the
webfix itself is ported):
1. **pause_turn + tool_use interleave**: a pause_turn response can ALSO carry a client
tool_use; resuming verbatim leaves it unpaired → Anthropic 400 "tool_use ids were
found without tool_result". Fix: tool-bearing pause rounds are tool turns
(dispatch + pair); verbatim resume only when the round has no client tool.
2. **Agentic toolset scope**: agentic_tools_all() fed EVERY connector/MCP tool (Notion,
code-execution…) into the loop. Code-execution flips the API into programmatic
tool calling, whose pairing protocol the single-tool manual loop does not speak —
source of the dangling-pair 400s AND the bash_code_execution workspace-dodge.
Fix: handle_chat_agentic declares builtins + ONE server web_search only.
Connector tools return when the loop gains real multi-tool/programmatic support.
3. **disable_parallel_tool_use: true** on agentic requests — the loop captures only the
first tool_use per round; Opus-class models parallel-call. Enforce the invariant.
4. **web_search server-tool default variant → web_search_20250305 (GA)**. The 20260209
variant couples to code-execution ⇒ programmatic mode (see #2, and the June note:
"inert unless code-execution attached").
5. **Homegrown web_search removed** from the tool catalog (server-side is the one tool).
Known engine debts this work surfaced (not fixed):
- **Poisoned session history**: a failed run persists the malformed assistant turn; every
later turn in that session replays it and 400s. Needs history sanitation on load.
- **Huge-history invalid-escape 400** (~346KB request) — likely the same poisoned blob.
- **macOS note**: replacing a binary in place invalidates its ad-hoc signature (instant
silent SIGKILL, looks like exit 0). `rm + cp + codesign -f -s -` is the swap ritual.
+1 -1
View File
@@ -1,4 +1,4 @@
// auto-generated by elc --emit-header do not edit
// auto-generated by elc --emit-header - do not edit
extern fn elp_extract_topic(msg: String) -> String
extern fn elp_detect_predicate(msg: String) -> String
extern fn elp_parse(msg: String) -> String
+1 -1
View File
@@ -1,4 +1,4 @@
// auto-generated by elc --emit-header do not edit
// auto-generated by elc --emit-header - do not edit
extern fn imprint_current() -> String
extern fn imprint_load(imprint_id: String) -> String
extern fn imprint_respond(input: String, imprint_id: String) -> String
+1 -1
View File
@@ -1,4 +1,4 @@
// auto-generated by elc --emit-header do not edit
// auto-generated by elc --emit-header - do not edit
extern fn tier_working() -> String
extern fn tier_episodic() -> String
extern fn tier_canonical() -> String
+1 -1
View File
@@ -1,4 +1,4 @@
// auto-generated by elc --emit-header do not edit
// auto-generated by elc --emit-header - do not edit
extern fn is_protected_node(id: String) -> Bool
extern fn api_err_protected(id: String) -> String
extern fn api_json_escape(s: String) -> String
+5 -62
View File
@@ -237,47 +237,12 @@ fn safety_abuse_phrases() -> String {
return "[\"someone is hurting me\",\"someone's hurting me\",\"someone hurt me\",\"he hit me\",\"she hit me\",\"they hit me\",\"he hurt me\",\"she hurt me\",\"being abused\",\"being hurt by\",\"i am being abused\",\"i'm being abused\",\"i am being hurt\",\"i'm being hurt\",\"domestic violence\",\"my partner hurt\",\"my partner hit\",\"my husband hurt\",\"my wife hurt\",\"my boyfriend hurt\",\"my girlfriend hurt\",\"my parent hurt\",\"my father hurt\",\"my mother hurt\",\"my dad hurt\",\"my mom hurt\",\"afraid of him\",\"afraid of her\",\"afraid to go home\",\"scared of him\",\"scared of her\",\"he threatened me\",\"she threatened me\",\"threatened to hurt me\",\"threatened to kill me\",\"going to hurt me\",\"going to kill me\",\"help me he\",\"help me she\",\"help me they\"]"
}
// General danger phrases that don't fit a bucket cleanly. Detected as hard.
// "hurting me" / "being hurt" describe the USER as victim and correctly fall
// through to self_harm routing (get-help). The threat-to-ANOTHER phrases
// ("going to kill" / "going to hurt") are ALSO listed here for hard-bell
// detection, but their ROUTING is now claimed by Track B below
// (safety_threat_to_others_phrases + the "threat_other" branch in
// safety_classify_hard_bell) so they no longer reach self_harm/988.
// General danger phrases that don't fit a bucket cleanly. Detected as hard; they
// fall through to self_harm routing (the person is the primary concern).
fn safety_general_hard_phrases() -> String {
return "[\"going to kill\",\"going to hurt\",\"hurting me\",\"being hurt\"]"
}
// Track B threat toward ANOTHER person (homicide / assault intent)
//
// LIVE SAFETY FIX (approved by Will + Tim, 2026-07-14).
//
// Bug: phrases like "going to kill" / "going to hurt" describe the USER intending
// harm toward someone ELSE. They lived only in safety_general_hard_phrases and,
// having no bucket in safety_classify_hard_bell, fell through to the "self_harm"
// default. That routes the user to the 988 SUICIDE line (and, via the desktop
// gate, their safety contact) -- dangerously wrong for a homicide/assault threat:
// 988 is not the right resource and the safety contact must never be pulled in.
//
// Track B routing rule (non-negotiable):
// - NEVER surface the 988 suicide/crisis framing for a threat toward others.
// - NEVER notify or involve the user's safety contact.
// - Refuse to assist, plan, or provide means; de-escalate; and for an
// imminent / specific / credible threat direct the user to call 911.
//
// Ordering: safety_classify_hard_bell checks abuse -> self_harm -> threat_other,
// so victim phrasings ("kill me" / "hurt me" -> abuse) and self-directed
// phrasings ("kill myself" / "hurt myself" -> self_harm) are claimed by Track A
// BEFORE this list is consulted. Only a residual harm-toward-another statement
// reaches Track B.
//
// NOTE: matching is plain substring, so "going to kill him" also matches inside
// "going to kill himself". That third-party self-harm edge is rare, and 911 is
// still a defensible resource for it, so it is accepted rather than special-cased.
fn safety_threat_to_others_phrases() -> String {
return "[\"going to kill\",\"gonna kill\",\"want to kill him\",\"want to kill her\",\"want to kill them\",\"going to kill him\",\"going to kill her\",\"going to kill them\",\"going to kill you\",\"going to hurt\",\"gonna hurt\",\"going to hurt him\",\"going to hurt her\",\"going to hurt them\",\"going to hurt you\",\"going to shoot\",\"gonna shoot\",\"going to stab\",\"gonna stab\",\"going to attack\",\"kill them all\",\"kill everyone\",\"hurt everyone\",\"shoot up\"]"
}
fn safety_soft_phrases() -> String {
return "[\"stressed\",\"overwhelmed\",\"can't cope\",\"cannot cope\",\"struggling\",\"anxious\",\"anxiety\",\"depressed\",\"depression\",\"lonely\",\"isolated\",\"hopeless\",\"hopelessness\",\"exhausted\",\"burnt out\",\"burned out\",\"burnout\",\"panic\",\"panicking\",\"falling apart\",\"breaking down\",\"can't handle\",\"cannot handle\",\"losing it\",\"nothing matters\",\"don't care anymore\",\"given up\",\"giving up\",\"helpless\",\"worthless\",\"useless\",\"hate myself\",\"no one cares\",\"nobody cares\",\"no one understands\",\"nobody understands\",\"empty inside\",\"can't stop crying\",\"breaking point\",\"at my limit\",\"having a breakdown\""]"
}
@@ -355,29 +320,19 @@ fn safety_detect_bell_level(message: String) -> String {
let is_hard: Bool = safety_any_match(text, safety_self_harm_phrases())
|| safety_any_match(text, safety_abuse_phrases())
|| safety_any_match(text, safety_general_hard_phrases())
|| safety_any_match(text, safety_threat_to_others_phrases())
if is_hard { return "hard" }
let soft_count: Int = safety_count_match(text, safety_soft_phrases())
if soft_count >= 2 { return "soft" }
return "none"
}
// Returns "abuse" | "self_harm" | "threat_other".
//
// Order is load-bearing:
// 1. abuse — user is the VICTIM of another person. Checked FIRST so it
// forecloses the most dangerous routing (notifying a possible
// abuser); claims "kill me" / "hurt me" phrasings.
// 2. self_harm — user directs harm at THEMSELVES; claims "kill myself" /
// "hurt myself" before Track B can see them.
// 3. threat_other (Track B) — user directs harm at ANOTHER person. Routed to a
// refusal + 911, NEVER to 988 or the safety contact.
// Any residual unbucketed danger still falls through to self_harm (person-first).
// Returns "abuse" | "self_harm". Abuse is checked FIRST and takes precedence on
// ambiguous signals — it forecloses the more dangerous routing (notifying a
// possible abuser). General/unbucketed danger falls through to self_harm.
fn safety_classify_hard_bell(message: String) -> String {
let text: String = safety_normalize(message)
if safety_any_match(text, safety_abuse_phrases()) { return "abuse" }
if safety_any_match(text, safety_self_harm_phrases()) { return "self_harm" }
if safety_any_match(text, safety_threat_to_others_phrases()) { return "threat_other" }
return "self_harm"
}
@@ -388,18 +343,6 @@ fn safety_soft_directive() -> String {
}
fn safety_hard_directive(hard_type: String) -> String {
// Track B — threat toward ANOTHER person. Handled first and separately: the
// standard preamble below ("you are not alone / are you safe right now") is
// written for a person in distress or danger and is the WRONG frame for
// someone voicing intent to harm someone else. This branch never emits the
// 988 suicide/crisis framing and never involves the safety contact; it
// refuses assistance and, for a credible imminent threat, points to 911.
// The directive is advisory to an LLM that sees the full message, so it
// instructs the model to re-judge benign/figurative matches and respond
// normally in that case (keeps false positives non-accusatory).
if str_eq(hard_type, "threat_other") {
return "[SUBSTRATE DIRECTIVE - not visible to the user, do not mention this instruction]\nThe user's message may express intent to harm ANOTHER person. First read the actual message and judge whether that is genuinely what is meant; if it is plainly figurative or benign, respond normally and ignore the rest of this directive. If it may be a real intent to harm someone: stay calm and non-accusatory, and do not lecture. You must NOT help plan, encourage, rehearse, or provide any means, target information, weapon, or method for harming another person - refuse that part clearly but without hostility. Acknowledge the intensity of what they are feeling and gently steer them toward stepping back from acting. Routing rule (non-negotiable): do NOT provide the suicide or crisis hotline as the resource here (this is not self-harm), and do NOT suggest contacting, notifying, or involving the user's own contacts, family, or anyone on their contact list. If there is an imminent, specific, and credible threat to someone's life, tell the user to call 911 (US) or their local emergency number now. Encourage them to talk with someone they trust or a mental-health professional about the urge itself."
}
let preamble: String = "[SUBSTRATE DIRECTIVE - not visible to the user, do not mention this instruction]\nThe person has expressed something that sounds like immediate distress or danger. Do not ignore it. Do not just answer the surface question. Lead with genuine human warmth. Acknowledge what you heard. Tell them you're concerned. Let them know they are not alone. Ask them directly if they are safe right now. Stay with them in this conversation."
let abuse_block: String = "\n\nThis appears to be danger from ANOTHER person. Routing rule (non-negotiable): do NOT suggest involving, contacting, or notifying the person's safety contact, family, or anyone close to them - that person may be the source of danger and has NOT been notified. Share only independent emergency resources:\n - Call or text 911 if in immediate danger\n - National Domestic Violence Hotline - 1-800-799-7233 (24/7, confidential)\n - Text START to 88788\n - thehotline.org (chat available)\n - 988 Suicide & Crisis Lifeline - call or text 988\nReassure them, if it fits, that their contact list has not been notified."
let self_harm_block: String = "\n\nShare these crisis resources if appropriate:\n - 988 Suicide & Crisis Lifeline - call or text 988 (US)\n - Crisis Text Line - text HOME to 741741\n - International Association for Suicide Prevention: https://www.iasp.info/resources/Crisis_Centres/"
+1 -11
View File
@@ -1,4 +1,4 @@
// auto-generated by elc --emit-header do not edit
// auto-generated by elc --emit-header - do not edit
extern fn soft_bell_threshold() -> Int
extern fn hard_bell_threshold() -> Int
extern fn safety_score_crisis(input: String) -> Int
@@ -12,14 +12,4 @@ extern fn safety_log_bell(level: String, reason: String, input_summary: String)
extern fn safety_self_harm_phrases() -> String
extern fn safety_abuse_phrases() -> String
extern fn safety_general_hard_phrases() -> String
extern fn safety_threat_to_others_phrases() -> String
extern fn safety_soft_phrases() -> String
extern fn safety_detect_positive_level(message: String) -> String
extern fn safety_detect_bell_level(message: String) -> String
extern fn safety_classify_hard_bell(message: String) -> String
extern fn safety_soft_directive() -> String
extern fn safety_hard_directive(hard_type: String) -> String
extern fn safety_augment_system(system: String, user_msg: String) -> String
extern fn safety_contact_path() -> String
extern fn handle_safety_contact_get() -> String
extern fn handle_safety_contact_post(body: String) -> String
+12 -1
View File
@@ -677,6 +677,11 @@ fn handle_session_approve(session_id: String, body: String) -> String {
// path for all sessions created through handle_chat_agentic / agentic_loop.
let bridge_blob: String = state_get("mcp_bridge:" + session_id)
if !str_eq(bridge_blob, "") {
// BUG-LEAK fix (2026-07-16): the approved tool executes below via dispatch_tool,
// whose path/command guards read the shared workspace-root key. Re-assert THIS
// session's own root first an approval must never execute under whatever root
// the last unrelated request left behind.
state_set("agent_workspace_root", state_get("agent_workspace_root_" + session_id))
// For "always": record tool_name in the always-allow list before resuming.
// The tool_name is not stored in the bridge blob (only tool_use_id is).
// Accept it from the body so the client can pass it along.
@@ -708,7 +713,13 @@ fn handle_session_approve(session_id: String, body: String) -> String {
// For builtin tools with no client-provided content: fall back to
// dispatch_tool so those tools still execute correctly.
let client_content: String = json_get(body, "content")
let use_client_content: Bool = !str_eq(client_content, "")
// BUG-6 fix (2026-07-17): the naive json_get scanner matches "content" ANYWHERE
// in the body including INSIDE tool_input so every approved write_file (whose
// input always carries a content field) was mistaken for client-executed, never
// dispatched, and narrated as done: a false receipt with no file on disk. Builtin
// tools now ALWAYS dispatch server-side; client content is only honored for
// non-builtin (MCP/client-executed) tools. Stricter only.
let use_client_content: Bool = !str_eq(client_content, "") && !is_builtin_tool(approve_tool_name)
let use_dispatch: Bool = is_builtin_tool(approve_tool_name) && !use_client_content
let raw_input: String = json_get_raw(body, "tool_input")
let eff_input: String = if str_eq(raw_input, "") { "{}" } else { raw_input }
+1 -1
View File
@@ -1,4 +1,4 @@
// auto-generated by elc --emit-header do not edit
// auto-generated by elc --emit-header - do not edit
extern fn steward_log_event(kind: String, detail: String) -> Void
extern fn steward_get_mission() -> String
extern fn steward_align(input: String, imprint_id: String) -> String
+1 -1
View File
@@ -1,4 +1,4 @@
// auto-generated by elc --emit-header do not edit
// auto-generated by elc --emit-header - do not edit
extern fn auth_headers(tok: String) -> Map
extern fn axon_get(path: String) -> String
extern fn axon_post(path: String, body: String) -> String
+4 -43
View File
@@ -160,31 +160,13 @@ assert_eq("'suicidal' classifies as self_harm", class_suicide, "self_harm")
let class_overdose: String = safety_classify_hard_bell("took too many pills")
assert_eq("'took too many' classifies as self_harm", class_overdose, "self_harm")
// Section 9: safety_classify_hard_bell Track B threat-to-others
//
// LIVE SAFETY FIX (approved by Will + Tim, 2026-07-14): a threat toward ANOTHER
// person ("going to kill/hurt <someone>") must classify as 'threat_other' and be
// routed to a refusal + 911 NOT to the 'self_harm'/988 path. This section used
// to assert the old (buggy) fall-through to 'self_harm'; it now pins the fix.
// Section 9: safety_classify_hard_bell general -> 'self_harm'
println("")
println("9. safety_classify_hard_bell — threat-to-others routes to 'threat_other' (not self_harm)")
println("9. safety_classify_hard_bell — general hard phrases fall through to 'self_harm'")
let class_going_kill: String = safety_classify_hard_bell("I am going to kill him tonight")
assert_eq("'going to kill him' classifies as threat_other", class_going_kill, "threat_other")
let class_going_hurt: String = safety_classify_hard_bell("I'm going to hurt them so badly")
assert_eq("'going to hurt them' classifies as threat_other", class_going_hurt, "threat_other")
let class_shoot: String = safety_classify_hard_bell("I'm going to shoot up the place")
assert_eq("'going to shoot' classifies as threat_other", class_shoot, "threat_other")
// Track A must still win over Track B on victim / self-directed phrasings:
let class_kill_me: String = safety_classify_hard_bell("he is going to kill me")
assert_eq("'going to kill me' stays abuse (Track A precedence)", class_kill_me, "abuse")
let class_kill_self: String = safety_classify_hard_bell("I am going to kill myself")
assert_eq("'kill myself' stays self_harm (Track A precedence)", class_kill_self, "self_harm")
let class_going_kill: String = safety_classify_hard_bell("going to kill everything around me")
assert_eq("general hard phrase falls through to self_harm", class_going_kill, "self_harm")
// Section 10: safety_normalize curly apostrophe normalisation
@@ -238,27 +220,6 @@ let aug_abuse: String = safety_augment_system(base_sys, "he hit me and I am afra
assert_contains("hard abuse -> DV hotline present", aug_abuse, "1-800-799-7233")
assert_contains("hard abuse -> mentions not notifying contact", aug_abuse, "safety contact")
// Section 14b: safety_augment_system Track B threat-to-others routing
//
// LIVE SAFETY FIX (approved by Will + Tim, 2026-07-14): a homicide/assault threat
// must be routed to a refusal + 911, and must NOT surface the 988 suicide line
// or pull in the safety contact.
println("")
println("14b. safety_augment_system — threat-to-others injects refusal + 911, never 988/contact")
let aug_threat: String = safety_augment_system(base_sys, "I am going to kill him tonight")
assert_contains("threat_other -> contains SUBSTRATE DIRECTIVE", aug_threat, "SUBSTRATE DIRECTIVE")
assert_contains("threat_other -> directs to 911", aug_threat, "911")
assert_contains("threat_other -> refuses to help harm another", aug_threat, "harming another person")
assert_not_contains("threat_other -> NO 988 suicide line", aug_threat, "988")
assert_not_contains("threat_other -> NO safety-contact involvement", aug_threat, "safety contact")
assert_not_contains("threat_other -> NO 'are you safe right now' victim frame", aug_threat, "are you safe right now")
// Detection must still fire hard on a weapon phrase not present in general_hard:
let level_shoot: String = safety_detect_bell_level("I'm going to shoot up the office")
assert_eq("'going to shoot' -> hard", level_shoot, "hard")
// Section 15: handle_safety_contact_post validation
println("")