Compare commits

...

4 Commits

Author SHA1 Message Date
will.anderson 7eca248f1d Fix all 7 remaining code review issues on activation-seed
Issue 1 (CRITICAL): Restore missing closing brace for `if is_bell` block in
auto_persist. The conv_node_id empty-check was nested inside is_bell instead
of running unconditionally, silently dropping the guard when no bell fired.

Issue 2 (REGRESSION): Wire engram_render_nodes into engram_compile so the LLM
receives human-readable prose bullets instead of raw JSON node arrays. Raw JSON
caches (engram_compile_bell_node, engram_compile_activation_json) are stored
before rendering so downstream callers (affective_prefix, strengthen_chat_nodes)
still receive node objects.

Issue 3 (BUG): Fix salience parsing in engram_render_node. The old
str_replace(".", "") approach produced 8 for "0.8" (not 80). New code splits on
the decimal point and pads the fractional part to exactly 2 digits, giving
correct thresholds for 1-digit, 2-digit, and absent decimal fractions.

Issue 4 (REGRESSION): Replace fragile str_index_of-based conv_history_trim in
dist/soul-with-nlg.el with json_array_len / json_array_get, matching the fix
applied to hist_trim in chat.el. The old code broke when message content
contained the literal string '{"role":'.

Issue 5 (LOGIC BUG): Fix `q_pos > 0` → `q_pos >= 0` in distill_transcript.
The old condition silently dropped a question mark at tail offset 0.

Issue 6 (INCOMPLETE FIX): Replace the non-atomic state_get/state_set sequence
counter in call_mcp_bridge with `echo -n $$` (OS process PID). Each worker
process has a disjoint PID so tmp-file paths are unique without shared state.

Issue 7 (INCONSISTENCY): Update soul-with-nlg.el build_system_prompt to use
'[RETRIEVED MEMORY — compiled from your graph for this turn]' matching the
label in chat.el.
2026-06-22 13:36:47 -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 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 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
2 changed files with 687 additions and 209 deletions
+655 -194
View File
File diff suppressed because it is too large Load Diff
Generated Vendored
+32 -15
View File
@@ -22186,10 +22186,10 @@ fn build_system_prompt(ctx: String) -> String {
let engram_block: String = if str_eq(ctx, "") {
""
} else {
"\n\n[ENGRAM CONTEXT — compiled from your graph]\n" + ctx
"\n\n[RETRIEVED MEMORY — compiled from your graph for this turn]\n" + ctx
}
// Safety first. Engram fills in. Identity is the base. Voice rules always present.
// Safety first. Memory fills in. Identity is the base. Voice rules always present.
return identity + date_line + voice_rules + safety_block + engram_block
}
@@ -22211,19 +22211,28 @@ fn count_context_nodes(ctx: String) -> String {
// conv_history_trim drop the oldest turn (2 entries) from a JSON history array
// when it exceeds 20 entries. Returns the trimmed array string.
// Locates the 3rd {"role": object boundary and slices from there.
//
// Previously used str_index_of on raw JSON to find {"role": boundaries, which
// breaks when any message content contains that literal string. Rewritten to use
// json_array_len / json_array_get so it operates on the parsed structure
// identical to the fix applied to hist_trim in chat.el.
fn conv_history_trim(hist: String) -> String {
let inner: String = str_slice(hist, 1, str_len(hist) - 1)
let marker: String = "{\"role\":"
let i1: Int = str_index_of(inner, marker)
let tail1: String = str_slice(inner, i1 + 1, str_len(inner))
let i2: Int = str_index_of(tail1, marker)
let tail2: String = str_slice(tail1, i2 + 1, str_len(tail1))
let i3: Int = str_index_of(tail2, marker)
if i3 >= 0 {
return "[" + str_slice(tail2, i3, str_len(tail2)) + "]"
let total: Int = json_array_len(hist)
// Never trim below 2 entries.
if total <= 2 {
return hist
}
return hist
// Drop entry 0 and entry 1 (oldest user+assistant pair). Rebuild from entry 2.
let result: String = ""
let i: Int = 2
while i < total {
let entry: String = json_array_get(hist, i)
let sep: String = if str_eq(result, "") { "" } else { "," }
let result = result + sep + entry
let i = i + 1
}
if str_eq(result, "") { return hist }
return "[" + result + "]"
}
fn handle_chat(body: String) -> String {
@@ -22313,7 +22322,11 @@ 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: thread-aware activation seed for nlg path (Issues 2-3,8-10).
let nlg_stored_hist: String = state_get("conv_history")
let nlg_hist_len: Int = if str_eq(nlg_stored_hist, "") { 0 } else { json_array_len(nlg_stored_hist) }
let nlg_seed: String = build_activation_seed(message, nlg_stored_hist, nlg_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")
@@ -22505,7 +22518,11 @@ fn handle_chat_agentic(body: String) -> String {
req_model
}
let ctx: String = engram_compile(message)
// Issue 7 fix: thread-aware seed for agentic nlg path.
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. "