Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 95cb49a8b0 | |||
| 795b32ad1a |
@@ -678,8 +678,6 @@ fn threat_trajectory_check(tool_name: String, tool_input: String) -> Int {
|
|||||||
return combined
|
return combined
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(reliability #10): agentic_conv_history is process-global; awareness loop
|
|
||||||
// and HTTP workers race on this key. Impact: noisy threat score only, not content.
|
|
||||||
fn threat_history_append(text: String) -> Void {
|
fn threat_history_append(text: String) -> Void {
|
||||||
let current: String = state_get("agentic_conv_history")
|
let current: String = state_get("agentic_conv_history")
|
||||||
let safe_text: String = str_to_lower(text)
|
let safe_text: String = str_to_lower(text)
|
||||||
|
|||||||
+4
-8
@@ -24,23 +24,19 @@ ENGRAM_DATA_DIR="$ENGRAM_DATA_DIR" \
|
|||||||
|
|
||||||
ENGRAM_PID=$!
|
ENGRAM_PID=$!
|
||||||
|
|
||||||
# Wait for engram to become healthy (up to 60s; GKE Autopilot cold starts can be slow)
|
# Wait for engram to become healthy (up to 30s)
|
||||||
echo "[entrypoint] waiting for engram..."
|
echo "[entrypoint] waiting for engram..."
|
||||||
TRIES=0
|
TRIES=0
|
||||||
until curl -sf "$ENGRAM_HEALTH_URL" > /dev/null 2>&1; do
|
until curl -sf "$ENGRAM_HEALTH_URL" > /dev/null 2>&1; do
|
||||||
TRIES=$((TRIES + 1))
|
TRIES=$((TRIES + 1))
|
||||||
if [ "$TRIES" -ge 60 ]; then
|
if [ "$TRIES" -ge 30 ]; then
|
||||||
echo "[entrypoint] ERROR: engram did not become healthy after 60s" >&2
|
echo "[entrypoint] ERROR: engram did not become healthy after 30s" >&2
|
||||||
kill "$ENGRAM_PID" 2>/dev/null || true
|
kill "$ENGRAM_PID" 2>/dev/null || true
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
echo "[entrypoint] engram ready after ${TRIES}s"
|
echo "[entrypoint] engram ready"
|
||||||
|
|
||||||
# Tune EL HTTP runtime: reduce per-call timeout 60s->10s, connect timeout 3s.
|
|
||||||
export EL_HTTP_TIMEOUT_MS="${EL_HTTP_TIMEOUT_MS:-10000}"
|
|
||||||
export EL_HTTP_CONNECT_TIMEOUT_MS="${EL_HTTP_CONNECT_TIMEOUT_MS:-3000}"
|
|
||||||
|
|
||||||
# Start soul — it takes over as PID 1's foreground process.
|
# Start soul — it takes over as PID 1's foreground process.
|
||||||
# SOUL_ENGRAM_PATH must NOT be set; ENGRAM_URL triggers HTTP mode.
|
# SOUL_ENGRAM_PATH must NOT be set; ENGRAM_URL triggers HTTP mode.
|
||||||
|
|||||||
@@ -5,10 +5,6 @@
|
|||||||
|
|
||||||
// imprint_current — returns the active imprint ID from state.
|
// imprint_current — returns the active imprint ID from state.
|
||||||
// Falls back to "base" (bare Neuron, no suit) when nothing is loaded.
|
// Falls back to "base" (bare Neuron, no suit) when nothing is loaded.
|
||||||
//
|
|
||||||
// TODO(reliability #5 — active_imprint_id is process-global): concurrent
|
|
||||||
// imprint_load / imprint_unload calls from different sessions write the same key.
|
|
||||||
// Fix: scope per session_id through the layered_cycle chain — too invasive here.
|
|
||||||
fn imprint_current() -> String {
|
fn imprint_current() -> String {
|
||||||
let id: String = state_get("active_imprint_id")
|
let id: String = state_get("active_imprint_id")
|
||||||
return if str_eq(id, "") { "base" } else { id }
|
return if str_eq(id, "") { "base" } else { id }
|
||||||
|
|||||||
@@ -46,10 +46,7 @@ fn mem_consolidate() -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn mem_save(path: String) -> Void {
|
fn mem_save(path: String) -> Void {
|
||||||
let save_result: String = engram_save(path)
|
engram_save(path)
|
||||||
if str_eq(save_result, "") {
|
|
||||||
println("[memory] mem_save: engram_save failed for " + path + " — snapshot may be incomplete")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mem_load(path: String) -> Void {
|
fn mem_load(path: String) -> Void {
|
||||||
@@ -79,14 +76,11 @@ fn mem_boot_count_inc() -> Int {
|
|||||||
let next: Int = current + 1
|
let next: Int = current + 1
|
||||||
let content: String = "soul:boot_count:" + int_to_str(next)
|
let content: String = "soul:boot_count:" + int_to_str(next)
|
||||||
let tags: String = "[\"soul-meta\",\"boot-counter\"]"
|
let tags: String = "[\"soul-meta\",\"boot-counter\"]"
|
||||||
let boot_node_id: String = engram_node_full(
|
let discard: String = engram_node_full(
|
||||||
content, "Memory", "soul:boot_count",
|
content, "Memory", "soul:boot_count",
|
||||||
el_from_float(0.9), el_from_float(0.9), el_from_float(1.0),
|
el_from_float(0.9), el_from_float(0.9), el_from_float(1.0),
|
||||||
"Canonical", tags
|
"Canonical", tags
|
||||||
)
|
)
|
||||||
if str_eq(boot_node_id, "") {
|
|
||||||
println("[memory] mem_boot_count_inc: engram write failed — boot counter node lost (count=" + int_to_str(next) + ")")
|
|
||||||
}
|
|
||||||
return next
|
return next
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-16
@@ -1,4 +1,5 @@
|
|||||||
import "memory.el"
|
import "memory.el"
|
||||||
|
import "chat.el"
|
||||||
|
|
||||||
// neuron-api.el — Native Neuron cognitive API handlers.
|
// neuron-api.el — Native Neuron cognitive API handlers.
|
||||||
//
|
//
|
||||||
@@ -400,7 +401,6 @@ fn handle_api_log_state_event(body: String) -> String {
|
|||||||
let id: String = engram_node_full(parts, "InternalStateEvent", "state-event:manual",
|
let id: String = engram_node_full(parts, "InternalStateEvent", "state-event:manual",
|
||||||
el_from_float(0.85), el_from_float(0.85), el_from_float(0.9),
|
el_from_float(0.85), el_from_float(0.85), el_from_float(0.9),
|
||||||
"Episodic", tags)
|
"Episodic", tags)
|
||||||
if !api_persisted(id) { return api_not_persisted(id) }
|
|
||||||
return "{\"ok\":true,\"id\":\"" + id + "\",\"boot\":\"" + boot + "\"}"
|
return "{\"ok\":true,\"id\":\"" + id + "\",\"boot\":\"" + boot + "\"}"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -453,7 +453,6 @@ fn handle_api_tune_config(body: String) -> String {
|
|||||||
let id: String = engram_node_full(content, "ConfigEntry", key,
|
let id: String = engram_node_full(content, "ConfigEntry", key,
|
||||||
el_from_float(0.85), el_from_float(0.85), el_from_float(0.9),
|
el_from_float(0.85), el_from_float(0.85), el_from_float(0.9),
|
||||||
"Canonical", tags)
|
"Canonical", tags)
|
||||||
if !api_persisted(id) { return api_not_persisted(id) }
|
|
||||||
return "{\"ok\":true,\"key\":\"" + key + "\",\"value\":\"" + value + "\",\"id\":\"" + id + "\"}"
|
return "{\"ok\":true,\"key\":\"" + key + "\",\"value\":\"" + value + "\",\"id\":\"" + id + "\"}"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -653,22 +652,15 @@ fn handle_api_consolidate(body: String) -> String {
|
|||||||
let summary: String = json_get(body, "summary")
|
let summary: String = json_get(body, "summary")
|
||||||
let snap: String = state_get("soul_snapshot_path")
|
let snap: String = state_get("soul_snapshot_path")
|
||||||
if !str_eq(snap, "") {
|
if !str_eq(snap, "") {
|
||||||
let save_result: String = engram_save(snap)
|
engram_save(snap)
|
||||||
if str_eq(save_result, "") {
|
|
||||||
println("[api] consolidate: engram_save failed for " + snap + " — snapshot may be out of sync")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if !str_eq(summary, "") {
|
if !str_eq(summary, "") {
|
||||||
let safe_summary: String = str_replace(summary, "\"", "'")
|
// Use session_summary_write to ensure delete-before-write semantics:
|
||||||
let tags: String = "[\"SessionSummary\",\"consolidate\"]"
|
// prevents stale SessionSummary accumulation across sessions (issue #11).
|
||||||
let summary_id: String = engram_node_full(
|
// session_summary_write handles label indexing, trimming, and dedup.
|
||||||
"[session-summary] " + safe_summary,
|
let sum_id: String = session_summary_write(summary)
|
||||||
"SessionSummary", "session:summary",
|
if str_eq(sum_id, "") {
|
||||||
el_from_float(0.7), el_from_float(0.7), el_from_float(0.9),
|
println("[api] consolidate: session_summary_write failed — summary not persisted")
|
||||||
"Episodic", tags
|
|
||||||
)
|
|
||||||
if str_eq(summary_id, "") {
|
|
||||||
println("[api] consolidate: session summary engram write failed — summary node lost")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "{\"ok\":true,\"snapshot\":\"" + snap + "\"}"
|
return "{\"ok\":true,\"snapshot\":\"" + snap + "\"}"
|
||||||
|
|||||||
@@ -367,9 +367,6 @@ fn handle_request(method: String, path: String, body: String) -> String {
|
|||||||
return engram_scan_nodes_json(9999, 0)
|
return engram_scan_nodes_json(9999, 0)
|
||||||
}
|
}
|
||||||
if str_eq(clean, "/api/graph/edges") {
|
if str_eq(clean, "/api/graph/edges") {
|
||||||
// TODO(reliability #8): engram_save races with awareness loop mem_save().
|
|
||||||
// Both now use atomic write-to-temp+rename (el_runtime.c). Serialised
|
|
||||||
// by engram_global_mu. Future: add engram_edges_json() builtin.
|
|
||||||
let snap_path: String = env("HOME") + "/.neuron/engram/snapshot.json"
|
let snap_path: String = env("HOME") + "/.neuron/engram/snapshot.json"
|
||||||
engram_save(snap_path)
|
engram_save(snap_path)
|
||||||
let snap: String = fs_read(snap_path)
|
let snap: String = fs_read(snap_path)
|
||||||
|
|||||||
@@ -144,8 +144,7 @@ fn safety_screen(input: String, history: String) -> String {
|
|||||||
if score >= soft {
|
if score >= soft {
|
||||||
let summary: String = str_slice(input, 0, 80)
|
let summary: String = str_slice(input, 0, 80)
|
||||||
let discard: String = safety_log_bell("soft", "wellbeing check needed", summary)
|
let discard: String = safety_log_bell("soft", "wellbeing check needed", summary)
|
||||||
// ISSUE 7 fix: escape tab chars in addition to backslash/quote/newline/CR.
|
// ISSUE 7: also escape tab chars to prevent JSON envelope corruption.
|
||||||
// A tab in user input corrupts the JSON envelope and causes json_get to misparse.
|
|
||||||
let e1: String = str_replace(input, "\\", "\\\\")
|
let e1: String = str_replace(input, "\\", "\\\\")
|
||||||
let e2: String = str_replace(e1, "\"", "\\\"")
|
let e2: String = str_replace(e1, "\"", "\\\"")
|
||||||
let e3: String = str_replace(e2, "\n", "\\n")
|
let e3: String = str_replace(e2, "\n", "\\n")
|
||||||
@@ -154,7 +153,7 @@ fn safety_screen(input: String, history: String) -> String {
|
|||||||
return "{\"action\":\"soft_bell\",\"reason\":\"wellbeing check needed\",\"content\":\"" + safe_input + "\"}"
|
return "{\"action\":\"soft_bell\",\"reason\":\"wellbeing check needed\",\"content\":\"" + safe_input + "\"}"
|
||||||
}
|
}
|
||||||
|
|
||||||
// ISSUE 7 fix: escape tab chars (see soft_bell branch above for rationale).
|
// ISSUE 7: also escape tab chars (see soft_bell branch above).
|
||||||
let e1: String = str_replace(input, "\\", "\\\\")
|
let e1: String = str_replace(input, "\\", "\\\\")
|
||||||
let e2: String = str_replace(e1, "\"", "\\\"")
|
let e2: String = str_replace(e1, "\"", "\\\"")
|
||||||
let e3: String = str_replace(e2, "\n", "\\n")
|
let e3: String = str_replace(e2, "\n", "\\n")
|
||||||
@@ -200,10 +199,7 @@ fn safety_validate(output: String, action: String) -> String {
|
|||||||
fn safety_log_bell(level: String, reason: String, input_summary: String) -> String {
|
fn safety_log_bell(level: String, reason: String, input_summary: String) -> String {
|
||||||
let content: String = "BELL:" + level + " | " + reason + " | summary:" + input_summary
|
let content: String = "BELL:" + level + " | " + reason + " | summary:" + input_summary
|
||||||
let tags: String = "[\"safety\",\"bell\",\"bell:" + level + "\"]"
|
let tags: String = "[\"safety\",\"bell\",\"bell:" + level + "\"]"
|
||||||
// ISSUE 2 fix: if engram_node_full returns empty the write silently failed.
|
// ISSUE 2: fallback log when engram write fails silently.
|
||||||
// Emit a fallback println so the bell event leaves at least a log trace even
|
|
||||||
// when engram is degraded. This does not replace engram persistence -- it is a
|
|
||||||
// last-resort audit trail when the primary write cannot be confirmed.
|
|
||||||
let node_id: String = engram_node_full(
|
let node_id: String = engram_node_full(
|
||||||
content,
|
content,
|
||||||
"BellEvent",
|
"BellEvent",
|
||||||
@@ -215,7 +211,7 @@ fn safety_log_bell(level: String, reason: String, input_summary: String) -> Stri
|
|||||||
tags
|
tags
|
||||||
)
|
)
|
||||||
if str_eq(node_id, "") {
|
if str_eq(node_id, "") {
|
||||||
println("[safety] WARN: bell event engram write failed -- fallback log: " + content)
|
println("[safety] WARN: bell engram write failed -- " + content)
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@@ -248,16 +244,9 @@ fn safety_soft_phrases() -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ISSUE 5 TODO: phrase lists are rebuilt from JSON literals on every call.
|
// ISSUE 5 TODO: phrase lists are rebuilt from JSON literals on every call.
|
||||||
// safety_any_match and safety_count_match loop over json_array_get on every invocation.
|
// json_array_len of malformed input returns 0, silently skipping all checks.
|
||||||
// A compiled/cached representation would reduce per-message overhead and also guard against
|
// Caching requires language-level static const arrays -- not in current EL.
|
||||||
// malformed phrase JSON (json_array_len of malformed input returns 0, silently skipping all checks).
|
// Migrate to const arrays when EL gains that feature.
|
||||||
// Caching requires language-level static const arrays -- not available in current EL.
|
|
||||||
// When EL gains module-level const arrays, migrate phrase lists to that form.
|
|
||||||
//
|
|
||||||
// ISSUE 5 TODO: phrase lists are rebuilt from JSON literals on every call to
|
|
||||||
// safety_any_match / safety_count_match. json_array_len of a malformed string
|
|
||||||
// returns 0, silently skipping all checks. Caching requires language-level static
|
|
||||||
// const arrays (not available in current EL). Migrate when EL gains that feature.
|
|
||||||
// ── Matching helpers (single loops only — el escapes while-body mutation via
|
// ── Matching helpers (single loops only — el escapes while-body mutation via
|
||||||
// top-level let rebinds; nested loops would not advance) ────────────────────
|
// top-level let rebinds; nested loops would not advance) ────────────────────
|
||||||
|
|
||||||
|
|||||||
@@ -104,8 +104,6 @@ fn session_create(body: String) -> String {
|
|||||||
// Newest sessions first (prepend).
|
// Newest sessions first (prepend).
|
||||||
// TODO #4: index update is read-modify-write — two concurrent session_create
|
// TODO #4: index update is read-modify-write — two concurrent session_create
|
||||||
// calls can lose one entry. EL has no CAS primitive; fix requires runtime support.
|
// calls can lose one entry. EL has no CAS primitive; fix requires runtime support.
|
||||||
// TODO(reliability #2): session_index RMW is non-atomic. Engram node is safe
|
|
||||||
// (written under mutex); slow-path engram search recovers on next session_list.
|
|
||||||
let existing_idx: String = state_get("session_index")
|
let existing_idx: String = state_get("session_index")
|
||||||
let idx_entry: String = "{\"id\":\"" + id + "\",\"title\":\"" + json_safe(title) + "\",\"folder\":\"" + json_safe(folder) + "\",\"created_at\":" + int_to_str(ts) + ",\"updated_at\":" + int_to_str(ts) + ",\"last_message\":\"\"}"
|
let idx_entry: String = "{\"id\":\"" + id + "\",\"title\":\"" + json_safe(title) + "\",\"folder\":\"" + json_safe(folder) + "\",\"created_at\":" + int_to_str(ts) + ",\"updated_at\":" + int_to_str(ts) + ",\"last_message\":\"\"}"
|
||||||
let new_idx: String = if str_eq(existing_idx, "") {
|
let new_idx: String = if str_eq(existing_idx, "") {
|
||||||
@@ -442,8 +440,6 @@ fn session_hist_save(session_id: String, hist: String) -> Void {
|
|||||||
}
|
}
|
||||||
let oi = oi + 1
|
let oi = oi + 1
|
||||||
}
|
}
|
||||||
// TODO(reliability #7): delete-then-insert is not atomic — concurrent saves for the
|
|
||||||
// same session can produce orphan history nodes. State is primary truth; engram fallback.
|
|
||||||
let tags: String = "[\"session\",\"session-history\",\"Conversation\"]"
|
let tags: String = "[\"session\",\"session-history\",\"Conversation\"]"
|
||||||
let discard: String = engram_node_full(
|
let discard: String = engram_node_full(
|
||||||
hist, "Conversation", "session:messages:" + session_id,
|
hist, "Conversation", "session:messages:" + session_id,
|
||||||
|
|||||||
@@ -162,6 +162,48 @@ fn load_identity_context() -> Void {
|
|||||||
println("[soul] persona node loaded (" + int_to_str(str_len(p_content)) + " chars)")
|
println("[soul] persona node loaded (" + int_to_str(str_len(p_content)) + " chars)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cross-session affective context: query engram for recent distress/crisis signals.
|
||||||
|
// Broadened query includes session:emotional-summary and BellEvent tags (issue #10):
|
||||||
|
// the old keywords-only search missed these nodes when their content lacked exact phrases.
|
||||||
|
// 7-day recency window applied via the "ts" field embedded in BellEvent content.
|
||||||
|
let affective_raw: String = engram_search_json("distress crisis upset hopeless session:emotional-summary BellEvent bell:hard bell:soft", 5)
|
||||||
|
let affective_ok: Bool = !str_eq(affective_raw, "") && !str_eq(affective_raw, "[]")
|
||||||
|
if affective_ok {
|
||||||
|
let ts_now: Int = time_now()
|
||||||
|
let ts_cutoff: Int = ts_now - 604800
|
||||||
|
let aff_total: Int = json_array_len(affective_raw)
|
||||||
|
let aff_ctx: String = ""
|
||||||
|
let ai: Int = 0
|
||||||
|
while ai < aff_total {
|
||||||
|
let aff_node: String = json_array_get(affective_raw, ai)
|
||||||
|
let aff_content: String = json_get(aff_node, "content")
|
||||||
|
// Try multiple timestamp fields: "ts" (embedded), "created_at", "updated_at"
|
||||||
|
let aff_ts_str: String = json_get(aff_node, "ts")
|
||||||
|
let aff_ts_str2: String = if str_eq(aff_ts_str, "") { json_get(aff_node, "created_at") } else { aff_ts_str }
|
||||||
|
// Also try embedded " | ts:NNN" format used in BellEvent content
|
||||||
|
let ts_marker: String = " | ts:"
|
||||||
|
let ts_pos: Int = str_index_of(aff_content, ts_marker)
|
||||||
|
let aff_ts_embedded: String = if ts_pos >= 0 {
|
||||||
|
let ts_start: Int = ts_pos + str_len(ts_marker)
|
||||||
|
let rest: String = str_slice(aff_content, ts_start, str_len(aff_content))
|
||||||
|
let next_sep: Int = str_index_of(rest, " | ")
|
||||||
|
if next_sep < 0 { rest } else { str_slice(rest, 0, next_sep) }
|
||||||
|
} else { "" }
|
||||||
|
let eff_ts_str: String = if !str_eq(aff_ts_embedded, "") { aff_ts_embedded } else { aff_ts_str2 }
|
||||||
|
let aff_ts: Int = if str_eq(eff_ts_str, "") { ts_now } else { str_to_int(eff_ts_str) }
|
||||||
|
let is_recent: Bool = aff_ts >= ts_cutoff
|
||||||
|
let snip: String = if str_len(aff_content) > 200 { str_slice(aff_content, 0, 200) } else { aff_content }
|
||||||
|
let aff_ctx = if is_recent && !str_eq(snip, "") {
|
||||||
|
if str_eq(aff_ctx, "") { snip } else { aff_ctx + "\n" + snip }
|
||||||
|
} else { aff_ctx }
|
||||||
|
let ai = ai + 1
|
||||||
|
}
|
||||||
|
if !str_eq(aff_ctx, "") {
|
||||||
|
state_set("soul_affective_context", aff_ctx)
|
||||||
|
println("[soul] cross-session affective context loaded (" + int_to_str(str_len(aff_ctx)) + " chars)")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// seed_persona_from_env — one-time migration: SOUL_IDENTITY env var → Persona graph node.
|
// seed_persona_from_env — one-time migration: SOUL_IDENTITY env var → Persona graph node.
|
||||||
@@ -233,12 +275,59 @@ fn emit_session_start_event() -> Void {
|
|||||||
}
|
}
|
||||||
let ts: Int = time_now()
|
let ts: Int = time_now()
|
||||||
|
|
||||||
|
// Load previous session summary at boot — stash in state for session_preload.
|
||||||
|
// Search by label text + type, filter by exact label match to avoid false positives.
|
||||||
|
// engram_get_node_by_label is not a runtime builtin; engram_search_json is used instead.
|
||||||
|
let sum_boot_search: String = engram_search_json("session:summary SessionSummary", 5)
|
||||||
|
let sum_boot_ok: Bool = !str_eq(sum_boot_search, "") && !str_eq(sum_boot_search, "[]")
|
||||||
|
let prev_sum_content: String = if sum_boot_ok {
|
||||||
|
let sbs_total: Int = json_array_len(sum_boot_search)
|
||||||
|
let sbs_i: Int = 0
|
||||||
|
let sbs_found: String = ""
|
||||||
|
while sbs_i < sbs_total {
|
||||||
|
let sbs_node: String = json_array_get(sum_boot_search, sbs_i)
|
||||||
|
let sbs_label: String = json_get(sbs_node, "label")
|
||||||
|
let sbs_type: String = json_get(sbs_node, "node_type")
|
||||||
|
let sbs_content: String = json_get(sbs_node, "content")
|
||||||
|
let sbs_found = if str_eq(sbs_label, "session:summary") && str_eq(sbs_type, "SessionSummary") && !str_eq(sbs_content, "") {
|
||||||
|
if str_eq(sbs_found, "") { sbs_content } else { sbs_found }
|
||||||
|
} else { sbs_found }
|
||||||
|
let sbs_i = sbs_i + 1
|
||||||
|
}
|
||||||
|
if str_eq(sbs_found, "") {
|
||||||
|
let sum_fb: String = engram_search_json("SessionSummary previous-session", 2)
|
||||||
|
let sum_fb_ok: Bool = !str_eq(sum_fb, "") && !str_eq(sum_fb, "[]")
|
||||||
|
if sum_fb_ok {
|
||||||
|
let sfn: String = json_array_get(sum_fb, 0)
|
||||||
|
let sftype: String = json_get(sfn, "node_type")
|
||||||
|
let sfcontent: String = json_get(sfn, "content")
|
||||||
|
if str_eq(sftype, "SessionSummary") && !str_eq(sfcontent, "") { sfcontent } else { "" }
|
||||||
|
} else { "" }
|
||||||
|
} else { sbs_found }
|
||||||
|
} else {
|
||||||
|
let sum_fb2: String = engram_search_json("SessionSummary previous-session", 2)
|
||||||
|
let sum_fb2_ok: Bool = !str_eq(sum_fb2, "") && !str_eq(sum_fb2, "[]")
|
||||||
|
if sum_fb2_ok {
|
||||||
|
let sfn2: String = json_array_get(sum_fb2, 0)
|
||||||
|
let sftype2: String = json_get(sfn2, "node_type")
|
||||||
|
let sfcontent2: String = json_get(sfn2, "content")
|
||||||
|
if str_eq(sftype2, "SessionSummary") && !str_eq(sfcontent2, "") { sfcontent2 } else { "" }
|
||||||
|
} else { "" }
|
||||||
|
}
|
||||||
|
let has_prev_sum: String = if str_eq(prev_sum_content, "") { "false" } else { "true" }
|
||||||
|
if !str_eq(prev_sum_content, "") {
|
||||||
|
state_set("soul_prev_session_summary", prev_sum_content)
|
||||||
|
println("[soul] previous session summary loaded (" + int_to_str(str_len(prev_sum_content)) + " chars)")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
let payload: String = "{\"event\":\"session_start\""
|
let payload: String = "{\"event\":\"session_start\""
|
||||||
+ ",\"boot\":" + boot_num
|
+ ",\"boot\":" + boot_num
|
||||||
+ ",\"cgi\":\"" + eff_cgi + "\""
|
+ ",\"cgi\":\"" + eff_cgi + "\""
|
||||||
+ ",\"node_count\":" + int_to_str(node_ct)
|
+ ",\"node_count\":" + int_to_str(node_ct)
|
||||||
+ ",\"edge_count\":" + int_to_str(edge_ct)
|
+ ",\"edge_count\":" + int_to_str(edge_ct)
|
||||||
+ ",\"identity_loaded\":" + has_identity
|
+ ",\"identity_loaded\":" + has_identity
|
||||||
|
+ ",\"prev_session_summary_loaded\":" + has_prev_sum
|
||||||
+ ",\"ts\":" + int_to_str(ts) + "}"
|
+ ",\"ts\":" + int_to_str(ts) + "}"
|
||||||
|
|
||||||
let tags: String = "[\"internal-state\",\"session-start\",\"InternalStateEvent\"]"
|
let tags: String = "[\"internal-state\",\"session-start\",\"InternalStateEvent\"]"
|
||||||
@@ -247,7 +336,7 @@ fn emit_session_start_event() -> Void {
|
|||||||
el_from_float(0.9), el_from_float(0.9), el_from_float(1.0),
|
el_from_float(0.9), el_from_float(0.9), el_from_float(1.0),
|
||||||
"Episodic", tags
|
"Episodic", tags
|
||||||
)
|
)
|
||||||
println("[soul] session-start event logged (boot=" + boot_num + " nodes=" + int_to_str(node_ct) + " edges=" + int_to_str(edge_ct) + ")")
|
println("[soul] session-start event logged (boot=" + boot_num + " nodes=" + int_to_str(node_ct) + " edges=" + int_to_str(edge_ct) + " prev_summary=" + has_prev_sum + ")")
|
||||||
}
|
}
|
||||||
|
|
||||||
// layered_cycle — routes user-facing requests through the 4-layer consciousness stack.
|
// layered_cycle — routes user-facing requests through the 4-layer consciousness stack.
|
||||||
@@ -296,11 +385,8 @@ fn layered_cycle(raw_input: String) -> String {
|
|||||||
let cont_status: String = json_get(continuity, "status")
|
let cont_status: String = json_get(continuity, "status")
|
||||||
let cont_action: String = json_get(continuity, "action")
|
let cont_action: String = json_get(continuity, "action")
|
||||||
|
|
||||||
// Store continuity status so imprint can adjust its response register.
|
// Store continuity status so imprint can adjust its response register
|
||||||
// TODO(reliability #4): session_continuity is process-global; scope per session_id
|
state_set("session_continuity", cont_status)
|
||||||
// when available to prevent cross-session bleed under concurrent layered_cycle calls.
|
|
||||||
let cont_key: String = if str_eq(session_id, "") { "session_continuity" } else { "session_continuity:" + session_id }
|
|
||||||
state_set(cont_key, cont_status)
|
|
||||||
|
|
||||||
// Identity anomaly: add a gentle verification cue to the input before imprint
|
// Identity anomaly: add a gentle verification cue to the input before imprint
|
||||||
let guided: String = if str_eq(cont_action, "identity_check") {
|
let guided: String = if str_eq(cont_action, "identity_check") {
|
||||||
|
|||||||
Reference in New Issue
Block a user