From 28e564aeb2eeb683d3164941b5be8975eedf1ca6 Mon Sep 17 00:00:00 2001 From: ProofOfConcept Date: Sat, 11 Apr 2026 19:28:03 -0400 Subject: [PATCH] save_agent_log: write flat context array matching AST order MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The old code wrote a JSON object with named section keys, which serde_json serialized in alphabetical order — putting conversation before system, making logs misleading. Write a single flat array in section order instead, matching what the model actually sees. Co-Authored-By: Proof of Concept --- src/agent/context.rs | 2 +- src/mind/unconscious.rs | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/agent/context.rs b/src/agent/context.rs index 2b8bf34..2e54391 100644 --- a/src/agent/context.rs +++ b/src/agent/context.rs @@ -764,7 +764,7 @@ impl ContextState { pub fn conversation(&self) -> &[AstNode] { &self.conversation } pub fn conversation_mut(&mut self) -> &mut Vec { &mut self.conversation } - fn sections(&self) -> [&Vec; 4] { + pub fn sections(&self) -> [&Vec; 4] { [&self.system, &self.identity, &self.journal, &self.conversation] } } diff --git a/src/mind/unconscious.rs b/src/mind/unconscious.rs index a137fe0..0f87b17 100644 --- a/src/mind/unconscious.rs +++ b/src/mind/unconscious.rs @@ -309,14 +309,11 @@ pub async fn save_agent_log(name: &str, agent: &std::sync::Arc = Vec::new(); + for section in ctx.sections() { + context.extend(section); + } + if let Ok(json) = serde_json::to_string_pretty(&context) { let _ = std::fs::write(&path, json); } }