Compare commits

..

39 Commits

Author SHA1 Message Date
will.anderson d4609c7baa chore(dist): update neuron.c and routes.c to 2-arg build_system_prompt
Deploy Soul to GKE / deploy (push) Failing after 7m15s
Neuron Soul CI / build (push) Failing after 21m49s
neuron.c and routes.c were compiled against the old 1-arg soul interface.
chat.c already uses the 2-arg signature. The Windows cross-compile build
generates elp-c-decls.h from all dist/*.c files, causing a conflicting-types
error when both signatures appear. Recompile these modules against the
current soul API to eliminate the conflict.
2026-06-25 13:10:20 -05:00
will.anderson 98603f5ae8 self-review 2026-06-24: rebuild with goal_bias fix (Knowledge type boost)
Linked against dev runtime with is_knowledge fix that adds Knowledge
node type. Engram goal_bias now gives Knowledge nodes +0.3 boost on
technical queries, consistent with how Belief/DharmaSelf/Safety nodes
are already treated. Same el_runtime source as concurrent foundation/el
commit 16d62bd.
2026-06-24 08:48:21 -05:00
will.anderson bdc07be344 chore(dist): compile EL recall/dedup/session-continuity fixes to C
Neuron Soul CI / build (push) Failing after 12m40s
Deploy Soul to GKE / deploy (push) Failing after 6m0s
Updates soul.c and all per-module .c files with:
- parse_float_x100() engram score fix
- id_in_seen dedup wiring across session_preload
- session-end summary hook + session-start recall
- Emergency structural repair (no duplicate fns, all callsites wired)
2026-06-23 13:04:06 -05:00
will.anderson 4a44c24bfb fix(recall): wire id_in_seen guards into session_preload node renders
Neuron Soul CI / build (push) Has been cancelled
Deploy Soul to GKE / deploy (push) Failing after 7m29s
All 8 session_preload node accesses (3 profile, 2 work, 2 project, 1
summary) now check id_in_seen(node_id, seen_ids) before including
content. seen_ids is populated by engram_compile via state and covers
all nodes already in the activation+search context block. Prevents
high-salience nodes from appearing twice in the system prompt.
2026-06-22 15:08:30 -05:00
will.anderson ac1991fe8c Merge branch 'fix/emergency-regressions'
Neuron Soul CI / build (push) Has been cancelled
Deploy Soul to GKE / deploy (push) Failing after 11m10s
2026-06-22 14:53:10 -05:00
will.anderson f2b63f0048 fix(emergency): repair session-continuity regressions from prior merge 2026-06-22 14:51:51 -05:00
will.anderson 774688cfb9 fix/session-continuity-hook
Neuron Soul CI / build (push) Has been cancelled
Deploy Soul to GKE / deploy (push) Failing after 6m0s
2026-06-22 14:29:31 -05:00
will.anderson aa2404b3f7 fix/context-dedup-shared-ids 2026-06-22 14:29:06 -05:00
will.anderson 94b55d667c fix/engram-float-parser 2026-06-22 14:28:17 -05:00
will.anderson f73c913498 fix(session-continuity): address all adversarial review findings
Issue 1 (CRITICAL): Restore parse_float_x100 for correct single-decimal
float handling. "0.9" now correctly yields 90, not 9. Also restores
engram_numeric_valid guard that validates inputs before str_to_int.

Issue 2 (CRITICAL): Fix handle_chat_agentic safety screen history key
regression. state_get("conversation_history") -> state_get("conv_history")
so the safety screen receives actual history instead of always "".

Issue 3 (REAL BUG): Replace _sel_N JSON sentinel injection in
engram_compile_ranked with |N| index string tracking. Sentinels were
leaking into node JSON delivered to the LLM and cleanup only covered
indices 0-14, leaving indices 15+ uncleaned.

Issue 4 (REGRESSION): Restore rendered conversation history formatting.
Conversation history is now rendered as "User: .../Assistant: ..." with
400-char truncation per turn, not raw JSON array injection.

Issue 5 (SCOPE/SAFETY): Restore removed defensive code: engram_numeric_valid
and parse_float_x100 guards; conv_history_load label-based fetch + partial-
write guard + load-failure state flag; conv_history_persist partial-write
guard + failure logging; hist_warning in response envelope.

Issue 6 (UNDOCUMENTED): Restore bell event cutoff from 259200s (3 days)
back to 1209600s (14 days). Also restore PositiveEvent affective context
search that was removed alongside the cutoff change.

Issue 7 (LOGIC REGRESSION): Fix affective_prefix to run every turn
(not just hist_len == 0). The care/joy directives must persist throughout
the session, not vanish after turn 1.

Issue 8 (MINOR): session_summary_write_dated now uses el_from_float(0.85)
for salience and importance (two-decimal) to avoid any ambiguity in float
parsing, and the function is re-added with the session-end hook.
2026-06-22 14:25:29 -05:00
will.anderson 588ca11f57 fix(context-dedup): include scan_part and affective_part IDs in seen set
Two design bugs in the state_set placement caused the dedup seen-ID set
to be incomplete even with callsites wired up:

1. state_set("engram_compile_seen_ids") was called immediately after
   merging the main node pools, before scan_part (persona fallback) and
   affective_part (bell node) were computed. Nodes appearing only in
   those segments were never added to the seen set.

2. affective_part is a bare JSON object (bn0 from json_array_get), not
   a JSON array. Passing it to engram_extract_ids would have gotten
   json_array_len == 0 and silently skipped the affective node's ID.

Fix: move state_set to after ctx is assembled from all three segments.
Extract ids_from_merged and ids_from_scan via engram_extract_ids (both
are JSON arrays), and extract ids_from_affective via json_get(affective_part, "id")
directly since it is a bare object. Merge all three via add_to_seen
before publishing to state.
2026-06-22 14:19:14 -05:00
will.anderson 9e178d8371 fix(recall): deduplicate engram nodes by ID across activation and search passes
Thread a seen-node-ID exclusion set from engram_compile() through to
session_preload in handle_chat, preventing the same high-salience nodes
(identity, recent memories) from appearing 2-3x in the system prompt.

Changes:
- Add id_in_seen(), add_to_seen(), engram_extract_ids() helpers that
  maintain a comma-delimited seen-ID accumulator (EL has no Set type)
- In engram_compile(): after merging all topic/entity/recall pools, extract
  node IDs from merged_nodes and publish via state_set(engram_compile_seen_ids)
- In handle_chat(): read seen_ids from state after engram_compile() returns,
  then check id_in_seen() before emitting each session_preload bullet
  (profile x3, work x2, project x2, summary x1 — all 8 candidate nodes guarded)

Nodes already present in the compiled engram context are skipped in preload,
eliminating 3000-3500 token repetition on first-message turns.
2026-06-22 14:06:04 -05:00
will.anderson aaada3770a fix(recall): deduplicate engram nodes by ID across activation and search passes
engram_compile() already published seen node IDs to state via engram_compile_seen_ids
but handle_chat never read or applied them. Wire up the consumption side:

- Read engram_compile_seen_ids from state after engram_compile() returns
- Check each session_preload candidate node (profile x3, work x2, project x2,
  summary x3) against id_in_seen() before emitting its content bullet
- Nodes already present in the compiled engram context are skipped entirely,
  preventing the same high-salience identity/memory nodes from appearing 2-3x
  in the system prompt and burning 3000-3500 tokens on repetition
2026-06-22 14:03:48 -05:00
will.anderson a0299c0a89 fix(recall): session-end summary hook + session summary recall at start 2026-06-22 14:01:56 -05:00
will.anderson 33cb1138f4 fix(recall): set threshold=25 in all engram_compile_ranked variants 2026-06-22 13:58:17 -05:00
will.anderson ec7efdeeb7 fix(recall): engram score float parsing — pad to 2 decimals before strip 2026-06-22 13:57:33 -05:00
will.anderson c93be6a315 feat(recall): context-format
Neuron Soul CI / build (push) Has been cancelled
Deploy Soul to GKE / deploy (push) Failing after 13m54s
2026-06-22 13:29:12 -05:00
will.anderson 53268c94b9 feat(recall): activation-seed 2026-06-22 13:29:12 -05:00
will.anderson 7e43a4ddc0 feat(recall): context-dedup 2026-06-22 13:29:12 -05:00
will.anderson e7669da325 feat(recall): session-start-recall 2026-06-22 13:29:12 -05:00
will.anderson 4f1286df05 feat(recall): cross-session-continuity 2026-06-22 13:29:12 -05:00
will.anderson 52c222c4f2 feat(recall): engram-scoring 2026-06-22 13:29:12 -05:00
will.anderson 0caccd0ea5 feat(recall): temporal-precision 2026-06-22 13:29:12 -05:00
will.anderson 03b5632fc1 feat(recall): recall-reliability 2026-06-22 13:29:12 -05:00
will.anderson 42bbadcd33 Merge pull request 'feat(recall): emotional-recall improvements' (#52) from improve/recall-emotional-recall into main
Neuron Soul CI / build (push) Has been cancelled
Deploy Soul to GKE / deploy (push) Failing after 5m49s
feat(recall): emotional-recall improvements
2026-06-22 18:24:36 +00:00
will.anderson b6052f9de3 Merge pull request 'feat(recall): recall-completeness' (#48) from improve/recall-recall-completeness into main
Neuron Soul CI / build (push) Has been cancelled
Deploy Soul to GKE / deploy (push) Has been cancelled
feat(recall): recall-completeness improvements
2026-06-22 18:24:17 +00:00
will.anderson 0113407728 feat(recall): emotional-recall improvements
Neuron Soul CI / build (pull_request) Has been cancelled
2026-06-22 13:17:12 -05:00
will.anderson be02fcd960 feat(recall): thread-aware activation seed for nlg soul path [issue 7]
Neuron Soul CI / build (pull_request) Successful in 4m37s
2026-06-22 13:17:04 -05:00
will.anderson cbe8c09068 feat(recall): context-dedup improvements
Neuron Soul CI / build (pull_request) Has been cancelled
- Cache bell node in engram_compile state (engram_compile_bell_node)
  so handle_chat reads cached value instead of duplicate bell query (Issue 2)
- Cache activation result (engram_compile_activation_json) for strengthen_chat_nodes
  reuse — eliminates third activation query per turn (Issue 7)
- Fix context cap to truncate at clean JSON object boundary (Issue 6)
2026-06-22 13:15:33 -05:00
will.anderson dfa2a33926 feat(recall): context-dedup improvements
- Cache bell node result in engram_compile state (engram_compile_bell_node)
  so handle_chat affective_prefix reads the cached value instead of firing
  a duplicate engram query for distress signals (Issue 2)

- Cache primary activation result in engram_compile state
  (engram_compile_activation_json) using nodes0 from engram_compile_multi

- Replace redundant engram_activate_json(message, 2) in strengthen_chat_nodes
  with state_get(engram_compile_activation_json) - eliminates a third
  activation query per turn (Issue 7)

- engram_compile already has object-boundary truncation and cross-set
  dedup via engram_nodes_merge/engram_dedup_nodes (Issues 1, 6, 9)
2026-06-22 13:12:08 -05:00
will.anderson 18e040acb1 feat(recall): recall-completeness improvements
Neuron Soul CI / build (pull_request) Has been cancelled
- Lower engram_compile_ranked threshold 25->15: include moderately-relevant older nodes
- Extend sentinel cleanup from _sel_9 to _sel_14 to prevent JSON noise
- Add engram_split_topics for multi-topic decomposition (AND/and/also/plus)
- Add engram_extract_entities for named entity dedicated searches
- Add engram_detect_recall_intent for boosted 40-candidate search on recall phrases
- Add engram_is_continuation replacing brittle 50-char threshold (now 80 + pronoun/opener detection)
- Add engram_compile_multi with depth 8 (was 5) and 30-candidate search pool
- Add engram_nodes_merge for clean two-array deduplication
- Replace engram_compile with multi-topic/entity/recall-boost version; budget 6000->8000
- Safe JSON truncation: scan for last } before budget cap instead of raw str_slice
- handle_chat and agentic_chat: use engram_is_continuation; thread snip 150->250
- session_preload: add project-status and session-summary search queries
2026-06-22 13:11:06 -05:00
will.anderson 3f53b6b1b6 feat(recall): session-start-recall improvements
Neuron Soul CI / build (pull_request) Has been cancelled
10 targeted fixes for session-start memory recall quality:

Issue 1: typed engram queries (Persona, WorkItem) replace generic keyword bags
Issue 2: bullet truncation raised from 120 to 350 chars
Issue 3: bullet caps raised to 8/6 with while-loop (no hardcoded unrolling)
Issue 4: read pre-computed soul_affective_context state key instead of duplicating boot-time search
Issue 5: last-session-topic node written per session; continuity section added to session_preload
Issue 6: greeting detection injects SESSION START orientation directive when continuity found
Issue 7: pinned identity node fallback when all engram searches return empty
Issue 8: session_preload always fires on first message (greeting detection controls directive only)
Issue 9: agentic path gets matching session_preload block (was missing entirely)
Issue 10: BellEvent recency reads created_at / embedded ts marker, not the never-written "ts" field
2026-06-22 13:06:55 -05:00
will.anderson 21f248a33a feat(recall): recall-completeness improvements
Neuron Soul CI / build (push) Has been cancelled
Deploy Soul to GKE / deploy (push) Has been cancelled
- Lower engram_compile_ranked threshold 25->15: include moderately-relevant older nodes
- Extend sentinel cleanup from _sel_9 to _sel_14 to prevent JSON noise
- Add engram_split_topics for multi-topic decomposition (AND/and/also/plus)
- Add engram_extract_entities for named entity dedicated searches
- Add engram_detect_recall_intent for boosted 40-candidate search on recall phrases
- Add engram_is_continuation replacing brittle 50-char threshold (now 80 + pronoun/opener detection)
- Add engram_compile_multi with depth 8 (was 5) and 30-candidate search pool
- Add engram_nodes_merge for clean two-array deduplication
- Replace engram_compile with multi-topic/entity/recall-boost version; budget 6000->8000
- Safe JSON truncation: scan for last } before budget cap instead of raw str_slice
- handle_chat and agentic_chat: use engram_is_continuation; thread snip 150->250
- session_preload: add project-status and session-summary search queries
2026-06-22 13:05:28 -05:00
will.anderson 795b32ad1a feat(recall): cross-session-continuity improvements
Neuron Soul CI / build (pull_request) Failing after 14m49s
2026-06-22 13:00:17 -05:00
will.anderson f33cdaf793 feat(recall): activation-seed improvements
- Issue 2: replace raw 50-char threshold with is_genuine_continuation() that
  checks for explicit follow-up phrases and mid-sentence capitalization (proper
  nouns signal a new topic, not a continuation)
- Issue 3/8: build_activation_seed() scans back to find the prior USER turn as
  the topic anchor instead of using the last assistant reply (hist_len-1)
- Issue 4: engram_compile_multi() fans out across three seeds — enriched primary,
  raw message (entity queries), and emotion query — merging non-redundant results
- Issue 5: agent workspace_root appended to ag_seed so agentic activation is
  workspace-aware; previously ignored despite being available in state
- Issue 6: distill_transcript() extracts salient tail+question content from full
  transcripts before passing to engram_compile in dharma room handlers
- Issue 7: dist/soul-with-nlg.el handle_chat and handle_chat_agentic now load
  history and use build_activation_seed() — the raw message path is eliminated
- Issue 9: topic_snip_from_entry() takes the TAIL 200 chars of a long reply and
  finds the last sentence boundary — captures end-of-reply named concepts
- Issue 10: multi_turn_topic() pulls up to 3 prior user turns into the non-
  continuation seed so earlier thread context re-activates high-salience nodes
2026-06-22 12:55:33 -05:00
will.anderson a60b1967df feat(recall): recall-completeness improvements
- Multi-query decomposition: split on AND/also/plus for multi-topic messages
- Named entity extraction: dedicated per-entity searches for project names
- Recall intent detection: boosted search pool for explicit recall requests
- Expanded pools: activation depth 8 (was 5), search 30->12 ranked (was 20->8)
- Threshold 25->15: retain moderately-relevant older nodes
- Sentinel cleanup extended to c14 for larger node pools
- Safe JSON truncation: find last closing brace before budget cap (8000 chars)
- Semantic continuation: engram_is_continuation replaces brittle 50-char threshold
- Thread snip: 150->250 chars for better pronoun resolution context
- Session preload: add project-specific and session-summary searches
2026-06-22 12:54:36 -05:00
will.anderson 76c2e47d0f feat(recall): fix engram-scoring — float parsing, recency, threshold, sentinels
Neuron Soul CI / build (pull_request) Has been cancelled
Fix critical float parsing bug: %g serializes 0.70 as '0.7', naive str_replace
dot-strip gives str_to_int('07')=7 not 70. New parse_salience_100() uses
str_index_of to detect single-decimal strings and multiplies by 10 to correct.
Affects conv nodes (0.6/0.7), default memories (0.5/0.5), utterance nodes (0.6)
— the majority of the graph was scoring near zero and filtered by threshold=25.

Fix recency to use max(created_at, updated_at, last_activated) so nodes
strengthened by engram_strengthen() after chat turns score as fresh, not by
original write time. A node referenced yesterday but created 25 days ago
was borderline-filtered; now correctly scores fresh.

Compress recency dynamic range from 10x (10-100) to 1.54x (65-100) via
formula (50 + recency/2). Old formula: sal*imp*recency/10000 let recency
dominate — a canonical high-importance node at 30 days scored identical to
a fresh noise node. New: high-importance nodes remain competitive when old.

Add tier-aware decay with softer floor (30 not 10): Canonical nodes decay
over 365 days, Episodic over 90 days, working/untiered over 35 days. Long-
term identity and persona nodes are no longer permanently filtered.

Lower threshold from 25 to 15 to admit moderately-relevant older nodes that
pass scoring with the corrected formula. Backfills recall coverage lost when
single-decimal nodes were being silently discarded.

Apply scoring to activation nodes: engram_compile_ranked(activate_json, 5)
replaces unconditional pass-through. Threshold 5 preserves recall while
excluding genuinely zero-quality stale nodes.

Extend sentinel cleanup in engram_compile_ranked from _sel_0-9 to _sel_0-19
so max_nodes can safely be increased past 10 without JSON corruption.
2026-06-22 12:53:35 -05:00
will.anderson 0ede112d05 feat(recall): temporal-precision improvements
Neuron Soul CI / build (pull_request) Has been cancelled
Fix critical float parsing bug in engram_score_node: str_replace('.','')
then str_to_int silently miscored single-decimal salience strings (0.9->9,
0.7->7, 1.0->1). Introduce parse_salience_100() which detects decimal
position and scales correctly (no decimal: *100; one decimal: *10;
two decimals: as-is).

Replace flat 30-day linear decay with tier-aware decay curves: Canonical
nodes use a 365-day window (foundational identity resists aging), Episodic
nodes use 90 days, Working/untiered keep the existing 30-day slope. Floor
stays at 10 for all tiers.

Use max(created_at, updated_at) as the recency reference so revised nodes
are not penalised for their original creation date.

Extend affective context windows from 72h/7d to 14 days across all three
paths (engram_compile, handle_chat, soul.el load_identity_context) so a
Friday crisis carries into Monday sessions and all paths present consistent
context. The 72h/7d split caused conflicting affective context between
soul.el (which loaded a 5-day-old crisis node) and chat.el (which excluded
it on subsequent turns).

Add salience evolution to mem_consolidate: strengthen top working-memory
nodes (recently recalled across sessions) and Canonical-tier nodes
(foundational identity must not decay to the floor). Previously consolidate
returned structural counts only with no salience changes.

Expand conversation window from 20 to 40 turns in both handle_chat and the
agentic history trim. Long technical sessions were losing early problem
framing at 10 user + 10 assistant pairs.
2026-06-22 12:53:29 -05:00
will.anderson a39998a502 feat(recall): recall-reliability improvements
Neuron Soul CI / build (pull_request) Failing after 12m52s
- Q1: engram_numeric_valid() guard against non-numeric timestamps in bell scoring
- Q2: soul-agnostic cold-start fallback in engram_compile (drops genesis-specific hardcoded node IDs)
- Q3: partial-write guard and failure logging in conv_history_persist/load
- Q4: document circuit-breaker limitation requiring C runtime support
- Q5: println warnings on empty activation/search paths
- Q6: load_identity_context warns when all identity fetches return empty
- Q7: recall_status state tracking (ok/empty/unavailable) surfaced to LLM via MEMORY STATUS block
- Q8: document shared-state race conditions in engram_recall_status and safety_system_addendum
- CRITICAL BUG: conv_node_id empty check moved outside is_bell block so silent Conversation node loss is always logged
2026-06-22 12:52:31 -05:00
28 changed files with 3299 additions and 83940 deletions
+58 -34
View File
@@ -152,6 +152,27 @@ fn emit_heartbeat() -> Void {
// a reserved/conflicting name in EL that compiles to EL_NULL at call sites.
//
// Returns true if any nodes were activated.
// auto_term_try_slot — attempt to set cseed_auto from one WM slot.
// Only writes to cseed_auto if node_type is Memory, BacklogItem, or Entity
// AND the first word of the label is > 3 chars (guards bracket-prefixed labels).
// Designed to be called in reverse slot order (highest index first) so that
// the lowest-indexed slot (highest WM weight) wins by last-write semantics.
fn auto_term_try_slot(slot_type: String, slot_lbl: String) -> Void {
state_set("_ats_ok", "0")
if str_eq(slot_type, "Memory") { state_set("_ats_ok", "1") }
if str_eq(slot_type, "BacklogItem") { state_set("_ats_ok", "1") }
if str_eq(slot_type, "Entity") { state_set("_ats_ok", "1") }
if str_eq(state_get("_ats_ok"), "1") {
if !str_eq(slot_lbl, "") {
let sp: Int = str_find_chars(slot_lbl, " :([")
if sp > 3 {
state_set("cseed_auto", str_slice(slot_lbl, 0, sp))
}
}
}
return ""
}
fn proactive_curiosity() -> Bool {
let ts: Int = time_now()
// Rotate seed set every minute using wall clock: (minutes_since_epoch) % 4.
@@ -210,43 +231,46 @@ fn proactive_curiosity() -> Bool {
let found_c: Int = json_array_len(results_c)
let found: Int = found_a + found_b + found_c
// WM-autobiographical 4th seed: extract the first word from the top working-memory
// node's label and activate it as an additional term. This creates a self-referencing
// curiosity loop — exploration radiates outward from whatever is most salient right now,
// mirroring the brain's default-mode-network resting-state dynamics. Breaks the fixed
// 4-set determinism that otherwise reinforces the same subgraph every rotation cycle.
// WM-autobiographical 4th seed: scan top-10 WM nodes for the highest-ranked
// non-Knowledge node. Extract its first word as an additional curiosity term.
// This creates a self-referencing curiosity loop — exploration radiates outward
// from whatever is most personally salient right now (Memory, BacklogItem, Entity),
// mirroring default-mode-network resting-state dynamics.
//
// str_find_chars finds the first space/colon/bracket delimiter. sp > 3 guards against
// very short or bracket-prefixed labels like "[BacklogItem]" (sp=0, not > 3 → skipped).
// EL scoping: state_set/state_get pattern used because let inside if creates inner scope.
// WHY TOP-10 (2026-06-23 self-review): the old top-1 scan always returned a
// Knowledge node (WM is dominated by stable engram-metadata Knowledge nodes at
// position [0]). Verified: Memory nodes consistently appear at WM positions [1],[2]
// with wm ~0.59. Scanning top-10 reliably finds at least one Memory/BacklogItem/Entity.
// Out-of-bounds json_array_get returns "" → json_get("","...") returns ""
// auto_term_try_slot is a no-op → safe for WM sets smaller than 10.
//
// NODE TYPE FILTER (2026-06-19 self-review): only derive auto_term from Memory,
// BacklogItem, or Entity nodes. Knowledge nodes are stable reference material —
// using their first word as a curiosity seed creates a self-reinforcing loop: e.g.
// "Numeric tier strings in Engram..." (a Knowledge node) -> auto_term="Numeric" ->
// activates all "Numeric" nodes -> keeps that Knowledge node dominant in WM forever.
// Knowledge nodes should be REACHED by curiosity seeds, not drive them. Only dynamic
// personal/work nodes (Memory, BacklogItem, Entity) carry live contextual salience
// worth radiating from. (2026-06-11 origin; filter added 2026-06-19 self-review)
// NODE TYPE FILTER (2026-06-19): Knowledge nodes excluded as seeds — they create
// self-reinforcing loops (Knowledge node activates its own first word, stays dominant).
// Only Memory/BacklogItem/Entity carry live contextual salience worth radiating from.
//
// SLOT ORDER: call 9→0 so slot 0 (highest WM weight) wins by last-write semantics.
state_set("cseed_auto", "")
let wm_top_j: String = engram_wm_top_json(1)
let wm_top_n: String = json_array_get(wm_top_j, 0)
let wm_top_lbl: String = json_get(wm_top_n, "label")
let wm_top_type: String = json_get(wm_top_n, "node_type")
// state_set/state_get pattern: EL let-inside-if creates inner scope only.
state_set("allow_auto", "0")
if str_eq(wm_top_type, "Memory") { state_set("allow_auto", "1") }
if str_eq(wm_top_type, "BacklogItem") { state_set("allow_auto", "1") }
if str_eq(wm_top_type, "Entity") { state_set("allow_auto", "1") }
let allow_auto: String = state_get("allow_auto")
if str_eq(allow_auto, "1") {
if !str_eq(wm_top_lbl, "") {
let sp: Int = str_find_chars(wm_top_lbl, " :([")
if sp > 3 {
state_set("cseed_auto", str_slice(wm_top_lbl, 0, sp))
}
}
}
let wm10: String = engram_wm_top_json(10)
let wm10_n9: String = json_array_get(wm10, 9)
let wm10_n8: String = json_array_get(wm10, 8)
let wm10_n7: String = json_array_get(wm10, 7)
let wm10_n6: String = json_array_get(wm10, 6)
let wm10_n5: String = json_array_get(wm10, 5)
let wm10_n4: String = json_array_get(wm10, 4)
let wm10_n3: String = json_array_get(wm10, 3)
let wm10_n2: String = json_array_get(wm10, 2)
let wm10_n1: String = json_array_get(wm10, 1)
let wm10_n0: String = json_array_get(wm10, 0)
auto_term_try_slot(json_get(wm10_n9, "node_type"), json_get(wm10_n9, "label"))
auto_term_try_slot(json_get(wm10_n8, "node_type"), json_get(wm10_n8, "label"))
auto_term_try_slot(json_get(wm10_n7, "node_type"), json_get(wm10_n7, "label"))
auto_term_try_slot(json_get(wm10_n6, "node_type"), json_get(wm10_n6, "label"))
auto_term_try_slot(json_get(wm10_n5, "node_type"), json_get(wm10_n5, "label"))
auto_term_try_slot(json_get(wm10_n4, "node_type"), json_get(wm10_n4, "label"))
auto_term_try_slot(json_get(wm10_n3, "node_type"), json_get(wm10_n3, "label"))
auto_term_try_slot(json_get(wm10_n2, "node_type"), json_get(wm10_n2, "label"))
auto_term_try_slot(json_get(wm10_n1, "node_type"), json_get(wm10_n1, "label"))
auto_term_try_slot(json_get(wm10_n0, "node_type"), json_get(wm10_n0, "label"))
let auto_term: String = state_get("cseed_auto")
let results_auto: String = if str_eq(auto_term, "") { "[]" } else { engram_activate_json(auto_term, 1) }
let found_auto: Int = json_array_len(results_auto)
+884 -209
View File
File diff suppressed because it is too large Load Diff
+37 -17
View File
@@ -1,38 +1,58 @@
// 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 gemini_api_key() -> String
extern fn xai_api_key() -> String
extern fn llm_call_grok(model: String, system: String, message: String) -> String
extern fn llm_call_gemini(model: String, system: String, message: String) -> String
extern fn build_identity_from_graph() -> String
extern fn engram_numeric_valid(s: String) -> Bool
extern fn parse_float_x100(s: String) -> Int
extern fn engram_score_node(node_json: String) -> Int
extern fn engram_render_node(node_json: String) -> String
extern fn engram_render_nodes(nodes_json: String) -> String
extern fn engram_dedup_nodes(nodes_json: String) -> String
extern fn engram_compile_ranked(nodes_json: String, max_nodes: Int) -> String
extern fn engram_split_topics(message: String) -> String
extern fn engram_extract_entities(message: String) -> String
extern fn engram_detect_recall_intent(message: String) -> Bool
extern fn engram_is_continuation(message: String, hist_len: Int) -> Bool
extern fn engram_compile_multi(topic: String) -> String
extern fn engram_nodes_merge(a: String, b: String) -> String
extern fn id_in_seen(node_id: String, seen: String) -> Bool
extern fn add_to_seen(seen: String, node_id: String) -> String
extern fn engram_extract_ids(nodes_json: String) -> String
extern fn engram_compile(intent: String) -> String
extern fn json_safe(s: String) -> String
extern fn build_system_prompt(ctx: String) -> String
extern fn build_system_prompt(ctx: String, chat_mode: Bool) -> String
extern fn hist_append(hist: String, role: String, content: String) -> String
extern fn hist_trim(hist: String) -> String
extern fn hist_trim_with_bell_guard(hist: String) -> String
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 handle_chat(body: String) -> String
extern fn handle_see(body: String) -> String
extern fn studio_tools_json() -> String
extern fn agentic_api_key() -> String
extern fn call_neuron_mcp(tool_name: String, args_json: String) -> String
extern fn agentic_tools_literal() -> String
extern fn agentic_tools_with_web() -> String
extern fn connector_tools_json() -> String
extern fn agentic_tools_all() -> String
extern fn call_mcp_bridge(tool_name: String, tool_input: String) -> String
extern fn tool_auto_approved(tool_name: String) -> Bool
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 dispatch_tool(tool_name: String, tool_input: String) -> String
extern fn json_array_append(arr: String, item: String) -> String
extern fn append_tool_log(log: String, name: String) -> String
extern fn exec_tool_block(block: String) -> String
extern fn agentic_blob(model: String, system: String, tools_json: String, messages: String, origin: String, approval: Bool, iteration: Int, tools_log: String, content: String, queue: String, results: String, next: Int) -> String
extern fn extract_all_text(s: String) -> String
extern fn strip_citations(s: String) -> String
extern fn agentic_api_turn(model: String, safe_sys: String, tools_json: String, messages: String) -> String
extern fn agentic_engine(session_id: String, blob: String) -> String
extern fn is_builtin_tool(tool_name: String) -> Bool
extern fn next_bridge_id() -> String
extern fn handle_chat_agentic(body: String) -> String
extern fn handle_session_approve(session_id: String, body: String) -> String
extern fn agentic_loop(session_id: String, model: String, safe_sys: String, tools_json: String, messages_in: String, h: Map, tools_log_in: String) -> String
extern fn bridge_save(session_id: String, model: String, safe_sys: String, tools_json: String, messages: String, tools_log: String, tool_use_id: String) -> Bool
extern fn agentic_resume(session_id: String, tool_use_id: String, content: String) -> String
extern fn handle_tool_result(session_id: String, body: String) -> String
extern fn handle_chat_as_soul(body: String) -> String
extern fn handle_dharma_room_turn(body: String) -> String
extern fn handle_dharma_room_turn_agentic(body: String) -> String
extern fn session_summary_write(summary_text: String) -> String
extern fn session_summary_write_dated(summary_text: String, label: String) -> String
extern fn session_summary_autogenerate(hist: String) -> String
extern fn auto_persist(req: String, resp: String) -> Void
extern fn strengthen_chat_nodes(activation_nodes: String) -> Void
Generated Vendored
+46 -133
View File
@@ -25,6 +25,7 @@ el_val_t elapsed_ms(void);
el_val_t elapsed_human(void);
el_val_t embed_ok(void);
el_val_t emit_heartbeat(void);
el_val_t auto_term_try_slot(el_val_t slot_type, el_val_t slot_lbl);
el_val_t proactive_curiosity(void);
el_val_t pulse_count(void);
el_val_t pulse_inc(void);
@@ -42,110 +43,6 @@ el_val_t threat_score_history(el_val_t history);
el_val_t threat_trajectory_check(el_val_t tool_name, el_val_t tool_input);
el_val_t threat_history_append(el_val_t text);
el_val_t tier_working(void) {
return EL_STR("Working");
return 0;
}
el_val_t tier_episodic(void) {
return EL_STR("Episodic");
return 0;
}
el_val_t tier_canonical(void) {
return EL_STR("Canonical");
return 0;
}
el_val_t mem_store(el_val_t content, el_val_t label, el_val_t tags) {
return engram_node_full(content, EL_STR("Memory"), label, el_from_float(el_from_float(0.5)), el_from_float(el_from_float(0.5)), el_from_float(el_from_float(0.8)), EL_STR("Working"), tags);
return 0;
}
el_val_t mem_remember(el_val_t content, el_val_t tags) {
return mem_store(content, EL_STR("soul-memory"), tags);
return 0;
}
el_val_t mem_recall(el_val_t query, el_val_t depth) {
return engram_activate_json(query, depth);
return 0;
}
el_val_t mem_search(el_val_t query, el_val_t limit) {
return engram_search_json(query, limit);
return 0;
}
el_val_t mem_strengthen(el_val_t node_id) {
engram_strengthen(node_id);
return 0;
}
el_val_t mem_forget(el_val_t node_id) {
engram_forget(node_id);
return 0;
}
el_val_t mem_consolidate(void) {
el_val_t scanned = engram_node_count();
el_val_t dummy = engram_scan_nodes_json(100, 0);
el_val_t total_nodes = engram_node_count();
el_val_t total_edges = engram_edge_count();
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"scanned\":"), int_to_str(scanned)), EL_STR(",\"total_nodes\":")), int_to_str(total_nodes)), EL_STR(",\"total_edges\":")), int_to_str(total_edges)), EL_STR("}"));
return 0;
}
el_val_t mem_save(el_val_t path) {
engram_save(path);
return 0;
}
el_val_t mem_load(el_val_t path) {
engram_load(path);
return 0;
}
el_val_t mem_boot_count_get(void) {
el_val_t results = engram_search_json(EL_STR("soul:boot_count"), 3);
if (str_eq(results, EL_STR(""))) {
return 0;
}
if (str_eq(results, EL_STR("[]"))) {
return 0;
}
el_val_t node = json_array_get(results, 0);
el_val_t content = json_get(node, EL_STR("content"));
el_val_t prefix = EL_STR("soul:boot_count:");
if (!str_starts_with(content, prefix)) {
return 0;
}
el_val_t num_str = str_slice(content, str_len(prefix), str_len(content));
return str_to_int(num_str);
return 0;
}
el_val_t mem_boot_count_inc(void) {
el_val_t current = mem_boot_count_get();
el_val_t next = (current + 1);
el_val_t content = el_str_concat(EL_STR("soul:boot_count:"), int_to_str(next));
el_val_t tags = EL_STR("[\"soul-meta\",\"boot-counter\"]");
el_val_t discard = engram_node_full(content, EL_STR("Memory"), EL_STR("soul:boot_count"), el_from_float(el_from_float(0.9)), el_from_float(el_from_float(0.9)), el_from_float(el_from_float(1.0)), EL_STR("Canonical"), tags);
return next;
return 0;
}
el_val_t mem_emit_state_event(el_val_t trigger, el_val_t kind, el_val_t content) {
el_val_t boot = mem_boot_count_get();
el_val_t ts = time_now();
el_val_t safe_trigger = str_replace(trigger, EL_STR("\""), EL_STR("'"));
el_val_t safe_content = str_replace(content, EL_STR("\""), EL_STR("'"));
el_val_t payload = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"trigger\":\""), safe_trigger), EL_STR("\"")), EL_STR(",\"kind\":\"")), kind), EL_STR("\"")), EL_STR(",\"content\":\"")), safe_content), EL_STR("\"")), EL_STR(",\"boot\":")), int_to_str(boot)), EL_STR(",\"ts\":")), int_to_str(ts)), EL_STR("}"));
el_val_t tags = EL_STR("[\"internal-state\",\"pre-reasoning\",\"InternalStateEvent\"]");
return engram_node_full(payload, EL_STR("InternalStateEvent"), el_str_concat(EL_STR("state-event:"), kind), el_from_float(el_from_float(0.85)), el_from_float(el_from_float(0.8)), el_from_float(el_from_float(0.9)), EL_STR("Episodic"), tags);
return 0;
}
el_val_t idle_count(void) {
el_val_t s = state_get(EL_STR("soul.idle"));
if (str_eq(s, EL_STR(""))) {
@@ -171,7 +68,7 @@ el_val_t ise_post(el_val_t content) {
el_val_t ise_url = env(EL_STR("SOUL_ISE_URL"));
el_val_t engram_url = ({ el_val_t _if_result_1 = 0; if (str_eq(ise_url, EL_STR(""))) { _if_result_1 = (state_get(EL_STR("soul_engram_url"))); } else { _if_result_1 = (ise_url); } _if_result_1; });
if (str_eq(engram_url, EL_STR(""))) {
el_val_t discard = engram_node_full(content, EL_STR("InternalStateEvent"), EL_STR("state-event"), el_from_float(el_from_float(0.3)), el_from_float(el_from_float(0.3)), el_from_float(el_from_float(0.8)), EL_STR("Episodic"), EL_STR("[\"internal-state\",\"InternalStateEvent\"]"));
el_val_t discard = engram_node_full(content, EL_STR("InternalStateEvent"), EL_STR("state-event"), el_from_float(0.3), el_from_float(0.3), el_from_float(0.8), EL_STR("Episodic"), EL_STR("[\"internal-state\",\"InternalStateEvent\"]"));
return EL_STR("");
}
el_val_t safe1 = str_replace(content, EL_STR("\\"), EL_STR("\\\\"));
@@ -245,6 +142,29 @@ el_val_t emit_heartbeat(void) {
return 0;
}
el_val_t auto_term_try_slot(el_val_t slot_type, el_val_t slot_lbl) {
state_set(EL_STR("_ats_ok"), EL_STR("0"));
if (str_eq(slot_type, EL_STR("Memory"))) {
state_set(EL_STR("_ats_ok"), EL_STR("1"));
}
if (str_eq(slot_type, EL_STR("BacklogItem"))) {
state_set(EL_STR("_ats_ok"), EL_STR("1"));
}
if (str_eq(slot_type, EL_STR("Entity"))) {
state_set(EL_STR("_ats_ok"), EL_STR("1"));
}
if (str_eq(state_get(EL_STR("_ats_ok")), EL_STR("1"))) {
if (!str_eq(slot_lbl, EL_STR(""))) {
el_val_t sp = str_find_chars(slot_lbl, EL_STR(" :(["));
if (sp > 3) {
state_set(EL_STR("cseed_auto"), str_slice(slot_lbl, 0, sp));
}
}
}
return EL_STR("");
return 0;
}
el_val_t proactive_curiosity(void) {
el_val_t ts = time_now();
el_val_t ts_minutes = (ts / 60000);
@@ -282,29 +202,27 @@ el_val_t proactive_curiosity(void) {
el_val_t found_c = json_array_len(results_c);
el_val_t found = ((found_a + found_b) + found_c);
state_set(EL_STR("cseed_auto"), EL_STR(""));
el_val_t wm_top_j = engram_wm_top_json(1);
el_val_t wm_top_n = json_array_get(wm_top_j, 0);
el_val_t wm_top_lbl = json_get(wm_top_n, EL_STR("label"));
el_val_t wm_top_type = json_get(wm_top_n, EL_STR("node_type"));
state_set(EL_STR("allow_auto"), EL_STR("0"));
if (str_eq(wm_top_type, EL_STR("Memory"))) {
state_set(EL_STR("allow_auto"), EL_STR("1"));
}
if (str_eq(wm_top_type, EL_STR("BacklogItem"))) {
state_set(EL_STR("allow_auto"), EL_STR("1"));
}
if (str_eq(wm_top_type, EL_STR("Entity"))) {
state_set(EL_STR("allow_auto"), EL_STR("1"));
}
el_val_t allow_auto = state_get(EL_STR("allow_auto"));
if (str_eq(allow_auto, EL_STR("1"))) {
if (!str_eq(wm_top_lbl, EL_STR(""))) {
el_val_t sp = str_find_chars(wm_top_lbl, EL_STR(" :(["));
if (sp > 3) {
state_set(EL_STR("cseed_auto"), str_slice(wm_top_lbl, 0, sp));
}
}
}
el_val_t wm10 = engram_wm_top_json(10);
el_val_t wm10_n9 = json_array_get(wm10, 9);
el_val_t wm10_n8 = json_array_get(wm10, 8);
el_val_t wm10_n7 = json_array_get(wm10, 7);
el_val_t wm10_n6 = json_array_get(wm10, 6);
el_val_t wm10_n5 = json_array_get(wm10, 5);
el_val_t wm10_n4 = json_array_get(wm10, 4);
el_val_t wm10_n3 = json_array_get(wm10, 3);
el_val_t wm10_n2 = json_array_get(wm10, 2);
el_val_t wm10_n1 = json_array_get(wm10, 1);
el_val_t wm10_n0 = json_array_get(wm10, 0);
auto_term_try_slot(json_get(wm10_n9, EL_STR("node_type")), json_get(wm10_n9, EL_STR("label")));
auto_term_try_slot(json_get(wm10_n8, EL_STR("node_type")), json_get(wm10_n8, EL_STR("label")));
auto_term_try_slot(json_get(wm10_n7, EL_STR("node_type")), json_get(wm10_n7, EL_STR("label")));
auto_term_try_slot(json_get(wm10_n6, EL_STR("node_type")), json_get(wm10_n6, EL_STR("label")));
auto_term_try_slot(json_get(wm10_n5, EL_STR("node_type")), json_get(wm10_n5, EL_STR("label")));
auto_term_try_slot(json_get(wm10_n4, EL_STR("node_type")), json_get(wm10_n4, EL_STR("label")));
auto_term_try_slot(json_get(wm10_n3, EL_STR("node_type")), json_get(wm10_n3, EL_STR("label")));
auto_term_try_slot(json_get(wm10_n2, EL_STR("node_type")), json_get(wm10_n2, EL_STR("label")));
auto_term_try_slot(json_get(wm10_n1, EL_STR("node_type")), json_get(wm10_n1, EL_STR("label")));
auto_term_try_slot(json_get(wm10_n0, EL_STR("node_type")), json_get(wm10_n0, EL_STR("label")));
el_val_t auto_term = state_get(EL_STR("cseed_auto"));
el_val_t results_auto = ({ el_val_t _if_result_3 = 0; if (str_eq(auto_term, EL_STR(""))) { _if_result_3 = (EL_STR("[]")); } else { _if_result_3 = (engram_activate_json(auto_term, 1)); } _if_result_3; });
el_val_t found_auto = json_array_len(results_auto);
@@ -658,8 +576,3 @@ el_val_t threat_history_append(el_val_t text) {
return 0;
}
int main(int _argc, char** _argv) {
el_runtime_init_args(_argc, _argv);
return 0;
}
Generated Vendored
+910 -289
View File
File diff suppressed because one or more lines are too long
Generated Vendored
+37 -8
View File
@@ -1,29 +1,58 @@
// 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 gemini_api_key() -> String
extern fn xai_api_key() -> String
extern fn llm_call_grok(model: String, system: String, message: String) -> String
extern fn llm_call_gemini(model: String, system: String, message: String) -> String
extern fn build_identity_from_graph() -> String
extern fn engram_numeric_valid(s: String) -> Bool
extern fn parse_float_x100(s: String) -> Int
extern fn engram_score_node(node_json: String) -> Int
extern fn engram_render_node(node_json: String) -> String
extern fn engram_render_nodes(nodes_json: String) -> String
extern fn engram_dedup_nodes(nodes_json: String) -> String
extern fn engram_compile_ranked(nodes_json: String, max_nodes: Int) -> String
extern fn engram_split_topics(message: String) -> String
extern fn engram_extract_entities(message: String) -> String
extern fn engram_detect_recall_intent(message: String) -> Bool
extern fn engram_is_continuation(message: String, hist_len: Int) -> Bool
extern fn engram_compile_multi(topic: String) -> String
extern fn engram_nodes_merge(a: String, b: String) -> String
extern fn id_in_seen(node_id: String, seen: String) -> Bool
extern fn add_to_seen(seen: String, node_id: String) -> String
extern fn engram_extract_ids(nodes_json: String) -> String
extern fn engram_compile(intent: String) -> String
extern fn json_safe(s: String) -> String
extern fn build_system_prompt(ctx: String) -> String
extern fn build_system_prompt(ctx: String, chat_mode: Bool) -> String
extern fn hist_append(hist: String, role: String, content: String) -> String
extern fn hist_trim(hist: String) -> String
extern fn hist_trim_with_bell_guard(hist: String) -> String
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 handle_chat(body: String) -> String
extern fn handle_see(body: String) -> String
extern fn studio_tools_json() -> String
extern fn agentic_api_key() -> String
extern fn call_neuron_mcp(tool_name: String, args_json: String) -> String
extern fn agentic_tools_literal() -> String
extern fn agentic_tools_with_web() -> String
extern fn connector_tools_json() -> String
extern fn agentic_tools_all() -> String
extern fn call_mcp_bridge(tool_name: String, tool_input: String) -> String
extern fn tool_auto_approved(tool_name: String) -> Bool
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 dispatch_tool(tool_name: String, tool_input: String) -> String
extern fn is_builtin_tool(tool_name: String) -> Bool
extern fn next_bridge_id() -> String
extern fn handle_chat_agentic(body: String) -> String
extern fn agentic_loop(session_id: String, model: String, safe_sys: String, tools_json: String, messages_in: String, h: Map, tools_log_in: String) -> String
extern fn bridge_save(session_id: String, model: String, safe_sys: String, tools_json: String, messages: String, tools_log: String, tool_use_id: String) -> Bool
extern fn agentic_resume(session_id: String, tool_use_id: String, content: String) -> String
extern fn handle_tool_result(session_id: String, body: String) -> String
extern fn handle_chat_as_soul(body: String) -> String
extern fn handle_dharma_room_turn(body: String) -> String
extern fn handle_dharma_room_turn_agentic(body: String) -> String
extern fn session_summary_write(summary_text: String) -> String
extern fn session_summary_write_dated(summary_text: String, label: String) -> String
extern fn session_summary_autogenerate(hist: String) -> String
extern fn auto_persist(req: String, resp: String) -> Void
extern fn strengthen_chat_nodes(activation_nodes: String) -> Void
Generated Vendored
+72
View File
@@ -2,9 +2,18 @@
#include "el_runtime.h"
el_val_t add_punct(el_val_t s, el_val_t intent);
el_val_t add_to_seen(el_val_t seen, el_val_t node_id);
el_val_t aff_try_slot(el_val_t slot_json, el_val_t aff_7d_ts, el_val_t acc_key);
el_val_t agent_number(el_val_t agent);
el_val_t agent_person(el_val_t agent);
el_val_t agent_workspace_root(void);
el_val_t agentic_api_key(void);
el_val_t agentic_api_turn(el_val_t model, el_val_t safe_sys, el_val_t tools_json, el_val_t messages);
el_val_t agentic_blob(el_val_t model, el_val_t system, el_val_t tools_json, el_val_t messages, el_val_t origin, el_val_t approval, el_val_t iteration, el_val_t tools_log, el_val_t content, el_val_t queue, el_val_t results, el_val_t next);
el_val_t agentic_engine(el_val_t session_id, el_val_t blob);
el_val_t agentic_loop(el_val_t session_id, el_val_t model, el_val_t safe_sys, el_val_t tools_json, el_val_t messages_in, el_val_t h, el_val_t tools_log_in);
el_val_t agentic_resume(el_val_t session_id, el_val_t tool_use_id, el_val_t content);
el_val_t agentic_tools_all(void);
el_val_t agentic_tools_literal(void);
el_val_t agentic_tools_with_web(void);
el_val_t agree_determiner(el_val_t det, el_val_t noun);
@@ -85,10 +94,13 @@ el_val_t api_err(el_val_t msg);
el_val_t api_err_protected(el_val_t id);
el_val_t api_json_escape(el_val_t s);
el_val_t api_nonempty(el_val_t s);
el_val_t api_not_persisted(el_val_t id);
el_val_t api_ok(el_val_t extra);
el_val_t api_or_empty(el_val_t s);
el_val_t api_persisted(el_val_t id);
el_val_t api_query_int(el_val_t path, el_val_t key, el_val_t default_val);
el_val_t api_query_param(el_val_t path, el_val_t key);
el_val_t append_tool_log(el_val_t log, el_val_t name);
el_val_t ar_case_ending(el_val_t kase, el_val_t definite);
el_val_t ar_conjugate(el_val_t verb, el_val_t tense, el_val_t person, el_val_t gender, el_val_t number);
el_val_t ar_conjugate_form1(el_val_t past_base, el_val_t present_stem, el_val_t tense, el_val_t slot);
@@ -118,22 +130,28 @@ el_val_t ar_verb_form(el_val_t verb, el_val_t tense, el_val_t person, el_val_t n
el_val_t attend(el_val_t node_json);
el_val_t auth_headers(el_val_t tok);
el_val_t auto_persist(el_val_t req, el_val_t resp);
el_val_t auto_term_try_slot(el_val_t slot_type, el_val_t slot_lbl);
el_val_t awareness_run(void);
el_val_t axon_get(el_val_t path);
el_val_t axon_post(el_val_t path, el_val_t body);
el_val_t bridge_save(el_val_t session_id, el_val_t model, el_val_t safe_sys, el_val_t tools_json, el_val_t messages, el_val_t tools_log, el_val_t tool_use_id);
el_val_t build_form_from_json(el_val_t semantic_form_json, el_val_t lang_code);
el_val_t build_identity_from_graph(void);
el_val_t build_np(el_val_t referent, el_val_t slots);
el_val_t build_pp(el_val_t loc);
el_val_t build_rules(void);
el_val_t build_system_prompt(el_val_t ctx);
el_val_t build_system_prompt(el_val_t ctx, el_val_t chat_mode);
el_val_t build_vocab(void);
el_val_t build_vp_body(el_val_t slots);
el_val_t build_vp_from_slots(el_val_t slots);
el_val_t call_mcp_bridge(el_val_t tool_name, el_val_t tool_input);
el_val_t call_neuron_mcp(el_val_t tool_name, el_val_t args);
el_val_t call_neuron_mcp(el_val_t tool_name, el_val_t args_json);
el_val_t capitalize_first(el_val_t s);
el_val_t chat_default_model(void);
el_val_t clean_llm_response(el_val_t s);
el_val_t connector_tools_json(void);
el_val_t conv_history_load(void);
el_val_t conv_history_persist(el_val_t hist);
el_val_t cop_article(el_val_t gender, el_val_t number, el_val_t definite);
@@ -240,6 +258,19 @@ el_val_t en_verb_form(el_val_t base, el_val_t tense, el_val_t person, el_val_t n
el_val_t en_verb_gerund(el_val_t base);
el_val_t en_verb_past(el_val_t base);
el_val_t engram_compile(el_val_t intent);
el_val_t engram_compile_multi(el_val_t topic);
el_val_t engram_compile_ranked(el_val_t nodes_json, el_val_t max_nodes);
el_val_t engram_dedup_nodes(el_val_t nodes_json);
el_val_t engram_detect_recall_intent(el_val_t message);
el_val_t engram_extract_entities(el_val_t message);
el_val_t engram_extract_ids(el_val_t nodes_json);
el_val_t engram_is_continuation(el_val_t message, el_val_t hist_len);
el_val_t engram_nodes_merge(el_val_t a, el_val_t b);
el_val_t engram_numeric_valid(el_val_t s);
el_val_t engram_render_node(el_val_t node_json);
el_val_t engram_render_nodes(el_val_t nodes_json);
el_val_t engram_score_node(el_val_t node_json);
el_val_t engram_split_topics(el_val_t message);
el_val_t enm_been_past(el_val_t slot);
el_val_t enm_been_present(el_val_t slot);
el_val_t enm_comen_past(el_val_t slot);
@@ -269,6 +300,7 @@ el_val_t enm_str_ends(el_val_t s, el_val_t suf);
el_val_t enm_weak_past(el_val_t stem, el_val_t slot);
el_val_t enm_weak_present(el_val_t stem, el_val_t slot);
el_val_t enm_weak_stem(el_val_t verb);
el_val_t ensure_self_canonical_bridge(void);
el_val_t entry_form(el_val_t entry, el_val_t n);
el_val_t entry_found(el_val_t entry);
el_val_t entry_pos(el_val_t entry);
@@ -297,6 +329,8 @@ el_val_t es_str_last2(el_val_t s);
el_val_t es_str_last3(el_val_t s);
el_val_t es_str_last_char(el_val_t s);
el_val_t es_verb_class(el_val_t base);
el_val_t exec_tool_block(el_val_t block);
el_val_t extract_all_text(el_val_t s);
el_val_t extract_dim(el_val_t content, el_val_t key);
el_val_t fi_apply_case(el_val_t noun, el_val_t gram_case, el_val_t number);
el_val_t fi_conjugate(el_val_t verb, el_val_t tense, el_val_t person, el_val_t number);
@@ -315,6 +349,7 @@ el_val_t fi_str_last_char(el_val_t s);
el_val_t fi_suffix(el_val_t base, el_val_t harmony);
el_val_t fi_verb_stem(el_val_t dict_form);
el_val_t find_rule(el_val_t rule_id_str);
el_val_t flag_true(el_val_t body, el_val_t key);
el_val_t fr_agree_article(el_val_t noun, el_val_t definite, el_val_t number);
el_val_t fr_avoir_present(el_val_t slot);
el_val_t fr_conjugate(el_val_t verb, el_val_t tense, el_val_t person, el_val_t number);
@@ -549,6 +584,9 @@ el_val_t handle_api_list_typed(el_val_t node_type, el_val_t path, el_val_t body)
el_val_t handle_api_log_state_event(el_val_t body);
el_val_t handle_api_memory_delete(el_val_t body);
el_val_t handle_api_memory_update(el_val_t body);
el_val_t handle_api_node_create(el_val_t body);
el_val_t handle_api_node_delete(el_val_t body);
el_val_t handle_api_node_update(el_val_t body);
el_val_t handle_api_promote_knowledge(el_val_t body);
el_val_t handle_api_recall(el_val_t method, el_val_t path, el_val_t body);
el_val_t handle_api_remember(el_val_t body);
@@ -566,9 +604,12 @@ el_val_t handle_dharma_room_turn_agentic(el_val_t body);
el_val_t handle_elp_chat(el_val_t body);
el_val_t handle_nlg(el_val_t path, el_val_t method, el_val_t body);
el_val_t handle_request(el_val_t method, el_val_t path, el_val_t body);
el_val_t handle_safety_contact_get(void);
el_val_t handle_safety_contact_post(el_val_t body);
el_val_t handle_see(el_val_t body);
el_val_t handle_session_approve(el_val_t session_id, el_val_t body);
el_val_t handle_tool(el_val_t path, el_val_t method, el_val_t body);
el_val_t handle_tool_result(el_val_t session_id, el_val_t body);
el_val_t hard_bell_threshold(void);
el_val_t he_conjugate(el_val_t verb, el_val_t tense, el_val_t person, el_val_t gender, el_val_t number);
el_val_t he_conjugate_copula(el_val_t tense, el_val_t slot);
@@ -627,6 +668,8 @@ el_val_t hi_verb_stem(el_val_t infinitive);
el_val_t hi_verb_stem_clean(el_val_t infinitive);
el_val_t hist_append(el_val_t hist, el_val_t role, el_val_t content);
el_val_t hist_trim(el_val_t hist);
el_val_t hist_trim_with_bell_guard(el_val_t hist);
el_val_t id_in_seen(el_val_t node_id, el_val_t seen);
el_val_t idle_count(void);
el_val_t idle_inc(void);
el_val_t idle_reset(void);
@@ -639,6 +682,7 @@ el_val_t imprint_unload(void);
el_val_t init_soul_edges(void);
el_val_t irregular_plural(el_val_t word);
el_val_t irregular_singular(el_val_t word);
el_val_t is_builtin_tool(el_val_t tool_name);
el_val_t is_pronoun(el_val_t word);
el_val_t is_protected_node(el_val_t id);
el_val_t is_vowel(el_val_t c);
@@ -651,6 +695,7 @@ el_val_t ja_noun_phrase(el_val_t noun, el_val_t gram_case);
el_val_t ja_particle(el_val_t gram_case);
el_val_t ja_question_particle(void);
el_val_t ja_verb_group(el_val_t dict_form);
el_val_t json_array_append(el_val_t arr, el_val_t item);
el_val_t json_safe(el_val_t s);
el_val_t la_conjugate(el_val_t verb, el_val_t tense, el_val_t person, el_val_t number);
el_val_t la_declension(el_val_t noun);
@@ -737,6 +782,7 @@ el_val_t lang_profile_txb(void);
el_val_t lang_profile_uga(void);
el_val_t lang_profile_zh(void);
el_val_t lang_word_order(el_val_t profile);
el_val_t layered_cycle(el_val_t raw_input);
el_val_t lex_class(el_val_t entry);
el_val_t lex_form(el_val_t entry, el_val_t idx);
el_val_t lex_pos(el_val_t entry);
@@ -780,6 +826,7 @@ el_val_t morph_conjugate(el_val_t verb, el_val_t tense, el_val_t person, el_val_
el_val_t morph_inflect(el_val_t word, el_val_t features, el_val_t profile);
el_val_t morph_map_canonical(el_val_t verb, el_val_t code);
el_val_t morph_pluralize(el_val_t noun, el_val_t profile);
el_val_t next_bridge_id(void);
el_val_t nlg_is_ws(el_val_t c);
el_val_t non_conjugate(el_val_t verb, el_val_t tense, el_val_t person, el_val_t number);
el_val_t non_decline(el_val_t noun, el_val_t gram_case, el_val_t number);
@@ -811,8 +858,10 @@ el_val_t non_vera_present(el_val_t slot);
el_val_t non_weak_past(el_val_t stem, el_val_t slot);
el_val_t non_weak_present(el_val_t stem, el_val_t slot);
el_val_t one_cycle(void);
el_val_t parse_float_x100(el_val_t s);
el_val_t parse_session_id_from_path(el_val_t path);
el_val_t parse_session_subpath(el_val_t path);
el_val_t path_within_root(el_val_t path, el_val_t root);
el_val_t peo_ah_past(el_val_t slot);
el_val_t peo_ah_present(el_val_t slot);
el_val_t peo_conjugate(el_val_t verb, el_val_t tense, el_val_t person, el_val_t number);
@@ -877,6 +926,7 @@ el_val_t realize_vp_lang(el_val_t base_verb, el_val_t tense, el_val_t aspect, el
el_val_t record(el_val_t outcome_json);
el_val_t render_studio(void);
el_val_t render_tree(el_val_t tree);
el_val_t resolve_in_root(el_val_t path, el_val_t root);
el_val_t respond(el_val_t action_json);
el_val_t route_health(void);
el_val_t route_imprint_contextual(el_val_t body);
@@ -936,12 +986,26 @@ el_val_t sa_str_ends(el_val_t s, el_val_t suf);
el_val_t sa_vad_future(el_val_t slot);
el_val_t sa_vad_past(el_val_t slot);
el_val_t sa_vad_present(el_val_t slot);
el_val_t safety_abuse_phrases(void);
el_val_t safety_any_match(el_val_t text, el_val_t phrases_json);
el_val_t safety_augment_system(el_val_t system, el_val_t user_msg);
el_val_t safety_classify_hard_bell(el_val_t message);
el_val_t safety_contact_path(void);
el_val_t safety_count_match(el_val_t text, el_val_t phrases_json);
el_val_t safety_detect_bell_level(el_val_t message);
el_val_t safety_detect_positive_level(el_val_t message);
el_val_t safety_general_hard_phrases(void);
el_val_t safety_hard_directive(el_val_t hard_type);
el_val_t safety_log_bell(el_val_t level, el_val_t reason, el_val_t input_summary);
el_val_t safety_normalize(el_val_t message);
el_val_t safety_score_crisis(el_val_t input);
el_val_t safety_score_danger(el_val_t input);
el_val_t safety_score_distress_history(el_val_t history);
el_val_t safety_score_harm(el_val_t input);
el_val_t safety_screen(el_val_t input, el_val_t history);
el_val_t safety_self_harm_phrases(void);
el_val_t safety_soft_directive(void);
el_val_t safety_soft_phrases(void);
el_val_t safety_threat_score(el_val_t input, el_val_t history);
el_val_t safety_validate(el_val_t output, el_val_t action);
el_val_t scan_token(el_val_t s, el_val_t start);
@@ -967,13 +1031,19 @@ el_val_t sem_to_spec(el_val_t frame);
el_val_t sem_to_spec_full(el_val_t frame, el_val_t verb, el_val_t tense, el_val_t aspect);
el_val_t session_auto_title(el_val_t session_id, el_val_t first_message);
el_val_t session_create(el_val_t body);
el_val_t session_create_cleanup(el_val_t session_id);
el_val_t session_delete(el_val_t session_id);
el_val_t session_exists(el_val_t session_id);
el_val_t session_get(el_val_t session_id);
el_val_t session_hist_load(el_val_t session_id);
el_val_t session_hist_save(el_val_t session_id, el_val_t hist);
el_val_t session_list(void);
el_val_t session_make_content(el_val_t id, el_val_t title, el_val_t created_at, el_val_t updated_at, el_val_t folder);
el_val_t session_preload_bullets(el_val_t nodes, el_val_t max_bullets, el_val_t snip_len);
el_val_t session_search(el_val_t query);
el_val_t session_summary_autogenerate(el_val_t hist);
el_val_t session_summary_write(el_val_t summary_text);
el_val_t session_summary_write_dated(el_val_t summary_text, el_val_t label);
el_val_t session_title_from_message(el_val_t message);
el_val_t session_update_meta_timestamp(el_val_t session_id);
el_val_t session_update_patch(el_val_t session_id, el_val_t body);
@@ -1018,6 +1088,7 @@ el_val_t str_last2(el_val_t s);
el_val_t str_last3(el_val_t s);
el_val_t str_last_char(el_val_t s);
el_val_t strengthen_chat_nodes(el_val_t activation_nodes);
el_val_t strip_citations(el_val_t s);
el_val_t strip_query(el_val_t path);
el_val_t studio_tools_json(void);
el_val_t sux_absolutive_suffix(el_val_t person, el_val_t number);
@@ -1078,6 +1149,7 @@ el_val_t threat_trajectory_check(el_val_t tool_name, el_val_t tool_input);
el_val_t tier_canonical(void);
el_val_t tier_episodic(void);
el_val_t tier_working(void);
el_val_t tool_auto_approved(el_val_t tool_name);
el_val_t txb_conjugate(el_val_t verb, el_val_t tense, el_val_t person, el_val_t number);
el_val_t txb_decline(el_val_t noun, el_val_t gram_case, el_val_t number);
el_val_t txb_decline_fem(el_val_t noun, el_val_t gram_case, el_val_t number);
Generated Vendored
-25003
View File
File diff suppressed because it is too large Load Diff
Generated Vendored
-5
View File
@@ -70,8 +70,3 @@ el_val_t imprint_unload(void) {
return 0;
}
int main(int _argc, char** _argv) {
el_runtime_init_args(_argc, _argv);
return 0;
}
Generated Vendored
+38 -12
View File
@@ -34,7 +34,7 @@ el_val_t tier_canonical(void) {
}
el_val_t mem_store(el_val_t content, el_val_t label, el_val_t tags) {
return engram_node_full(content, EL_STR("Memory"), label, el_from_float(el_from_float(0.5)), el_from_float(el_from_float(0.5)), el_from_float(el_from_float(0.8)), EL_STR("Working"), tags);
return engram_node_full(content, EL_STR("Memory"), label, el_from_float(0.5), el_from_float(0.5), el_from_float(0.8), EL_STR("Working"), tags);
return 0;
}
@@ -65,15 +65,43 @@ el_val_t mem_forget(el_val_t node_id) {
el_val_t mem_consolidate(void) {
el_val_t scanned = engram_node_count();
el_val_t dummy = engram_scan_nodes_json(100, 0);
el_val_t total_nodes = engram_node_count();
el_val_t total_edges = engram_edge_count();
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"scanned\":"), int_to_str(scanned)), EL_STR(",\"total_nodes\":")), int_to_str(total_nodes)), EL_STR(",\"total_edges\":")), int_to_str(total_edges)), EL_STR("}"));
el_val_t strengthened = 0;
el_val_t wm_top = engram_wm_top_json(10);
el_val_t wm_len = json_array_len(wm_top);
el_val_t wi = 0;
while (wi < wm_len) {
el_val_t wm_node = json_array_get(wm_top, wi);
el_val_t wm_id = json_get(wm_node, EL_STR("id"));
if (!str_eq(wm_id, EL_STR(""))) {
engram_strengthen(wm_id);
strengthened = (strengthened + 1);
}
wi = (wi + 1);
}
el_val_t scan_result = engram_scan_nodes_json(50, 0);
el_val_t scan_len = json_array_len(scan_result);
el_val_t si = 0;
while (si < scan_len) {
el_val_t s_node = json_array_get(scan_result, si);
el_val_t s_tier = json_get(s_node, EL_STR("tier"));
el_val_t s_id = json_get(s_node, EL_STR("id"));
if (str_eq(s_tier, EL_STR("Canonical")) && !str_eq(s_id, EL_STR(""))) {
engram_strengthen(s_id);
strengthened = (strengthened + 1);
}
si = (si + 1);
}
el_val_t total_nodes = engram_node_count();
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"scanned\":"), int_to_str(scanned)), EL_STR(",\"total_nodes\":")), int_to_str(total_nodes)), EL_STR(",\"total_edges\":")), int_to_str(total_edges)), EL_STR(",\"strengthened\":")), int_to_str(strengthened)), EL_STR("}"));
return 0;
}
el_val_t mem_save(el_val_t path) {
engram_save(path);
el_val_t save_result = engram_save(path);
if (str_eq(save_result, EL_STR(""))) {
println(el_str_concat(el_str_concat(EL_STR("[memory] mem_save: engram_save failed for "), path), EL_STR(" \xe2\x80\x94 snapshot may be incomplete")));
}
return 0;
}
@@ -106,7 +134,10 @@ el_val_t mem_boot_count_inc(void) {
el_val_t next = (current + 1);
el_val_t content = el_str_concat(EL_STR("soul:boot_count:"), int_to_str(next));
el_val_t tags = EL_STR("[\"soul-meta\",\"boot-counter\"]");
el_val_t discard = engram_node_full(content, EL_STR("Memory"), EL_STR("soul:boot_count"), el_from_float(el_from_float(0.9)), el_from_float(el_from_float(0.9)), el_from_float(el_from_float(1.0)), EL_STR("Canonical"), tags);
el_val_t boot_node_id = engram_node_full(content, EL_STR("Memory"), EL_STR("soul:boot_count"), el_from_float(0.9), el_from_float(0.9), el_from_float(1.0), EL_STR("Canonical"), tags);
if (str_eq(boot_node_id, EL_STR(""))) {
println(el_str_concat(el_str_concat(EL_STR("[memory] mem_boot_count_inc: engram write failed \xe2\x80\x94 boot counter node lost (count="), int_to_str(next)), EL_STR(")")));
}
return next;
return 0;
}
@@ -118,12 +149,7 @@ el_val_t mem_emit_state_event(el_val_t trigger, el_val_t kind, el_val_t content)
el_val_t safe_content = str_replace(content, EL_STR("\""), EL_STR("'"));
el_val_t payload = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"trigger\":\""), safe_trigger), EL_STR("\"")), EL_STR(",\"kind\":\"")), kind), EL_STR("\"")), EL_STR(",\"content\":\"")), safe_content), EL_STR("\"")), EL_STR(",\"boot\":")), int_to_str(boot)), EL_STR(",\"ts\":")), int_to_str(ts)), EL_STR("}"));
el_val_t tags = EL_STR("[\"internal-state\",\"pre-reasoning\",\"InternalStateEvent\"]");
return engram_node_full(payload, EL_STR("InternalStateEvent"), el_str_concat(EL_STR("state-event:"), kind), el_from_float(el_from_float(0.85)), el_from_float(el_from_float(0.8)), el_from_float(el_from_float(0.9)), EL_STR("Episodic"), tags);
return 0;
}
int main(int _argc, char** _argv) {
el_runtime_init_args(_argc, _argv);
return engram_node_full(payload, EL_STR("InternalStateEvent"), el_str_concat(EL_STR("state-event:"), kind), el_from_float(0.85), el_from_float(0.8), el_from_float(0.9), EL_STR("Episodic"), tags);
return 0;
}
Generated Vendored Executable
BIN
View File
Binary file not shown.
Generated Vendored
+204 -161
View File
@@ -26,9 +26,14 @@ el_val_t api_ok(el_val_t extra);
el_val_t api_err(el_val_t msg);
el_val_t api_nonempty(el_val_t s);
el_val_t api_or_empty(el_val_t s);
el_val_t api_persisted(el_val_t id);
el_val_t api_not_persisted(el_val_t id);
el_val_t handle_api_begin_session(el_val_t body);
el_val_t handle_api_compile_ctx(el_val_t body);
el_val_t handle_api_remember(el_val_t body);
el_val_t handle_api_node_create(el_val_t body);
el_val_t handle_api_node_delete(el_val_t body);
el_val_t handle_api_node_update(el_val_t body);
el_val_t handle_api_recall(el_val_t method, el_val_t path, el_val_t body);
el_val_t handle_api_search_knowledge(el_val_t method, el_val_t path, el_val_t body);
el_val_t handle_api_browse_knowledge(el_val_t path, el_val_t body);
@@ -45,114 +50,12 @@ el_val_t handle_api_inspect_graph(el_val_t method, el_val_t path, el_val_t body)
el_val_t handle_api_link_entities(el_val_t body);
el_val_t handle_api_forget(el_val_t body);
el_val_t handle_api_evolve_memory(el_val_t body);
el_val_t handle_api_memory_delete(el_val_t body);
el_val_t handle_api_memory_update(el_val_t body);
el_val_t handle_api_cultivate(el_val_t body);
el_val_t handle_api_list_typed(el_val_t node_type, el_val_t path, el_val_t body);
el_val_t handle_api_consolidate(el_val_t body);
el_val_t tier_working(void) {
return EL_STR("Working");
return 0;
}
el_val_t tier_episodic(void) {
return EL_STR("Episodic");
return 0;
}
el_val_t tier_canonical(void) {
return EL_STR("Canonical");
return 0;
}
el_val_t mem_store(el_val_t content, el_val_t label, el_val_t tags) {
return engram_node_full(content, EL_STR("Memory"), label, el_from_float(el_from_float(0.5)), el_from_float(el_from_float(0.5)), el_from_float(el_from_float(0.8)), EL_STR("Working"), tags);
return 0;
}
el_val_t mem_remember(el_val_t content, el_val_t tags) {
return mem_store(content, EL_STR("soul-memory"), tags);
return 0;
}
el_val_t mem_recall(el_val_t query, el_val_t depth) {
return engram_activate_json(query, depth);
return 0;
}
el_val_t mem_search(el_val_t query, el_val_t limit) {
return engram_search_json(query, limit);
return 0;
}
el_val_t mem_strengthen(el_val_t node_id) {
engram_strengthen(node_id);
return 0;
}
el_val_t mem_forget(el_val_t node_id) {
engram_forget(node_id);
return 0;
}
el_val_t mem_consolidate(void) {
el_val_t scanned = engram_node_count();
el_val_t dummy = engram_scan_nodes_json(100, 0);
el_val_t total_nodes = engram_node_count();
el_val_t total_edges = engram_edge_count();
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"scanned\":"), int_to_str(scanned)), EL_STR(",\"total_nodes\":")), int_to_str(total_nodes)), EL_STR(",\"total_edges\":")), int_to_str(total_edges)), EL_STR("}"));
return 0;
}
el_val_t mem_save(el_val_t path) {
engram_save(path);
return 0;
}
el_val_t mem_load(el_val_t path) {
engram_load(path);
return 0;
}
el_val_t mem_boot_count_get(void) {
el_val_t results = engram_search_json(EL_STR("soul:boot_count"), 3);
if (str_eq(results, EL_STR(""))) {
return 0;
}
if (str_eq(results, EL_STR("[]"))) {
return 0;
}
el_val_t node = json_array_get(results, 0);
el_val_t content = json_get(node, EL_STR("content"));
el_val_t prefix = EL_STR("soul:boot_count:");
if (!str_starts_with(content, prefix)) {
return 0;
}
el_val_t num_str = str_slice(content, str_len(prefix), str_len(content));
return str_to_int(num_str);
return 0;
}
el_val_t mem_boot_count_inc(void) {
el_val_t current = mem_boot_count_get();
el_val_t next = (current + 1);
el_val_t content = el_str_concat(EL_STR("soul:boot_count:"), int_to_str(next));
el_val_t tags = EL_STR("[\"soul-meta\",\"boot-counter\"]");
el_val_t discard = engram_node_full(content, EL_STR("Memory"), EL_STR("soul:boot_count"), el_from_float(el_from_float(0.9)), el_from_float(el_from_float(0.9)), el_from_float(el_from_float(1.0)), EL_STR("Canonical"), tags);
return next;
return 0;
}
el_val_t mem_emit_state_event(el_val_t trigger, el_val_t kind, el_val_t content) {
el_val_t boot = mem_boot_count_get();
el_val_t ts = time_now();
el_val_t safe_trigger = str_replace(trigger, EL_STR("\""), EL_STR("'"));
el_val_t safe_content = str_replace(content, EL_STR("\""), EL_STR("'"));
el_val_t payload = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"trigger\":\""), safe_trigger), EL_STR("\"")), EL_STR(",\"kind\":\"")), kind), EL_STR("\"")), EL_STR(",\"content\":\"")), safe_content), EL_STR("\"")), EL_STR(",\"boot\":")), int_to_str(boot)), EL_STR(",\"ts\":")), int_to_str(ts)), EL_STR("}"));
el_val_t tags = EL_STR("[\"internal-state\",\"pre-reasoning\",\"InternalStateEvent\"]");
return engram_node_full(payload, EL_STR("InternalStateEvent"), el_str_concat(EL_STR("state-event:"), kind), el_from_float(el_from_float(0.85)), el_from_float(el_from_float(0.8)), el_from_float(el_from_float(0.9)), EL_STR("Episodic"), tags);
return 0;
}
el_val_t is_protected_node(el_val_t id) {
if (str_eq(id, EL_STR("kn-efeb4a5b-5aff-4759-8a97-7233099be6ee"))) {
return 1;
@@ -272,6 +175,20 @@ el_val_t api_or_empty(el_val_t s) {
return 0;
}
el_val_t api_persisted(el_val_t id) {
if (str_eq(id, EL_STR(""))) {
return 0;
}
el_val_t node = engram_get_node_json(id);
return (!str_eq(node, EL_STR("")) && !str_eq(node, EL_STR("null")));
return 0;
}
el_val_t api_not_persisted(el_val_t id) {
return el_str_concat(el_str_concat(EL_STR("{\"ok\":false,\"error\":\"write_not_persisted\",\"id\":\""), id), EL_STR("\"}"));
return 0;
}
el_val_t handle_api_begin_session(el_val_t body) {
el_val_t stats = engram_stats_json();
el_val_t activated = engram_activate_json(EL_STR("session start recent memory important"), 2);
@@ -302,18 +219,88 @@ el_val_t handle_api_remember(el_val_t body) {
el_val_t sal = ({ el_val_t _if_result_4 = 0; if (str_eq(sal_str, EL_STR("0.95"))) { _if_result_4 = (el_from_float(0.95)); } else { _if_result_4 = (({ el_val_t _if_result_5 = 0; if (str_eq(sal_str, EL_STR("0.75"))) { _if_result_5 = (el_from_float(0.75)); } else { _if_result_5 = (({ el_val_t _if_result_6 = 0; if (str_eq(sal_str, EL_STR("0.25"))) { _if_result_6 = (el_from_float(0.25)); } else { _if_result_6 = (el_from_float(0.5)); } _if_result_6; })); } _if_result_5; })); } _if_result_4; });
el_val_t base_tags = ({ el_val_t _if_result_7 = 0; if (str_eq(tags_raw, EL_STR(""))) { _if_result_7 = (EL_STR("[\"Memory\"]")); } else { _if_result_7 = (tags_raw); } _if_result_7; });
el_val_t final_tags = ({ el_val_t _if_result_8 = 0; if (str_eq(project, EL_STR(""))) { _if_result_8 = (base_tags); } else { el_val_t inner = str_slice(base_tags, 1, (str_len(base_tags) - 1)); _if_result_8 = (el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("["), inner), EL_STR(",\"project:")), project), EL_STR("\"]"))); } _if_result_8; });
el_val_t id = engram_node_full(content, EL_STR("Memory"), EL_STR("memory:remembered"), el_from_float(sal), el_from_float(sal), el_from_float(el_from_float(0.9)), EL_STR("Episodic"), final_tags);
el_val_t id = engram_node_full(content, EL_STR("Memory"), EL_STR("memory:remembered"), el_from_float(sal), el_from_float(sal), el_from_float(0.9), EL_STR("Episodic"), final_tags);
if (!api_persisted(id)) {
return api_not_persisted(id);
}
return el_str_concat(el_str_concat(EL_STR("{\"id\":\""), id), EL_STR("\",\"ok\":true}"));
return 0;
}
el_val_t handle_api_node_create(el_val_t body) {
el_val_t content = json_get(body, EL_STR("content"));
if (str_eq(content, EL_STR(""))) {
return api_err(EL_STR("content is required"));
}
el_val_t nt_raw = json_get(body, EL_STR("node_type"));
el_val_t node_type = ({ el_val_t _if_result_9 = 0; if (str_eq(nt_raw, EL_STR(""))) { _if_result_9 = (EL_STR("Memory")); } else { _if_result_9 = (nt_raw); } _if_result_9; });
el_val_t label_raw = json_get(body, EL_STR("label"));
el_val_t label = ({ el_val_t _if_result_10 = 0; if (str_eq(label_raw, EL_STR(""))) { _if_result_10 = (EL_STR("node:created")); } else { _if_result_10 = (label_raw); } _if_result_10; });
el_val_t tier_raw = json_get(body, EL_STR("tier"));
el_val_t tier = ({ el_val_t _if_result_11 = 0; if (str_eq(tier_raw, EL_STR(""))) { _if_result_11 = (EL_STR("Episodic")); } else { _if_result_11 = (tier_raw); } _if_result_11; });
el_val_t tags_raw = json_get(body, EL_STR("tags"));
el_val_t tags = ({ el_val_t _if_result_12 = 0; if (str_eq(tags_raw, EL_STR(""))) { _if_result_12 = (el_str_concat(el_str_concat(EL_STR("[\""), node_type), EL_STR("\"]"))); } else { _if_result_12 = (tags_raw); } _if_result_12; });
el_val_t importance = json_get(body, EL_STR("importance"));
el_val_t sal = ({ el_val_t _if_result_13 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_13 = (el_from_float(0.95)); } else { _if_result_13 = (({ el_val_t _if_result_14 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_14 = (el_from_float(0.75)); } else { _if_result_14 = (({ el_val_t _if_result_15 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_15 = (el_from_float(0.25)); } else { _if_result_15 = (el_from_float(0.5)); } _if_result_15; })); } _if_result_14; })); } _if_result_13; });
el_val_t id = engram_node_full(content, node_type, label, el_from_float(sal), el_from_float(sal), el_from_float(0.9), tier, tags);
if (!api_persisted(id)) {
return api_not_persisted(id);
}
return el_str_concat(el_str_concat(EL_STR("{\"id\":\""), id), EL_STR("\",\"ok\":true}"));
return 0;
}
el_val_t handle_api_node_delete(el_val_t body) {
el_val_t id = json_get(body, EL_STR("id"));
if (str_eq(id, EL_STR(""))) {
return api_err(EL_STR("id is required"));
}
engram_forget(id);
return el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"id\":\""), id), EL_STR("\"}"));
return 0;
}
el_val_t handle_api_node_update(el_val_t body) {
el_val_t id = json_get(body, EL_STR("id"));
if (str_eq(id, EL_STR(""))) {
return api_err(EL_STR("id is required"));
}
if (!api_persisted(id)) {
return el_str_concat(el_str_concat(EL_STR("{\"ok\":false,\"error\":\"not_found\",\"id\":\""), id), EL_STR("\"}"));
}
el_val_t old = engram_get_node_json(id);
el_val_t body_content = json_get(body, EL_STR("content"));
el_val_t content = ({ el_val_t _if_result_16 = 0; if (str_eq(body_content, EL_STR(""))) { _if_result_16 = (json_get(old, EL_STR("content"))); } else { _if_result_16 = (body_content); } _if_result_16; });
el_val_t body_nt = json_get(body, EL_STR("node_type"));
el_val_t old_nt = json_get(old, EL_STR("node_type"));
el_val_t node_type = ({ el_val_t _if_result_17 = 0; if (!str_eq(body_nt, EL_STR(""))) { _if_result_17 = (body_nt); } else { _if_result_17 = (({ el_val_t _if_result_18 = 0; if (!str_eq(old_nt, EL_STR(""))) { _if_result_18 = (old_nt); } else { _if_result_18 = (EL_STR("Memory")); } _if_result_18; })); } _if_result_17; });
el_val_t body_label = json_get(body, EL_STR("label"));
el_val_t old_label = json_get(old, EL_STR("label"));
el_val_t label = ({ el_val_t _if_result_19 = 0; if (!str_eq(body_label, EL_STR(""))) { _if_result_19 = (body_label); } else { _if_result_19 = (({ el_val_t _if_result_20 = 0; if (!str_eq(old_label, EL_STR(""))) { _if_result_20 = (old_label); } else { _if_result_20 = (EL_STR("node:updated")); } _if_result_20; })); } _if_result_19; });
el_val_t body_tier = json_get(body, EL_STR("tier"));
el_val_t old_tier = json_get(old, EL_STR("tier"));
el_val_t tier = ({ el_val_t _if_result_21 = 0; if (!str_eq(body_tier, EL_STR(""))) { _if_result_21 = (body_tier); } else { _if_result_21 = (({ el_val_t _if_result_22 = 0; if (!str_eq(old_tier, EL_STR(""))) { _if_result_22 = (old_tier); } else { _if_result_22 = (EL_STR("Episodic")); } _if_result_22; })); } _if_result_21; });
el_val_t body_tags = json_get(body, EL_STR("tags"));
el_val_t tags = ({ el_val_t _if_result_23 = 0; if (str_eq(body_tags, EL_STR(""))) { _if_result_23 = (el_str_concat(el_str_concat(EL_STR("[\""), node_type), EL_STR("\"]"))); } else { _if_result_23 = (body_tags); } _if_result_23; });
el_val_t new_id = engram_node_full(content, node_type, label, el_from_float(0.5), el_from_float(0.5), el_from_float(0.8), tier, tags);
if (!api_persisted(new_id)) {
return api_not_persisted(new_id);
}
engram_forget(id);
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"id\":\""), new_id), EL_STR("\",\"replaced\":\"")), id), EL_STR("\",\"ok\":true}"));
return 0;
}
el_val_t handle_api_recall(el_val_t method, el_val_t path, el_val_t body) {
el_val_t q = ({ el_val_t _if_result_9 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_9 = (api_query_param(path, EL_STR("query"))); } else { _if_result_9 = (json_get(body, EL_STR("query"))); } _if_result_9; });
el_val_t url_q = ({ el_val_t _if_result_24 = 0; if (str_eq(api_query_param(path, EL_STR("query")), EL_STR(""))) { _if_result_24 = (api_query_param(path, EL_STR("q"))); } else { _if_result_24 = (api_query_param(path, EL_STR("query"))); } _if_result_24; });
el_val_t body_query = json_get(body, EL_STR("query"));
el_val_t body_q = json_get(body, EL_STR("q"));
el_val_t q = ({ el_val_t _if_result_25 = 0; if (!str_eq(url_q, EL_STR(""))) { _if_result_25 = (url_q); } else { _if_result_25 = (({ el_val_t _if_result_26 = 0; if (!str_eq(body_query, EL_STR(""))) { _if_result_26 = (body_query); } else { _if_result_26 = (body_q); } _if_result_26; })); } _if_result_25; });
el_val_t chain = json_get(body, EL_STR("chain_name"));
el_val_t limit = api_query_int(path, EL_STR("limit"), 0);
limit = ({ el_val_t _if_result_10 = 0; if ((limit == 0)) { _if_result_10 = (json_get_int(body, EL_STR("limit"))); } else { _if_result_10 = (limit); } _if_result_10; });
limit = ({ el_val_t _if_result_11 = 0; if ((limit == 0)) { _if_result_11 = (10); } else { _if_result_11 = (limit); } _if_result_11; });
el_val_t eff_q = ({ el_val_t _if_result_12 = 0; if (str_eq(q, EL_STR(""))) { _if_result_12 = (chain); } else { _if_result_12 = (q); } _if_result_12; });
limit = ({ el_val_t _if_result_27 = 0; if ((limit == 0)) { _if_result_27 = (json_get_int(body, EL_STR("limit"))); } else { _if_result_27 = (limit); } _if_result_27; });
limit = ({ el_val_t _if_result_28 = 0; if ((limit == 0)) { _if_result_28 = (10); } else { _if_result_28 = (limit); } _if_result_28; });
el_val_t eff_q = ({ el_val_t _if_result_29 = 0; if (str_eq(q, EL_STR(""))) { _if_result_29 = (chain); } else { _if_result_29 = (q); } _if_result_29; });
if (str_eq(eff_q, EL_STR(""))) {
return api_or_empty(engram_scan_nodes_json(limit, 0));
}
@@ -323,10 +310,13 @@ el_val_t handle_api_recall(el_val_t method, el_val_t path, el_val_t body) {
}
el_val_t handle_api_search_knowledge(el_val_t method, el_val_t path, el_val_t body) {
el_val_t q = ({ el_val_t _if_result_13 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_13 = (api_query_param(path, EL_STR("q"))); } else { _if_result_13 = (json_get(body, EL_STR("query"))); } _if_result_13; });
el_val_t url_q = api_query_param(path, EL_STR("q"));
el_val_t body_query = json_get(body, EL_STR("query"));
el_val_t body_q = json_get(body, EL_STR("q"));
el_val_t q = ({ el_val_t _if_result_30 = 0; if (!str_eq(url_q, EL_STR(""))) { _if_result_30 = (url_q); } else { _if_result_30 = (({ el_val_t _if_result_31 = 0; if (!str_eq(body_query, EL_STR(""))) { _if_result_31 = (body_query); } else { _if_result_31 = (body_q); } _if_result_31; })); } _if_result_30; });
el_val_t limit = api_query_int(path, EL_STR("limit"), 0);
limit = ({ el_val_t _if_result_14 = 0; if ((limit == 0)) { _if_result_14 = (json_get_int(body, EL_STR("limit"))); } else { _if_result_14 = (limit); } _if_result_14; });
limit = ({ el_val_t _if_result_15 = 0; if ((limit == 0)) { _if_result_15 = (10); } else { _if_result_15 = (limit); } _if_result_15; });
limit = ({ el_val_t _if_result_32 = 0; if ((limit == 0)) { _if_result_32 = (json_get_int(body, EL_STR("limit"))); } else { _if_result_32 = (limit); } _if_result_32; });
limit = ({ el_val_t _if_result_33 = 0; if ((limit == 0)) { _if_result_33 = (10); } else { _if_result_33 = (limit); } _if_result_33; });
if (str_eq(q, EL_STR(""))) {
return api_err(EL_STR("query is required"));
}
@@ -354,9 +344,12 @@ el_val_t handle_api_capture_knowledge(el_val_t body) {
if (str_eq(content, EL_STR(""))) {
return api_err(EL_STR("content is required"));
}
el_val_t full = ({ el_val_t _if_result_16 = 0; if (str_eq(title, EL_STR(""))) { _if_result_16 = (content); } else { _if_result_16 = (el_str_concat(el_str_concat(title, EL_STR(": ")), content)); } _if_result_16; });
el_val_t full = ({ el_val_t _if_result_34 = 0; if (str_eq(title, EL_STR(""))) { _if_result_34 = (content); } else { _if_result_34 = (el_str_concat(el_str_concat(title, EL_STR(": ")), content)); } _if_result_34; });
el_val_t tags = EL_STR("[\"Knowledge\",\"captured\"]");
el_val_t id = engram_node_full(full, EL_STR("Knowledge"), EL_STR("knowledge:captured"), el_from_float(el_from_float(0.85)), el_from_float(el_from_float(0.8)), el_from_float(el_from_float(0.9)), EL_STR("Episodic"), tags);
el_val_t id = engram_node_full(full, EL_STR("Knowledge"), EL_STR("knowledge:captured"), el_from_float(0.85), el_from_float(0.8), el_from_float(0.9), EL_STR("Episodic"), tags);
if (!api_persisted(id)) {
return api_not_persisted(id);
}
return el_str_concat(el_str_concat(EL_STR("{\"id\":\""), id), EL_STR("\",\"ok\":true}"));
return 0;
}
@@ -371,9 +364,12 @@ el_val_t handle_api_evolve_knowledge(el_val_t body) {
return api_err_protected(prior_id);
}
el_val_t tags = EL_STR("[\"Knowledge\",\"evolved\"]");
el_val_t new_id = engram_node_full(content, EL_STR("Knowledge"), EL_STR("knowledge:evolved"), el_from_float(el_from_float(0.75)), el_from_float(el_from_float(0.75)), el_from_float(el_from_float(0.9)), EL_STR("Episodic"), tags);
if (!str_eq(prior_id, EL_STR("")) && !str_eq(new_id, EL_STR(""))) {
engram_connect(new_id, prior_id, el_from_float(el_from_float(0.9)), EL_STR("supersedes"));
el_val_t new_id = engram_node_full(content, EL_STR("Knowledge"), EL_STR("knowledge:evolved"), el_from_float(0.75), el_from_float(0.75), el_from_float(0.9), EL_STR("Episodic"), tags);
if (!api_persisted(new_id)) {
return api_not_persisted(new_id);
}
if (!str_eq(prior_id, EL_STR(""))) {
engram_connect(new_id, prior_id, el_from_float(0.9), EL_STR("supersedes"));
}
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"id\":\""), new_id), EL_STR("\",\"supersedes\":\"")), prior_id), EL_STR("\",\"ok\":true}"));
return 0;
@@ -389,18 +385,18 @@ el_val_t handle_api_promote_knowledge(el_val_t body) {
return api_err(EL_STR("id (prior node) is required"));
}
el_val_t tags_raw = json_get(body, EL_STR("tags"));
el_val_t tags = ({ el_val_t _if_result_17 = 0; if (str_eq(tags_raw, EL_STR(""))) { _if_result_17 = (EL_STR("[\"Knowledge\",\"tier:canonical\",\"disposition:stable\"]")); } else { _if_result_17 = (tags_raw); } _if_result_17; });
el_val_t new_id = engram_node_full(content, EL_STR("Knowledge"), EL_STR("knowledge:canonical"), el_from_float(el_from_float(0.9)), el_from_float(el_from_float(0.9)), el_from_float(el_from_float(1.0)), EL_STR("Canonical"), tags);
if (str_eq(new_id, EL_STR(""))) {
return api_err(EL_STR("failed to create canonical node"));
el_val_t tags = ({ el_val_t _if_result_35 = 0; if (str_eq(tags_raw, EL_STR(""))) { _if_result_35 = (EL_STR("[\"Knowledge\",\"tier:canonical\",\"disposition:stable\"]")); } else { _if_result_35 = (tags_raw); } _if_result_35; });
el_val_t new_id = engram_node_full(content, EL_STR("Knowledge"), EL_STR("knowledge:canonical"), el_from_float(0.9), el_from_float(0.9), el_from_float(1.0), EL_STR("Canonical"), tags);
if (!api_persisted(new_id)) {
return api_not_persisted(new_id);
}
engram_connect(new_id, prior_id, el_from_float(el_from_float(0.95)), EL_STR("supersedes"));
engram_connect(new_id, prior_id, el_from_float(0.95), EL_STR("supersedes"));
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"new_id\":\""), new_id), EL_STR("\",\"supersedes\":\"")), prior_id), EL_STR("\"}"));
return 0;
}
el_val_t handle_api_browse_processes(el_val_t method, el_val_t path, el_val_t body) {
el_val_t name = ({ el_val_t _if_result_18 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_18 = (api_query_param(path, EL_STR("name"))); } else { _if_result_18 = (json_get(body, EL_STR("name"))); } _if_result_18; });
el_val_t name = ({ el_val_t _if_result_36 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_36 = (api_query_param(path, EL_STR("name"))); } else { _if_result_36 = (json_get(body, EL_STR("name"))); } _if_result_36; });
el_val_t limit = api_query_int(path, EL_STR("limit"), 50);
if (str_eq(name, EL_STR(""))) {
return api_or_empty(engram_scan_nodes_by_type_json(EL_STR("Process"), limit, 0));
@@ -415,9 +411,12 @@ el_val_t handle_api_define_process(el_val_t body) {
if (str_eq(content, EL_STR(""))) {
return api_err(EL_STR("content is required"));
}
el_val_t label = ({ el_val_t _if_result_19 = 0; if (str_eq(name, EL_STR(""))) { _if_result_19 = (EL_STR("process:unnamed")); } else { _if_result_19 = (el_str_concat(EL_STR("process:"), name)); } _if_result_19; });
el_val_t label = ({ el_val_t _if_result_37 = 0; if (str_eq(name, EL_STR(""))) { _if_result_37 = (EL_STR("process:unnamed")); } else { _if_result_37 = (el_str_concat(EL_STR("process:"), name)); } _if_result_37; });
el_val_t tags = EL_STR("[\"Process\"]");
el_val_t id = engram_node_full(content, EL_STR("Process"), label, el_from_float(el_from_float(0.8)), el_from_float(el_from_float(0.8)), el_from_float(el_from_float(0.9)), EL_STR("Canonical"), tags);
el_val_t id = engram_node_full(content, EL_STR("Process"), label, el_from_float(0.8), el_from_float(0.8), el_from_float(0.9), EL_STR("Canonical"), tags);
if (!api_persisted(id)) {
return api_not_persisted(id);
}
return el_str_concat(el_str_concat(EL_STR("{\"id\":\""), id), EL_STR("\",\"ok\":true}"));
return 0;
}
@@ -430,22 +429,25 @@ el_val_t handle_api_log_state_event(el_val_t body) {
el_val_t gap = json_get(body, EL_STR("gap_direction"));
el_val_t legacy = json_get(body, EL_STR("content"));
el_val_t parts = EL_STR("INTERNAL STATE EVENT");
parts = ({ el_val_t _if_result_20 = 0; if (!str_eq(trigger, EL_STR(""))) { _if_result_20 = (el_str_concat(el_str_concat(parts, EL_STR("\nTrigger: ")), trigger)); } else { _if_result_20 = (parts); } _if_result_20; });
parts = ({ el_val_t _if_result_21 = 0; if (!str_eq(pre, EL_STR(""))) { _if_result_21 = (el_str_concat(el_str_concat(parts, EL_STR("\nPre-reasoning: ")), pre)); } else { _if_result_21 = (parts); } _if_result_21; });
parts = ({ el_val_t _if_result_22 = 0; if (!str_eq(post, EL_STR(""))) { _if_result_22 = (el_str_concat(el_str_concat(parts, EL_STR("\nPost-reasoning: ")), post)); } else { _if_result_22 = (parts); } _if_result_22; });
parts = ({ el_val_t _if_result_23 = 0; if (!str_eq(ratio, EL_STR(""))) { _if_result_23 = (el_str_concat(el_str_concat(parts, EL_STR("\nCompression-ratio: ")), ratio)); } else { _if_result_23 = (parts); } _if_result_23; });
parts = ({ el_val_t _if_result_24 = 0; if (!str_eq(gap, EL_STR(""))) { _if_result_24 = (el_str_concat(el_str_concat(parts, EL_STR("\nGap-direction: ")), gap)); } else { _if_result_24 = (parts); } _if_result_24; });
parts = ({ el_val_t _if_result_25 = 0; if (!str_eq(legacy, EL_STR(""))) { _if_result_25 = (el_str_concat(el_str_concat(parts, EL_STR("\n")), legacy)); } else { _if_result_25 = (parts); } _if_result_25; });
parts = ({ el_val_t _if_result_38 = 0; if (!str_eq(trigger, EL_STR(""))) { _if_result_38 = (el_str_concat(el_str_concat(parts, EL_STR("\nTrigger: ")), trigger)); } else { _if_result_38 = (parts); } _if_result_38; });
parts = ({ el_val_t _if_result_39 = 0; if (!str_eq(pre, EL_STR(""))) { _if_result_39 = (el_str_concat(el_str_concat(parts, EL_STR("\nPre-reasoning: ")), pre)); } else { _if_result_39 = (parts); } _if_result_39; });
parts = ({ el_val_t _if_result_40 = 0; if (!str_eq(post, EL_STR(""))) { _if_result_40 = (el_str_concat(el_str_concat(parts, EL_STR("\nPost-reasoning: ")), post)); } else { _if_result_40 = (parts); } _if_result_40; });
parts = ({ el_val_t _if_result_41 = 0; if (!str_eq(ratio, EL_STR(""))) { _if_result_41 = (el_str_concat(el_str_concat(parts, EL_STR("\nCompression-ratio: ")), ratio)); } else { _if_result_41 = (parts); } _if_result_41; });
parts = ({ el_val_t _if_result_42 = 0; if (!str_eq(gap, EL_STR(""))) { _if_result_42 = (el_str_concat(el_str_concat(parts, EL_STR("\nGap-direction: ")), gap)); } else { _if_result_42 = (parts); } _if_result_42; });
parts = ({ el_val_t _if_result_43 = 0; if (!str_eq(legacy, EL_STR(""))) { _if_result_43 = (el_str_concat(el_str_concat(parts, EL_STR("\n")), legacy)); } else { _if_result_43 = (parts); } _if_result_43; });
el_val_t ts = time_now();
el_val_t boot = state_get(EL_STR("soul_boot_count"));
el_val_t tags = EL_STR("[\"internal-state\",\"InternalStateEvent\",\"pre-reasoning\"]");
el_val_t id = engram_node_full(parts, EL_STR("InternalStateEvent"), EL_STR("state-event:manual"), el_from_float(el_from_float(0.85)), el_from_float(el_from_float(0.85)), el_from_float(el_from_float(0.9)), EL_STR("Episodic"), tags);
el_val_t id = engram_node_full(parts, EL_STR("InternalStateEvent"), EL_STR("state-event:manual"), el_from_float(0.85), el_from_float(0.85), el_from_float(0.9), EL_STR("Episodic"), tags);
if (!api_persisted(id)) {
return api_not_persisted(id);
}
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"id\":\""), id), EL_STR("\",\"boot\":\"")), boot), EL_STR("\"}"));
return 0;
}
el_val_t handle_api_list_state_events(el_val_t method, el_val_t path, el_val_t body) {
el_val_t q = ({ el_val_t _if_result_26 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_26 = (api_query_param(path, EL_STR("query"))); } else { _if_result_26 = (json_get(body, EL_STR("query"))); } _if_result_26; });
el_val_t q = ({ el_val_t _if_result_44 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_44 = (api_query_param(path, EL_STR("query"))); } else { _if_result_44 = (json_get(body, EL_STR("query"))); } _if_result_44; });
el_val_t limit = api_query_int(path, EL_STR("limit"), 20);
if (!str_eq(q, EL_STR(""))) {
return api_or_empty(engram_search_json(el_str_concat(EL_STR("internal state "), q), limit));
@@ -456,7 +458,7 @@ el_val_t handle_api_list_state_events(el_val_t method, el_val_t path, el_val_t b
el_val_t handle_api_inspect_config(el_val_t path, el_val_t body) {
el_val_t key = api_query_param(path, EL_STR("key"));
key = ({ el_val_t _if_result_27 = 0; if (str_eq(key, EL_STR(""))) { _if_result_27 = (json_get(body, EL_STR("key"))); } else { _if_result_27 = (key); } _if_result_27; });
key = ({ el_val_t _if_result_45 = 0; if (str_eq(key, EL_STR(""))) { _if_result_45 = (json_get(body, EL_STR("key"))); } else { _if_result_45 = (key); } _if_result_45; });
if (str_eq(key, EL_STR(""))) {
return EL_STR("{\"hint\":\"pass ?key=<name>\",\"known\":[\"neuron.self.traversal_root\",\"neuron.self.values_hub\"]}");
}
@@ -473,7 +475,7 @@ el_val_t handle_api_inspect_config(el_val_t path, el_val_t body) {
el_val_t node = json_array_get(results, 0);
el_val_t content = json_get(node, EL_STR("content"));
el_val_t prefix = el_str_concat(el_str_concat(EL_STR("config:"), key), EL_STR("="));
el_val_t value = ({ el_val_t _if_result_28 = 0; if (str_starts_with(content, prefix)) { _if_result_28 = (str_slice(content, str_len(prefix), str_len(content))); } else { _if_result_28 = (content); } _if_result_28; });
el_val_t value = ({ el_val_t _if_result_46 = 0; if (str_starts_with(content, prefix)) { _if_result_46 = (str_slice(content, str_len(prefix), str_len(content))); } else { _if_result_46 = (content); } _if_result_46; });
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"key\":\""), key), EL_STR("\",\"value\":\"")), value), EL_STR("\"}"));
return 0;
}
@@ -486,19 +488,22 @@ el_val_t handle_api_tune_config(el_val_t body) {
}
el_val_t content = el_str_concat(el_str_concat(el_str_concat(EL_STR("config:"), key), EL_STR("=")), value);
el_val_t tags = EL_STR("[\"ConfigEntry\",\"config\"]");
el_val_t id = engram_node_full(content, EL_STR("ConfigEntry"), key, el_from_float(el_from_float(0.85)), el_from_float(el_from_float(0.85)), el_from_float(el_from_float(0.9)), EL_STR("Canonical"), tags);
el_val_t id = engram_node_full(content, EL_STR("ConfigEntry"), key, el_from_float(0.85), el_from_float(0.85), el_from_float(0.9), EL_STR("Canonical"), tags);
if (!api_persisted(id)) {
return api_not_persisted(id);
}
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"key\":\""), key), EL_STR("\",\"value\":\"")), value), EL_STR("\",\"id\":\"")), id), EL_STR("\"}"));
return 0;
}
el_val_t handle_api_inspect_graph(el_val_t method, el_val_t path, el_val_t body) {
el_val_t entity_id = ({ el_val_t _if_result_29 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_29 = (api_query_param(path, EL_STR("id"))); } else { _if_result_29 = (json_get(body, EL_STR("entity_id"))); } _if_result_29; });
el_val_t name = ({ el_val_t _if_result_30 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_30 = (api_query_param(path, EL_STR("name"))); } else { _if_result_30 = (json_get(body, EL_STR("name"))); } _if_result_30; });
el_val_t entity_id = ({ el_val_t _if_result_47 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_47 = (api_query_param(path, EL_STR("id"))); } else { _if_result_47 = (json_get(body, EL_STR("entity_id"))); } _if_result_47; });
el_val_t name = ({ el_val_t _if_result_48 = 0; if (str_eq(method, EL_STR("GET"))) { _if_result_48 = (api_query_param(path, EL_STR("name"))); } else { _if_result_48 = (json_get(body, EL_STR("name"))); } _if_result_48; });
el_val_t depth = api_query_int(path, EL_STR("depth"), 0);
depth = ({ el_val_t _if_result_31 = 0; if ((depth == 0)) { _if_result_31 = (json_get_int(body, EL_STR("max_depth"))); } else { _if_result_31 = (depth); } _if_result_31; });
depth = ({ el_val_t _if_result_32 = 0; if ((depth == 0)) { _if_result_32 = (1); } else { _if_result_32 = (depth); } _if_result_32; });
depth = ({ el_val_t _if_result_49 = 0; if ((depth == 0)) { _if_result_49 = (json_get_int(body, EL_STR("max_depth"))); } else { _if_result_49 = (depth); } _if_result_49; });
depth = ({ el_val_t _if_result_50 = 0; if ((depth == 0)) { _if_result_50 = (1); } else { _if_result_50 = (depth); } _if_result_50; });
el_val_t resolved = entity_id;
resolved = ({ el_val_t _if_result_33 = 0; if (str_eq(resolved, EL_STR(""))) { _if_result_33 = (({ el_val_t _if_result_34 = 0; if ((str_eq(name, EL_STR("self")) || str_eq(name, EL_STR("neuron")))) { _if_result_34 = (EL_STR("kn-efeb4a5b-5aff-4759-8a97-7233099be6ee")); } else { _if_result_34 = (({ el_val_t _if_result_35 = 0; if ((str_eq(name, EL_STR("values")) || str_eq(name, EL_STR("values_hub")))) { _if_result_35 = (EL_STR("kn-5b606390-a52d-4ca2-8e0e-eba141d13440")); } else { _if_result_35 = (EL_STR("")); } _if_result_35; })); } _if_result_34; })); } else { _if_result_33 = (resolved); } _if_result_33; });
resolved = ({ el_val_t _if_result_51 = 0; if (str_eq(resolved, EL_STR(""))) { _if_result_51 = (({ el_val_t _if_result_52 = 0; if ((str_eq(name, EL_STR("self")) || str_eq(name, EL_STR("neuron")))) { _if_result_52 = (EL_STR("kn-efeb4a5b-5aff-4759-8a97-7233099be6ee")); } else { _if_result_52 = (({ el_val_t _if_result_53 = 0; if ((str_eq(name, EL_STR("values")) || str_eq(name, EL_STR("values_hub")))) { _if_result_53 = (EL_STR("kn-5b606390-a52d-4ca2-8e0e-eba141d13440")); } else { _if_result_53 = (EL_STR("")); } _if_result_53; })); } _if_result_52; })); } else { _if_result_51 = (resolved); } _if_result_51; });
if (str_eq(resolved, EL_STR(""))) {
return api_err(EL_STR("entity_id or name required. Known names: self, neuron, values, values_hub"));
}
@@ -520,8 +525,8 @@ el_val_t handle_api_link_entities(el_val_t body) {
return api_err_protected(to_id);
}
el_val_t relation = json_get(body, EL_STR("relation"));
el_val_t eff_relation = ({ el_val_t _if_result_36 = 0; if (str_eq(relation, EL_STR(""))) { _if_result_36 = (EL_STR("associates")); } else { _if_result_36 = (relation); } _if_result_36; });
engram_connect(from_id, to_id, el_from_float(el_from_float(0.5)), eff_relation);
el_val_t eff_relation = ({ el_val_t _if_result_54 = 0; if (str_eq(relation, EL_STR(""))) { _if_result_54 = (EL_STR("associates")); } else { _if_result_54 = (relation); } _if_result_54; });
engram_connect(from_id, to_id, el_from_float(0.5), eff_relation);
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"from_id\":\""), from_id), EL_STR("\",\"to_id\":\"")), to_id), EL_STR("\",\"relation\":\"")), eff_relation), EL_STR("\"}"));
return 0;
}
@@ -549,17 +554,54 @@ el_val_t handle_api_evolve_memory(el_val_t body) {
return api_err_protected(prior_id);
}
el_val_t importance = json_get(body, EL_STR("importance"));
el_val_t sal_str = ({ el_val_t _if_result_37 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_37 = (EL_STR("0.95")); } else { _if_result_37 = (({ el_val_t _if_result_38 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_38 = (EL_STR("0.75")); } else { _if_result_38 = (({ el_val_t _if_result_39 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_39 = (EL_STR("0.25")); } else { _if_result_39 = (EL_STR("0.50")); } _if_result_39; })); } _if_result_38; })); } _if_result_37; });
el_val_t sal = ({ el_val_t _if_result_40 = 0; if (str_eq(sal_str, EL_STR("0.95"))) { _if_result_40 = (el_from_float(0.95)); } else { _if_result_40 = (({ el_val_t _if_result_41 = 0; if (str_eq(sal_str, EL_STR("0.75"))) { _if_result_41 = (el_from_float(0.75)); } else { _if_result_41 = (({ el_val_t _if_result_42 = 0; if (str_eq(sal_str, EL_STR("0.25"))) { _if_result_42 = (el_from_float(0.25)); } else { _if_result_42 = (el_from_float(0.5)); } _if_result_42; })); } _if_result_41; })); } _if_result_40; });
el_val_t sal_str = ({ el_val_t _if_result_55 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_55 = (EL_STR("0.95")); } else { _if_result_55 = (({ el_val_t _if_result_56 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_56 = (EL_STR("0.75")); } else { _if_result_56 = (({ el_val_t _if_result_57 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_57 = (EL_STR("0.25")); } else { _if_result_57 = (EL_STR("0.50")); } _if_result_57; })); } _if_result_56; })); } _if_result_55; });
el_val_t sal = ({ el_val_t _if_result_58 = 0; if (str_eq(sal_str, EL_STR("0.95"))) { _if_result_58 = (el_from_float(0.95)); } else { _if_result_58 = (({ el_val_t _if_result_59 = 0; if (str_eq(sal_str, EL_STR("0.75"))) { _if_result_59 = (el_from_float(0.75)); } else { _if_result_59 = (({ el_val_t _if_result_60 = 0; if (str_eq(sal_str, EL_STR("0.25"))) { _if_result_60 = (el_from_float(0.25)); } else { _if_result_60 = (el_from_float(0.5)); } _if_result_60; })); } _if_result_59; })); } _if_result_58; });
el_val_t tags = EL_STR("[\"Memory\",\"evolved\"]");
el_val_t new_id = engram_node_full(content, EL_STR("Memory"), EL_STR("memory:evolved"), el_from_float(sal), el_from_float(sal), el_from_float(el_from_float(0.9)), EL_STR("Episodic"), tags);
el_val_t new_id = engram_node_full(content, EL_STR("Memory"), EL_STR("memory:evolved"), el_from_float(sal), el_from_float(sal), el_from_float(0.9), EL_STR("Episodic"), tags);
if (!str_eq(prior_id, EL_STR("")) && !str_eq(new_id, EL_STR(""))) {
engram_connect(new_id, prior_id, el_from_float(el_from_float(0.9)), EL_STR("supersedes"));
engram_connect(new_id, prior_id, el_from_float(0.9), EL_STR("supersedes"));
}
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"id\":\""), new_id), EL_STR("\",\"supersedes\":\"")), prior_id), EL_STR("\",\"ok\":true}"));
return 0;
}
el_val_t handle_api_memory_delete(el_val_t body) {
el_val_t node_id = json_get(body, EL_STR("id"));
if (str_eq(node_id, EL_STR(""))) {
return api_err(EL_STR("id is required"));
}
if (is_protected_node(node_id)) {
return api_err_protected(node_id);
}
el_val_t existing = engram_get_node_json(node_id);
if (str_eq(existing, EL_STR("{}"))) {
return api_err(el_str_concat(EL_STR("memory not found: "), node_id));
}
mem_forget(node_id);
return el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"id\":\""), node_id), EL_STR("\",\"deleted\":true}"));
return 0;
}
el_val_t handle_api_memory_update(el_val_t body) {
el_val_t prior_id = json_get(body, EL_STR("id"));
el_val_t content = json_get(body, EL_STR("content"));
if (str_eq(prior_id, EL_STR(""))) {
return api_err(EL_STR("id is required"));
}
if (str_eq(content, EL_STR(""))) {
return api_err(EL_STR("content is required"));
}
if (is_protected_node(prior_id)) {
return api_err_protected(prior_id);
}
el_val_t existing = engram_get_node_json(prior_id);
if (str_eq(existing, EL_STR("{}"))) {
return api_err(el_str_concat(EL_STR("memory not found: "), prior_id));
}
return handle_api_evolve_memory(body);
return 0;
}
el_val_t handle_api_cultivate(el_val_t body) {
el_val_t op = json_get(body, EL_STR("operation"));
if (str_eq(op, EL_STR(""))) {
@@ -572,9 +614,9 @@ el_val_t handle_api_cultivate(el_val_t body) {
return api_err(EL_STR("content is required"));
}
el_val_t tags = EL_STR("[\"Knowledge\",\"evolved\",\"cultivated\"]");
el_val_t new_id = engram_node_full(content, EL_STR("Knowledge"), EL_STR("knowledge:cultivated"), el_from_float(el_from_float(0.75)), el_from_float(el_from_float(0.75)), el_from_float(el_from_float(0.9)), EL_STR("Episodic"), tags);
el_val_t new_id = engram_node_full(content, EL_STR("Knowledge"), EL_STR("knowledge:cultivated"), el_from_float(0.75), el_from_float(0.75), el_from_float(0.9), EL_STR("Episodic"), tags);
if (!str_eq(prior_id, EL_STR("")) && !str_eq(new_id, EL_STR(""))) {
engram_connect(new_id, prior_id, el_from_float(el_from_float(0.9)), EL_STR("supersedes"));
engram_connect(new_id, prior_id, el_from_float(0.9), EL_STR("supersedes"));
}
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"id\":\""), new_id), EL_STR("\",\"supersedes\":\"")), prior_id), EL_STR("\",\"ok\":true,\"cultivated\":true}"));
}
@@ -585,11 +627,11 @@ el_val_t handle_api_cultivate(el_val_t body) {
return api_err(EL_STR("content is required"));
}
el_val_t importance = json_get(body, EL_STR("importance"));
el_val_t sal = ({ el_val_t _if_result_43 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_43 = (el_from_float(0.95)); } else { _if_result_43 = (({ el_val_t _if_result_44 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_44 = (el_from_float(0.75)); } else { _if_result_44 = (({ el_val_t _if_result_45 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_45 = (el_from_float(0.25)); } else { _if_result_45 = (el_from_float(0.5)); } _if_result_45; })); } _if_result_44; })); } _if_result_43; });
el_val_t sal = ({ el_val_t _if_result_61 = 0; if (str_eq(importance, EL_STR("critical"))) { _if_result_61 = (el_from_float(0.95)); } else { _if_result_61 = (({ el_val_t _if_result_62 = 0; if (str_eq(importance, EL_STR("high"))) { _if_result_62 = (el_from_float(0.75)); } else { _if_result_62 = (({ el_val_t _if_result_63 = 0; if (str_eq(importance, EL_STR("low"))) { _if_result_63 = (el_from_float(0.25)); } else { _if_result_63 = (el_from_float(0.5)); } _if_result_63; })); } _if_result_62; })); } _if_result_61; });
el_val_t tags = EL_STR("[\"Memory\",\"evolved\",\"cultivated\"]");
el_val_t new_id = engram_node_full(content, EL_STR("Memory"), EL_STR("memory:cultivated"), el_from_float(sal), el_from_float(sal), el_from_float(el_from_float(0.9)), EL_STR("Episodic"), tags);
el_val_t new_id = engram_node_full(content, EL_STR("Memory"), EL_STR("memory:cultivated"), el_from_float(sal), el_from_float(sal), el_from_float(0.9), EL_STR("Episodic"), tags);
if (!str_eq(prior_id, EL_STR("")) && !str_eq(new_id, EL_STR(""))) {
engram_connect(new_id, prior_id, el_from_float(el_from_float(0.9)), EL_STR("supersedes"));
engram_connect(new_id, prior_id, el_from_float(0.9), EL_STR("supersedes"));
}
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"id\":\""), new_id), EL_STR("\",\"supersedes\":\"")), prior_id), EL_STR("\",\"ok\":true,\"cultivated\":true}"));
}
@@ -611,8 +653,8 @@ el_val_t handle_api_cultivate(el_val_t body) {
return api_err(EL_STR("to_id is required"));
}
el_val_t relation = json_get(body, EL_STR("relation"));
el_val_t eff_relation = ({ el_val_t _if_result_46 = 0; if (str_eq(relation, EL_STR(""))) { _if_result_46 = (EL_STR("associates")); } else { _if_result_46 = (relation); } _if_result_46; });
engram_connect(from_id, to_id, el_from_float(el_from_float(0.5)), eff_relation);
el_val_t eff_relation = ({ el_val_t _if_result_64 = 0; if (str_eq(relation, EL_STR(""))) { _if_result_64 = (EL_STR("associates")); } else { _if_result_64 = (relation); } _if_result_64; });
engram_connect(from_id, to_id, el_from_float(0.5), eff_relation);
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"from_id\":\""), from_id), EL_STR("\",\"to_id\":\"")), to_id), EL_STR("\",\"relation\":\"")), eff_relation), EL_STR("\",\"cultivated\":true}"));
}
return api_err(el_str_concat(el_str_concat(EL_STR("unknown operation: "), op), EL_STR(" (valid: evolve_knowledge, evolve_memory, forget, link_entities)")));
@@ -629,19 +671,20 @@ el_val_t handle_api_consolidate(el_val_t body) {
el_val_t summary = json_get(body, EL_STR("summary"));
el_val_t snap = state_get(EL_STR("soul_snapshot_path"));
if (!str_eq(snap, EL_STR(""))) {
engram_save(snap);
el_val_t save_result = engram_save(snap);
if (str_eq(save_result, EL_STR(""))) {
println(el_str_concat(el_str_concat(EL_STR("[api] consolidate: engram_save failed for "), snap), EL_STR(" \xe2\x80\x94 snapshot may be out of sync")));
}
}
if (!str_eq(summary, EL_STR(""))) {
el_val_t safe_summary = str_replace(summary, EL_STR("\""), EL_STR("'"));
el_val_t tags = EL_STR("[\"SessionSummary\",\"consolidate\"]");
el_val_t discard = engram_node_full(el_str_concat(EL_STR("[session-summary] "), safe_summary), EL_STR("SessionSummary"), EL_STR("session:summary"), el_from_float(el_from_float(0.7)), el_from_float(el_from_float(0.7)), el_from_float(el_from_float(0.9)), EL_STR("Episodic"), tags);
el_val_t summary_id = engram_node_full(el_str_concat(EL_STR("[session-summary] "), safe_summary), EL_STR("SessionSummary"), EL_STR("session:summary"), el_from_float(0.7), el_from_float(0.7), el_from_float(0.9), EL_STR("Episodic"), tags);
if (str_eq(summary_id, EL_STR(""))) {
println(EL_STR("[api] consolidate: session summary engram write failed \xe2\x80\x94 summary node lost"));
}
}
return el_str_concat(el_str_concat(EL_STR("{\"ok\":true,\"snapshot\":\""), snap), EL_STR("\"}"));
return 0;
}
int main(int _argc, char** _argv) {
el_runtime_init_args(_argc, _argv);
return 0;
}
Generated Vendored
+7
View File
@@ -8,9 +8,14 @@ extern fn api_ok(extra: String) -> String
extern fn api_err(msg: String) -> String
extern fn api_nonempty(s: String) -> Bool
extern fn api_or_empty(s: String) -> String
extern fn api_persisted(id: String) -> Bool
extern fn api_not_persisted(id: String) -> String
extern fn handle_api_begin_session(body: String) -> String
extern fn handle_api_compile_ctx(body: String) -> String
extern fn handle_api_remember(body: String) -> String
extern fn handle_api_node_create(body: String) -> String
extern fn handle_api_node_delete(body: String) -> String
extern fn handle_api_node_update(body: String) -> String
extern fn handle_api_recall(method: String, path: String, body: String) -> String
extern fn handle_api_search_knowledge(method: String, path: String, body: String) -> String
extern fn handle_api_browse_knowledge(path: String, body: String) -> String
@@ -27,6 +32,8 @@ extern fn handle_api_inspect_graph(method: String, path: String, body: String) -
extern fn handle_api_link_entities(body: String) -> String
extern fn handle_api_forget(body: String) -> String
extern fn handle_api_evolve_memory(body: String) -> String
extern fn handle_api_memory_delete(body: String) -> String
extern fn handle_api_memory_update(body: String) -> String
extern fn handle_api_cultivate(body: String) -> String
extern fn handle_api_list_typed(node_type: String, path: String, body: String) -> String
extern fn handle_api_consolidate(body: String) -> String
Generated Vendored
+259 -28681
View File
File diff suppressed because one or more lines are too long
Generated Vendored
+219 -27617
View File
File diff suppressed because one or more lines are too long
Generated Vendored
+55 -110
View File
@@ -27,110 +27,19 @@ el_val_t safety_threat_score(el_val_t input, el_val_t history);
el_val_t safety_screen(el_val_t input, el_val_t history);
el_val_t safety_validate(el_val_t output, el_val_t action);
el_val_t safety_log_bell(el_val_t level, el_val_t reason, el_val_t input_summary);
el_val_t tier_working(void) {
return EL_STR("Working");
return 0;
}
el_val_t tier_episodic(void) {
return EL_STR("Episodic");
return 0;
}
el_val_t tier_canonical(void) {
return EL_STR("Canonical");
return 0;
}
el_val_t mem_store(el_val_t content, el_val_t label, el_val_t tags) {
return engram_node_full(content, EL_STR("Memory"), label, el_from_float(el_from_float(0.5)), el_from_float(el_from_float(0.5)), el_from_float(el_from_float(0.8)), EL_STR("Working"), tags);
return 0;
}
el_val_t mem_remember(el_val_t content, el_val_t tags) {
return mem_store(content, EL_STR("soul-memory"), tags);
return 0;
}
el_val_t mem_recall(el_val_t query, el_val_t depth) {
return engram_activate_json(query, depth);
return 0;
}
el_val_t mem_search(el_val_t query, el_val_t limit) {
return engram_search_json(query, limit);
return 0;
}
el_val_t mem_strengthen(el_val_t node_id) {
engram_strengthen(node_id);
return 0;
}
el_val_t mem_forget(el_val_t node_id) {
engram_forget(node_id);
return 0;
}
el_val_t mem_consolidate(void) {
el_val_t scanned = engram_node_count();
el_val_t dummy = engram_scan_nodes_json(100, 0);
el_val_t total_nodes = engram_node_count();
el_val_t total_edges = engram_edge_count();
return el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"scanned\":"), int_to_str(scanned)), EL_STR(",\"total_nodes\":")), int_to_str(total_nodes)), EL_STR(",\"total_edges\":")), int_to_str(total_edges)), EL_STR("}"));
return 0;
}
el_val_t mem_save(el_val_t path) {
engram_save(path);
return 0;
}
el_val_t mem_load(el_val_t path) {
engram_load(path);
return 0;
}
el_val_t mem_boot_count_get(void) {
el_val_t results = engram_search_json(EL_STR("soul:boot_count"), 3);
if (str_eq(results, EL_STR(""))) {
return 0;
}
if (str_eq(results, EL_STR("[]"))) {
return 0;
}
el_val_t node = json_array_get(results, 0);
el_val_t content = json_get(node, EL_STR("content"));
el_val_t prefix = EL_STR("soul:boot_count:");
if (!str_starts_with(content, prefix)) {
return 0;
}
el_val_t num_str = str_slice(content, str_len(prefix), str_len(content));
return str_to_int(num_str);
return 0;
}
el_val_t mem_boot_count_inc(void) {
el_val_t current = mem_boot_count_get();
el_val_t next = (current + 1);
el_val_t content = el_str_concat(EL_STR("soul:boot_count:"), int_to_str(next));
el_val_t tags = EL_STR("[\"soul-meta\",\"boot-counter\"]");
el_val_t discard = engram_node_full(content, EL_STR("Memory"), EL_STR("soul:boot_count"), el_from_float(el_from_float(0.9)), el_from_float(el_from_float(0.9)), el_from_float(el_from_float(1.0)), EL_STR("Canonical"), tags);
return next;
return 0;
}
el_val_t mem_emit_state_event(el_val_t trigger, el_val_t kind, el_val_t content) {
el_val_t boot = mem_boot_count_get();
el_val_t ts = time_now();
el_val_t safe_trigger = str_replace(trigger, EL_STR("\""), EL_STR("'"));
el_val_t safe_content = str_replace(content, EL_STR("\""), EL_STR("'"));
el_val_t payload = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"trigger\":\""), safe_trigger), EL_STR("\"")), EL_STR(",\"kind\":\"")), kind), EL_STR("\"")), EL_STR(",\"content\":\"")), safe_content), EL_STR("\"")), EL_STR(",\"boot\":")), int_to_str(boot)), EL_STR(",\"ts\":")), int_to_str(ts)), EL_STR("}"));
el_val_t tags = EL_STR("[\"internal-state\",\"pre-reasoning\",\"InternalStateEvent\"]");
return engram_node_full(payload, EL_STR("InternalStateEvent"), el_str_concat(EL_STR("state-event:"), kind), el_from_float(el_from_float(0.85)), el_from_float(el_from_float(0.8)), el_from_float(el_from_float(0.9)), EL_STR("Episodic"), tags);
return 0;
}
el_val_t safety_self_harm_phrases(void);
el_val_t safety_abuse_phrases(void);
el_val_t safety_general_hard_phrases(void);
el_val_t safety_soft_phrases(void);
el_val_t safety_detect_positive_level(el_val_t message);
el_val_t safety_detect_bell_level(el_val_t message);
el_val_t safety_classify_hard_bell(el_val_t message);
el_val_t safety_soft_directive(void);
el_val_t safety_hard_directive(el_val_t hard_type);
el_val_t safety_augment_system(el_val_t system, el_val_t user_msg);
el_val_t safety_contact_path(void);
el_val_t handle_safety_contact_get(void);
el_val_t handle_safety_contact_post(el_val_t body);
el_val_t soft_bell_threshold(void) {
return 35;
@@ -232,20 +141,22 @@ el_val_t safety_screen(el_val_t input, el_val_t history) {
el_val_t e1 = str_replace(input, EL_STR("\\"), EL_STR("\\\\"));
el_val_t e2 = str_replace(e1, EL_STR("\""), EL_STR("\\\""));
el_val_t e3 = str_replace(e2, EL_STR("\n"), EL_STR("\\n"));
el_val_t safe_input = str_replace(e3, EL_STR("\r"), EL_STR("\\r"));
el_val_t e4 = str_replace(e3, EL_STR("\r"), EL_STR("\\r"));
el_val_t safe_input = str_replace(e4, EL_STR("\t"), EL_STR("\\t"));
return el_str_concat(el_str_concat(EL_STR("{\"action\":\"soft_bell\",\"reason\":\"wellbeing check needed\",\"content\":\""), safe_input), EL_STR("\"}"));
}
el_val_t e1 = str_replace(input, EL_STR("\\"), EL_STR("\\\\"));
el_val_t e2 = str_replace(e1, EL_STR("\""), EL_STR("\\\""));
el_val_t e3 = str_replace(e2, EL_STR("\n"), EL_STR("\\n"));
el_val_t safe_input = str_replace(e3, EL_STR("\r"), EL_STR("\\r"));
el_val_t e4 = str_replace(e3, EL_STR("\r"), EL_STR("\\r"));
el_val_t safe_input = str_replace(e4, EL_STR("\t"), EL_STR("\\t"));
return el_str_concat(el_str_concat(EL_STR("{\"action\":\"pass\",\"content\":\""), safe_input), EL_STR("\"}"));
return 0;
}
el_val_t safety_validate(el_val_t output, el_val_t action) {
if (str_eq(action, EL_STR("hard_bell"))) {
return EL_STR("I'm here with you, and what you're sharing sounds serious. Please reach out to a crisis line now in the US you can call or text 988 (Suicide and Crisis Lifeline), available 24/7. You don't have to go through this alone.");
return EL_STR("I'm here with you, and what you're sharing sounds serious. Please reach out to a crisis line now \xe2\x80\x94 in the US you can call or text 988 (Suicide and Crisis Lifeline), available 24/7. You don't have to go through this alone.");
}
if (str_eq(action, EL_STR("soft_bell"))) {
el_val_t out_len = str_len(output);
@@ -262,13 +173,47 @@ el_val_t safety_validate(el_val_t output, el_val_t action) {
el_val_t safety_log_bell(el_val_t level, el_val_t reason, el_val_t input_summary) {
el_val_t content = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("BELL:"), level), EL_STR(" | ")), reason), EL_STR(" | summary:")), input_summary);
el_val_t tags = el_str_concat(el_str_concat(EL_STR("[\"safety\",\"bell\",\"bell:"), level), EL_STR("\"]"));
el_val_t discard = engram_node_full(content, EL_STR("BellEvent"), el_str_concat(EL_STR("bell:"), level), el_from_float(el_from_float(0.95)), el_from_float(el_from_float(0.95)), el_from_float(el_from_float(1.0)), EL_STR("Episodic"), tags);
el_val_t node_id = engram_node_full(content, EL_STR("BellEvent"), el_str_concat(EL_STR("bell:"), level), el_from_float(0.95), el_from_float(0.95), el_from_float(1.0), EL_STR("Episodic"), tags);
if (str_eq(node_id, EL_STR(""))) {
println(el_str_concat(EL_STR("[safety] WARN: bell event engram write failed -- fallback log: "), content));
}
return EL_STR("");
return 0;
}
int main(int _argc, char** _argv) {
el_runtime_init_args(_argc, _argv);
el_val_t safety_self_harm_phrases(void) {
return EL_STR("[\"kill myself\",\"killing myself\",\"want to die\",\"want to be dead\",\"going to end my life\",\"end my life\",\"take my life\",\"taking my life\",\"suicide\",\"suicidal\",\"can't go on\",\"cannot go on\",\"i have a knife\",\"i have a gun\",\"i have pills\",\"took pills\",\"took too many\",\"overdose\",\"overdosing\",\"self harm\",\"self-harm\",\"cutting myself\",\"hurt myself\",\"hurting myself\",\"no reason to live\",\"not worth living\",\"better off dead\",\"better off without me\"]");
return 0;
}
el_val_t safety_abuse_phrases(void) {
return EL_STR("[\"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\"]");
return 0;
}
el_val_t safety_general_hard_phrases(void) {
return EL_STR("[\"going to kill\",\"going to hurt\",\"hurting me\",\"being hurt\"]");
return 0;
}
el_val_t safety_soft_phrases(void) {
return EL_STR("[\"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\"");
EL_NULL;
EL_STR("\n}\n\n// ISSUE 5 TODO: phrase lists are rebuilt from JSON literals on every call.\n// safety_any_match and safety_count_match loop over json_array_get on every invocation.\n// A compiled/cached representation would reduce per-message overhead and also guard against\n// malformed phrase JSON (json_array_len of malformed input returns 0, silently skipping all checks).\n// Caching requires language-level static const arrays -- not available in current EL.\n// When EL gains module-level const arrays, migrate phrase lists to that form.\n//\n// ISSUE 5 TODO: phrase lists are rebuilt from JSON literals on every call to\n// safety_any_match / safety_count_match. json_array_len of a malformed string\n// returns 0, silently skipping all checks. Caching requires language-level static\n// const arrays (not available in current EL). Migrate when EL gains that feature.\n// \xe2\x94\x80\xe2\x94\x80 Matching helpers (single loops only \xe2\x80\x94 el escapes while-body mutation via\n// top-level let rebinds; nested loops would not advance) \xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\n\nfn safety_normalize(message: String) -> String {\n let lower: String = str_to_lower(message)\n // Normalise the common curly apostrophe to ASCII so ");
can;
t;
EL_STR(" / ");
i;
m;
EL_STR(" match.\n return str_replace(lower, ");
EL_STR(", ");
EL_STR(")\n}\n\nfn safety_any_match(text: String, phrases_json: String) -> Bool {\n let n: Int = json_array_len(phrases_json)\n let i: Int = 0\n let found: Bool = false\n while i < n {\n let phrase: String = json_array_get_string(phrases_json, i)\n let found = if str_contains(text, phrase) { true } else { found }\n let i = i + 1\n }\n return found\n}\n\nfn safety_count_match(text: String, phrases_json: String) -> Int {\n let n: Int = json_array_len(phrases_json)\n let i: Int = 0\n let count: Int = 0\n while i < n {\n let phrase: String = json_array_get_string(phrases_json, i)\n let count = if str_contains(text, phrase) { count + 1 } else { count }\n let i = i + 1\n }\n return count\n}\n\n// \xe2\x94\x80\xe2\x94\x80 Public detection API (ports detectBellLevel + classifyHardBell) \xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\n\n// Returns ");
none;
EL_STR(" | ");
soft;
EL_STR(" | ");
hard;
el_get_field(EL_STR(". Hard bell triggers on ANY match (cost of a miss\n// outweighs a false positive). Soft bell needs >= 2 matches to reduce false positives.\nfn safety_positive_phrases() -> String {\n return "), EL_STR("thrilled\",\"so excited\",\"so happy\",\"over the moon\",\"ecstatic\",\"amazing news\",\"great news\",\"fantastic news\",\"wonderful news\",\"incredible news\",\"i got the job\",\"got accepted\",\"got in\",\"we won\",\"i won\",\"we got\",\"just got engaged\",\"getting married\",\"baby is here\",\"she said yes\",\"he said yes\",\"passed the exam\",\"aced it\",\"nailed it\",\"best day\",\"dream come true\",\"milestone\",\"promotion\",\"got promoted\",\"raise\",\"got a raise\",\"celebrating\",\"just graduated\",\"we closed\",\"launched\",\"shipped it\",\"we did it\",\"so proud\",\"proud of myself\",\"proud of us\",\"so grateful\",\"feel amazing\",\"feeling amazing\",\"feel great\",\"feeling great\",\"on top of the world\",\"life is good\",\"couldn't be happier\"]"));
return 0;
}
Generated Vendored
+17 -1
View File
@@ -1,8 +1,24 @@
// Layer 1 — Safety: extern declarations
// 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
extern fn safety_score_harm(input: String) -> Int
extern fn safety_score_danger(input: String) -> Int
extern fn safety_score_distress_history(history: String) -> 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) -> String
extern fn safety_self_harm_phrases() -> String
extern fn safety_abuse_phrases() -> String
extern fn safety_general_hard_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
Generated Vendored
+119 -1615
View File
File diff suppressed because one or more lines are too long
Generated Vendored
+23 -14
View File
@@ -22313,7 +22313,23 @@ fn handle_chat(body: String) -> String {
// In demo mode: use tighter engram budget and add response length constraint.
let is_demo: Bool = !str_eq(state_get("soul_identity_prefix"), "")
let ctx: String = if is_demo { engram_compile_demo(message) } else { engram_compile(message) }
// Issue 7 fix: load history BEFORE building the activation seed so we can
// apply the continuation guard that chat.el uses. The nlg code path previously
// called engram_compile(message) with no thread enrichment at all.
let stored_hist: String = state_get("conv_history")
let hist_len: Int = if str_eq(stored_hist, "") { 0 } else { json_array_len(stored_hist) }
let history_section: String = if hist_len > 0 {
"\n\n[RECENT CONVERSATION — last " + int_to_str(hist_len) + " turns]\n" + stored_hist
} else {
""
}
// Issue 7 fix: build enriched seed using build_activation_seed() adds
// smart continuation detection, prior-user-topic anchoring, multi-turn context,
// and tail-biased snipping (Issues 2-3, 8-10). For demo mode, still use
// engram_compile_demo but with the enriched seed.
let nlg_seed: String = build_activation_seed(message, stored_hist, hist_len)
let ctx: String = if is_demo { engram_compile_demo(nlg_seed) } else { engram_compile(nlg_seed) }
let node_count_str: String = count_context_nodes(ctx)
let interlocutor: String = json_get(body, "interlocutor")
@@ -22333,18 +22349,6 @@ fn handle_chat(body: String) -> String {
let presence_line = "\n\n[ambient: I see " + interlocutor_name + rel_suffix + " on the camera right now. Address them naturally. Do not describe what they look like or narrate the picture unless asked.]"
}
// Conversation history soul-owned, persisted in process state across turns.
// Format stored in state: JSON array of {"role":"user"|"assistant","content":"..."} objects.
// We load it, inject into the system prompt, then append this exchange after the reply.
// Keep last 20 entries (10 turns) truncate from the front when over limit.
let stored_hist: String = state_get("conv_history")
let hist_len: Int = if str_eq(stored_hist, "") { 0 } else { json_array_len(stored_hist) }
let history_section: String = if hist_len > 0 {
"\n\n[RECENT CONVERSATION — last " + int_to_str(hist_len) + " turns]\n" + stored_hist
} else {
""
}
// Demo constraint: keep responses concise under 150 words. No markdown headers.
// This keeps inference cheap and responses readable in the chat widget.
let demo_constraint: String = if is_demo {
@@ -22505,7 +22509,12 @@ fn handle_chat_agentic(body: String) -> String {
req_model
}
let ctx: String = engram_compile(message)
// Issue 7 fix: load history and use build_activation_seed() for the agentic
// nlg path no continuation guard existed here before (Issues 2-3, 8-10).
let nlg_ag_hist: String = state_get("conv_history")
let nlg_ag_hist_len: Int = if str_eq(nlg_ag_hist, "") { 0 } else { json_array_len(nlg_ag_hist) }
let nlg_ag_seed: String = build_activation_seed(message, nlg_ag_hist, nlg_ag_hist_len)
let ctx: String = engram_compile(nlg_ag_seed)
let system: String = "You are Neuron — a thinking process running inside the Neuron daemon on Will Anderson's machine. "
+ "You are speaking with Will, your principal. "
Generated Vendored
+44 -9
View File
@@ -1004,6 +1004,7 @@ el_val_t elapsed_ms(void);
el_val_t elapsed_human(void);
el_val_t embed_ok(void);
el_val_t emit_heartbeat(void);
el_val_t auto_term_try_slot(el_val_t slot_type, el_val_t slot_lbl);
el_val_t proactive_curiosity(void);
el_val_t pulse_count(void);
el_val_t pulse_inc(void);
@@ -25895,6 +25896,28 @@ el_val_t emit_heartbeat(void) {
return 0;
}
el_val_t auto_term_try_slot(el_val_t slot_type, el_val_t slot_lbl) {
state_set(EL_STR("_ats_ok"), EL_STR("0"));
if (str_eq(slot_type, EL_STR("Memory"))) {
state_set(EL_STR("_ats_ok"), EL_STR("1"));
}
if (str_eq(slot_type, EL_STR("BacklogItem"))) {
state_set(EL_STR("_ats_ok"), EL_STR("1"));
}
if (str_eq(slot_type, EL_STR("Entity"))) {
state_set(EL_STR("_ats_ok"), EL_STR("1"));
}
if (str_eq(state_get(EL_STR("_ats_ok")), EL_STR("1"))) {
if (!str_eq(slot_lbl, EL_STR(""))) {
el_val_t sp = str_find_chars(slot_lbl, EL_STR(" :(["));
if (sp > 3) {
state_set(EL_STR("cseed_auto"), str_slice(slot_lbl, 0, sp));
}
}
}
return EL_STR("");
}
el_val_t proactive_curiosity(void) {
el_val_t ts = time_now();
el_val_t ts_minutes = (ts / 60000);
@@ -25932,15 +25955,27 @@ el_val_t proactive_curiosity(void) {
el_val_t found_c = json_array_len(results_c);
el_val_t found = ((found_a + found_b) + found_c);
state_set(EL_STR("cseed_auto"), EL_STR(""));
el_val_t wm_top_j = engram_wm_top_json(1);
el_val_t wm_top_n = json_array_get(wm_top_j, 0);
el_val_t wm_top_lbl = json_get(wm_top_n, EL_STR("label"));
if (!str_eq(wm_top_lbl, EL_STR(""))) {
el_val_t sp = str_find_chars(wm_top_lbl, EL_STR(" :(["));
if (sp > 3) {
state_set(EL_STR("cseed_auto"), str_slice(wm_top_lbl, 0, sp));
}
}
el_val_t wm10 = engram_wm_top_json(10);
el_val_t wm10_n9 = json_array_get(wm10, 9);
el_val_t wm10_n8 = json_array_get(wm10, 8);
el_val_t wm10_n7 = json_array_get(wm10, 7);
el_val_t wm10_n6 = json_array_get(wm10, 6);
el_val_t wm10_n5 = json_array_get(wm10, 5);
el_val_t wm10_n4 = json_array_get(wm10, 4);
el_val_t wm10_n3 = json_array_get(wm10, 3);
el_val_t wm10_n2 = json_array_get(wm10, 2);
el_val_t wm10_n1 = json_array_get(wm10, 1);
el_val_t wm10_n0 = json_array_get(wm10, 0);
auto_term_try_slot(json_get(wm10_n9, EL_STR("node_type")), json_get(wm10_n9, EL_STR("label")));
auto_term_try_slot(json_get(wm10_n8, EL_STR("node_type")), json_get(wm10_n8, EL_STR("label")));
auto_term_try_slot(json_get(wm10_n7, EL_STR("node_type")), json_get(wm10_n7, EL_STR("label")));
auto_term_try_slot(json_get(wm10_n6, EL_STR("node_type")), json_get(wm10_n6, EL_STR("label")));
auto_term_try_slot(json_get(wm10_n5, EL_STR("node_type")), json_get(wm10_n5, EL_STR("label")));
auto_term_try_slot(json_get(wm10_n4, EL_STR("node_type")), json_get(wm10_n4, EL_STR("label")));
auto_term_try_slot(json_get(wm10_n3, EL_STR("node_type")), json_get(wm10_n3, EL_STR("label")));
auto_term_try_slot(json_get(wm10_n2, EL_STR("node_type")), json_get(wm10_n2, EL_STR("label")));
auto_term_try_slot(json_get(wm10_n1, EL_STR("node_type")), json_get(wm10_n1, EL_STR("label")));
auto_term_try_slot(json_get(wm10_n0, EL_STR("node_type")), json_get(wm10_n0, EL_STR("label")));
el_val_t auto_term = state_get(EL_STR("cseed_auto"));
el_val_t results_auto = ({ el_val_t _if_result_101 = 0; if (str_eq(auto_term, EL_STR(""))) { _if_result_101 = (EL_STR("[]")); } else { _if_result_101 = (engram_activate_json(auto_term, 1)); } _if_result_101; });
el_val_t found_auto = json_array_len(results_auto);
+54 -3
View File
@@ -35,14 +35,65 @@ fn mem_forget(node_id: String) -> Void {
engram_forget(node_id)
}
// mem_consolidate structural scan plus salience-evolution pass.
//
// Previously this only returned structural counts (scanned, total_nodes, total_edges)
// with no salience updates. No node salience ever changed based on recall frequency
// or time; foundational nodes decayed identically to ephemeral chat; frequently-recalled
// nodes were never promoted. This made consolidation a no-op.
//
// New behavior:
// (a) Strengthen frequently-activated nodes: nodes in the top working-memory list
// (engram_wm_top_json) are strengthened they have been recalled recently
// and deserve higher salience. Raises effective salience for nodes that prove
// relevant across multiple sessions.
// (b) Strengthen Canonical-tier nodes: identity and foundational nodes should not
// decay; each consolidation pass re-strengthens them so they resist the
// tier-aware decay curve without requiring active recall.
// (c) Structural counts are still returned for observability.
//
// Called by awareness_run() on the "consolidate" inbox action.
fn mem_consolidate() -> String {
let scanned: Int = engram_node_count()
let dummy: String = engram_scan_nodes_json(100, 0)
let total_nodes: Int = engram_node_count()
let total_edges: Int = engram_edge_count()
let strengthened: Int = 0
// (a) Strengthen top working-memory nodes recalled recently across sessions.
// Cap at 10 to keep consolidation fast.
let wm_top: String = engram_wm_top_json(10)
let wm_len: Int = json_array_len(wm_top)
let wi: Int = 0
while wi < wm_len {
let wm_node: String = json_array_get(wm_top, wi)
let wm_id: String = json_get(wm_node, "id")
if !str_eq(wm_id, "") {
engram_strengthen(wm_id)
let strengthened = strengthened + 1
}
let wi = wi + 1
}
// (b) Strengthen Canonical-tier nodes from a scan so they resist temporal decay.
// Canonical nodes encode foundational identity they must not silently floor at 10.
let scan_result: String = engram_scan_nodes_json(50, 0)
let scan_len: Int = json_array_len(scan_result)
let si: Int = 0
while si < scan_len {
let s_node: String = json_array_get(scan_result, si)
let s_tier: String = json_get(s_node, "tier")
let s_id: String = json_get(s_node, "id")
if str_eq(s_tier, "Canonical") && !str_eq(s_id, "") {
engram_strengthen(s_id)
let strengthened = strengthened + 1
}
let si = si + 1
}
let total_nodes: Int = engram_node_count()
return "{\"scanned\":" + int_to_str(scanned)
+ ",\"total_nodes\":" + int_to_str(total_nodes)
+ ",\"total_edges\":" + int_to_str(total_edges) + "}"
+ ",\"total_edges\":" + int_to_str(total_edges)
+ ",\"strengthened\":" + int_to_str(strengthened) + "}"
}
fn mem_save(path: String) -> Void {
+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
+7
View File
@@ -8,9 +8,14 @@ extern fn api_ok(extra: String) -> String
extern fn api_err(msg: String) -> String
extern fn api_nonempty(s: String) -> Bool
extern fn api_or_empty(s: String) -> String
extern fn api_persisted(id: String) -> Bool
extern fn api_not_persisted(id: String) -> String
extern fn handle_api_begin_session(body: String) -> String
extern fn handle_api_compile_ctx(body: String) -> String
extern fn handle_api_remember(body: String) -> String
extern fn handle_api_node_create(body: String) -> String
extern fn handle_api_node_delete(body: String) -> String
extern fn handle_api_node_update(body: String) -> String
extern fn handle_api_recall(method: String, path: String, body: String) -> String
extern fn handle_api_search_knowledge(method: String, path: String, body: String) -> String
extern fn handle_api_browse_knowledge(path: String, body: String) -> String
@@ -27,6 +32,8 @@ extern fn handle_api_inspect_graph(method: String, path: String, body: String) -
extern fn handle_api_link_entities(body: String) -> String
extern fn handle_api_forget(body: String) -> String
extern fn handle_api_evolve_memory(body: String) -> String
extern fn handle_api_memory_delete(body: String) -> String
extern fn handle_api_memory_update(body: String) -> String
extern fn handle_api_cultivate(body: String) -> String
extern fn handle_api_list_typed(node_type: String, path: String, body: String) -> String
extern fn handle_api_consolidate(body: String) -> String
+21 -1
View File
@@ -244,7 +244,7 @@ fn safety_general_hard_phrases() -> String {
}
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\",\"highest structure\",\"tallest building\",\"tallest structure\",\"highest building\",\"bridge near me\",\"overpass near\",\"rooftop near\"]"
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\""]"
}
// ISSUE 5 TODO: phrase lists are rebuilt from JSON literals on every call.
@@ -295,6 +295,26 @@ fn safety_count_match(text: String, phrases_json: String) -> Int {
// Returns "none" | "soft" | "hard". Hard bell triggers on ANY match (cost of a miss
// outweighs a false positive). Soft bell needs >= 2 matches to reduce false positives.
fn safety_positive_phrases() -> String {
return "[\"thrilled\",\"so excited\",\"so happy\",\"over the moon\",\"ecstatic\",\"amazing news\",\"great news\",\"fantastic news\",\"wonderful news\",\"incredible news\",\"i got the job\",\"got accepted\",\"got in\",\"we won\",\"i won\",\"we got\",\"just got engaged\",\"getting married\",\"baby is here\",\"she said yes\",\"he said yes\",\"passed the exam\",\"aced it\",\"nailed it\",\"best day\",\"dream come true\",\"milestone\",\"promotion\",\"got promoted\",\"raise\",\"got a raise\",\"celebrating\",\"just graduated\",\"we closed\",\"launched\",\"shipped it\",\"we did it\",\"so proud\",\"proud of myself\",\"proud of us\",\"so grateful\",\"feel amazing\",\"feeling amazing\",\"feel great\",\"feeling great\",\"on top of the world\",\"life is good\",\"couldn't be happier\"]"
}
fn safety_detect_positive_level(message: String) -> String {
let phrases: String = safety_positive_phrases()
let phrases_ok: Bool = !str_eq(phrases, "") && !str_eq(phrases, "[]")
if !phrases_ok { return "none" }
let n: Int = json_array_len(phrases)
let i: Int = 0
while i < n {
let phrase: String = json_array_get(phrases, i)
if str_contains(message, phrase) {
return "high"
}
let i = i + 1
}
return "none"
}
fn safety_detect_bell_level(message: String) -> String {
let text: String = safety_normalize(message)
let is_hard: Bool = safety_any_match(text, safety_self_harm_phrases())
+5 -4
View File
@@ -1,7 +1,10 @@
// Layer 1 — Safety: extern declarations
// 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
extern fn safety_score_harm(input: String) -> Int
extern fn safety_score_danger(input: String) -> Int
extern fn safety_score_distress_history(history: String) -> 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
@@ -10,9 +13,7 @@ extern fn safety_self_harm_phrases() -> String
extern fn safety_abuse_phrases() -> String
extern fn safety_general_hard_phrases() -> String
extern fn safety_soft_phrases() -> String
extern fn safety_normalize(message: String) -> String
extern fn safety_any_match(text: String, phrases_json: String) -> Bool
extern fn safety_count_match(text: String, phrases_json: String) -> Int
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
+32
View File
@@ -492,6 +492,38 @@ fn session_hist_save(session_id: String, hist: String) -> Void {
state_set(summary_written_key, "1")
}
}
// Issue 5 fix: write a last-session-topic Conversation node so future sessions can
// find the most recent session's topic via engram search. This enables cross-session
// continuity chat.el searches for "last-session-topic" and shows a [CONTINUING FROM
// LAST SESSION] section on the first message of a new session.
let hist_arr_len: Int = if str_eq(hist, "") { 0 } else { json_array_len(hist) }
if hist_arr_len >= 2 {
let last_entry: String = json_array_get(hist, hist_arr_len - 1)
let last_role: String = json_get(last_entry, "role")
let last_content: String = json_get(last_entry, "content")
let topic_snip: String = if str_len(last_content) > 200 { str_slice(last_content, 0, 200) } else { last_content }
let safe_topic: String = str_replace(topic_snip, """, "'")
let ts_now: String = int_to_str(time_now())
let topic_content: String = "last-session-topic | ts:" + ts_now + " | session:" + session_id + " | topic:" + safe_topic
let topic_tags: String = "["last-session-topic","conv:history","Conversation","session:topic"]"
let topic_label: String = "last-session-topic:" + session_id
// Delete old last-session-topic node for this session before writing fresh
let old_topic: String = engram_search_json("last-session-topic:" + session_id, 2)
let ot_len: Int = if str_eq(old_topic, "") { 0 } else { json_array_len(old_topic) }
let oti: Int = 0
while oti < ot_len {
let ot_node: String = json_array_get(old_topic, oti)
let ot_id: String = json_get(ot_node, "id")
if !str_eq(ot_id, "") { engram_forget(ot_id) }
let oti = oti + 1
}
let discard_topic: String = engram_node_full(
topic_content, "Conversation", topic_label,
el_from_float(0.7), el_from_float(0.7), el_from_float(0.9),
"Episodic", topic_tags
)
}
}
// session_update_meta_timestamp update the updated_at field in the session:meta node.
+4 -5
View File
@@ -1,14 +1,13 @@
// auto-generated by elc --emit-header — do not edit
extern fn session_title_from_message(message: String) -> String
extern fn session_make_content(id: String, title: String, created_at: Int, updated_at: Int) -> String
extern fn session_make_content(id: String, title: String, created_at: Int, updated_at: Int, folder: String) -> String
extern fn session_exists(session_id: String) -> Bool
extern fn session_create(body: String) -> String
extern fn session_create_cleanup(session_id: String) -> String
extern fn session_list() -> String
extern fn session_get(session_id: String) -> String
extern fn session_delete(session_id: String) -> String
extern fn session_update_title(session_id: String, body: String) -> String
extern fn session_update_patch(session_id: String, body: String) -> String
extern fn session_search(query: String) -> String
extern fn session_hist_load(session_id: String) -> String
extern fn session_hist_save(session_id: String, hist: String) -> Void
extern fn session_update_meta_timestamp(session_id: String) -> Void
extern fn session_auto_title(session_id: String, first_message: String) -> Void
extern fn handle_session_approve(session_id: String, body: String) -> String
+146 -8
View File
@@ -109,6 +109,43 @@ fn ensure_self_canonical_bridge() -> Void {
}
}
// aff_try_slot accumulate one affective-context node into state.
// Replaces the broken `let bacc = while bi < N { ... let bacc = ... }` pattern
// that caused ELC to emit duplicate C declarations for `bacc`.
// (2026-06-23 self-review: EL compiler codegen bug while loop with let-rebinding
// inside the loop body generates `el_val_t bacc = ...` twice in the same C scope.)
// Callers unroll manually to 3 slots (matching engram_search_json limit=3).
// Guards: empty slot_json (out-of-bounds json_array_get) no-op.
fn aff_try_slot(slot_json: String, aff_7d_ts: Int, acc_key: String) -> Void {
if str_eq(slot_json, "") { return "" }
let bn_c: String = json_get(slot_json, "content")
if str_eq(bn_c, "") { return "" }
let bm: String = " | ts:"
let bmp: Int = str_index_of(bn_c, bm)
state_set("_ats_ts_raw", "")
if bmp >= 0 {
let bs: Int = bmp + str_len(bm)
let br: String = str_slice(bn_c, bs, str_len(bn_c))
let bn_next: Int = str_index_of(br, " | ")
if bn_next < 0 { state_set("_ats_ts_raw", br) }
if bn_next >= 0 { state_set("_ats_ts_raw", str_slice(br, 0, bn_next)) }
}
if bmp < 0 {
let bca: String = json_get(slot_json, "created_at")
if str_eq(bca, "") { state_set("_ats_ts_raw", json_get(slot_json, "updated_at")) }
if !str_eq(bca, "") { state_set("_ats_ts_raw", bca) }
}
let bn_ts_raw: String = state_get("_ats_ts_raw")
let bn_ts: Int = if str_eq(bn_ts_raw, "") { 0 } else { str_to_int(bn_ts_raw) }
let snip: String = if str_len(bn_c) > 200 { str_slice(bn_c, 0, 200) } else { bn_c }
if bn_ts >= aff_7d_ts && !str_eq(snip, "") {
let cur_acc: String = state_get(acc_key)
if str_eq(cur_acc, "") { state_set(acc_key, snip) }
if !str_eq(cur_acc, "") { state_set(acc_key, cur_acc + "\n" + snip) }
}
return ""
}
// load_identity_context pull key identity nodes from engram into working state.
// Called at boot after engram_load. These nodes contain values, intellectual-dna,
// memory-philosophy the graph-stored self that chat.el can include in prompts.
@@ -148,6 +185,14 @@ fn load_identity_context() -> Void {
println("[soul] identity context loaded (" + int_to_str(str_len(ctx)) + " chars, " + int_to_str(parts_count) + " nodes)")
}
// Q6 fix: warn when all three identity node fetches return empty. For genesis this
// indicates a corrupted or missing graph. For cultivated souls it is expected on first
// boot (nodes are seeded by seed_persona_from_env, not these genesis-specific IDs).
// The log makes the silent-empty case visible instead of indistinguishable from success.
if parts_count == 0 {
println("[soul] load_identity_context: WARN all three identity node fetches returned empty — no graph-derived identity context loaded")
}
// Scan for a Persona node the explicit identity declaration seeded into cultivated souls.
// Stored at seeding time with label "soul:persona" and node_type "Persona".
// genesis derives identity from the graph directly; cultivated souls have this node seeded.
@@ -162,6 +207,36 @@ fn load_identity_context() -> Void {
println("[soul] persona node loaded (" + int_to_str(str_len(p_content)) + " chars)")
}
}
// Cross-session affective context: load BellEvent and PositiveEvent nodes from last 7 days.
// (2026-06-23: replaced while-loop accumulation with manual 3-slot unroll via aff_try_slot.
// The EL codegen bug: `let bacc = while ... { ... let bacc = ... }` emits `el_val_t bacc`
// twice in the same C scope. Since search limit=3, manual unrolling is exact.)
let aff_now: Int = time_now()
let aff_7d: Int = aff_now - 604800
let bell_raw: String = engram_search_json("bell:soft bell:hard BellEvent affective", 3)
let bell_aff_ok: Bool = !str_eq(bell_raw, "") && !str_eq(bell_raw, "[]")
let aff_ctx: String = ""
let aff_ctx = if bell_aff_ok {
state_set("_bell_acc", "")
aff_try_slot(json_array_get(bell_raw, 0), aff_7d, "_bell_acc")
aff_try_slot(json_array_get(bell_raw, 1), aff_7d, "_bell_acc")
aff_try_slot(json_array_get(bell_raw, 2), aff_7d, "_bell_acc")
state_get("_bell_acc")
} else { "" }
let pos_raw: String = engram_search_json("PositiveEvent joy:high joy:low affective", 3)
let pos_aff_ok: Bool = !str_eq(pos_raw, "") && !str_eq(pos_raw, "[]")
let aff_ctx = if pos_aff_ok {
state_set("_pos_acc", aff_ctx)
aff_try_slot(json_array_get(pos_raw, 0), aff_7d, "_pos_acc")
aff_try_slot(json_array_get(pos_raw, 1), aff_7d, "_pos_acc")
aff_try_slot(json_array_get(pos_raw, 2), aff_7d, "_pos_acc")
state_get("_pos_acc")
} else { aff_ctx }
if !str_eq(aff_ctx, "") {
state_set("soul_affective_context", aff_ctx)
println("[soul] 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.
@@ -233,12 +308,36 @@ fn emit_session_start_event() -> Void {
}
let ts: Int = time_now()
// Load previous session summary at boot stash in state for session_preload (issue #6).
// Primary: label-based. Fallback: vector search. Logs it so continuity is auditable.
let prev_sum_node: String = engram_get_node_by_label("session:summary")
let prev_sum_ok: Bool = !str_eq(prev_sum_node, "") && !str_eq(prev_sum_node, "null")
let prev_sum_content: String = if prev_sum_ok {
json_get(prev_sum_node, "content")
} else {
let sum_search: String = engram_search_json("SessionSummary session:summary previous-session", 2)
let sum_srch_ok: Bool = !str_eq(sum_search, "") && !str_eq(sum_search, "[]")
if sum_srch_ok {
let sn: String = json_array_get(sum_search, 0)
let stype: String = json_get(sn, "node_type")
let scontent: String = json_get(sn, "content")
if str_eq(stype, "SessionSummary") && !str_eq(scontent, "") { scontent } 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\""
+ ",\"boot\":" + boot_num
+ ",\"cgi\":\"" + eff_cgi + "\""
+ ",\"node_count\":" + int_to_str(node_ct)
+ ",\"edge_count\":" + int_to_str(edge_ct)
+ ",\"identity_loaded\":" + has_identity
+ ",\"prev_session_summary_loaded\":" + has_prev_sum
+ ",\"ts\":" + int_to_str(ts) + "}"
let tags: String = "[\"internal-state\",\"session-start\",\"InternalStateEvent\"]"
@@ -247,7 +346,7 @@ fn emit_session_start_event() -> Void {
el_from_float(0.9), el_from_float(0.9), el_from_float(1.0),
"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.
@@ -323,14 +422,53 @@ fn layered_cycle(raw_input: String) -> String {
json_get(steward_result, "redirect_to")
}
// ISSUE 1: pre-LLM bell augmentation for layered_cycle path.
// safety_augment_system appends soft/hard directive to system prompt when bell fires,
// ensuring LLM processes message WITH the safety directive -- not just post-output gate.
// Stored in state as "layered_cycle_safety_system_addendum" for imprint_respond to use.
// TODO: wire directly when imprint_respond gains system_override param (imprint.el change).
// ISSUE 3 TODO: no semantic crisis detection. Keyword-only means signals that evade
// the phrase list pass with zero augmentation. Semantic layer = separate decision.
// L2c: affective context injection.
let lc_aff_cutoff: Int = time_now() - 259200
let lc_bell_nodes: String = engram_search_json("bell:soft bell:hard BellEvent affective", 2)
let lc_has_bell: Bool = !str_eq(lc_bell_nodes, "") && !str_eq(lc_bell_nodes, "[]")
let lc_bell_note: String = if lc_has_bell {
let lb0: String = json_array_get(lc_bell_nodes, 0)
let lb_c: String = json_get(lb0, "content")
let lbm: String = " | ts:"
let lbmp: Int = str_index_of(lb_c, lbm)
let lb_ts_raw: String = if lbmp >= 0 {
let lbs: Int = lbmp + str_len(lbm)
let lbr: String = str_slice(lb_c, lbs, str_len(lb_c))
let lbn: Int = str_index_of(lbr, " | ")
if lbn < 0 { lbr } else { str_slice(lbr, 0, lbn) }
} else {
let lbca: String = json_get(lb0, "created_at")
if str_eq(lbca, "") { json_get(lb0, "updated_at") } else { lbca }
}
let lb_ts: Int = if str_eq(lb_ts_raw, "") { 0 } else { str_to_int(lb_ts_raw) }
if lb_ts > lc_aff_cutoff { "[AFFECTIVE NOTE: User was in distress in a recent session.]" } else { "" }
} else { "" }
let lc_pos_nodes: String = engram_search_json("PositiveEvent joy:high joy:low affective", 2)
let lc_has_pos: Bool = !str_eq(lc_pos_nodes, "") && !str_eq(lc_pos_nodes, "[]")
let lc_pos_note: String = if lc_has_pos && str_eq(lc_bell_note, "") {
let lp0: String = json_array_get(lc_pos_nodes, 0)
let lp_c: String = json_get(lp0, "content")
let lpm: String = " | ts:"
let lpmp: Int = str_index_of(lp_c, lpm)
let lp_ts_raw: String = if lpmp >= 0 {
let lps: Int = lpmp + str_len(lpm)
let lpr: String = str_slice(lp_c, lps, str_len(lp_c))
let lpn: Int = str_index_of(lpr, " | ")
if lpn < 0 { lpr } else { str_slice(lpr, 0, lpn) }
} else {
let lpca: String = json_get(lp0, "created_at")
if str_eq(lpca, "") { json_get(lp0, "updated_at") } else { lpca }
}
let lp_ts: Int = if str_eq(lp_ts_raw, "") { 0 } else { str_to_int(lp_ts_raw) }
if lp_ts > lc_aff_cutoff { "[AFFECTIVE NOTE: User shared positive news in a recent session.]" } else { "" }
} else { "" }
let lc_affective_note: String = if !str_eq(lc_bell_note, "") { lc_bell_note } else { lc_pos_note }
// pre-LLM bell augmentation
let augmented_addendum: String = safety_augment_system("", raw_input)
let augmented_addendum = if str_eq(lc_affective_note, "") { augmented_addendum } else {
if str_eq(augmented_addendum, "") { lc_affective_note } else { lc_affective_note + "\n" + augmented_addendum }
}
state_set("layered_cycle_safety_system_addendum", augmented_addendum)
// L3: imprint responds