Replace push() with explicit push_log() and push_no_log()

No implicit auto-logging. Call sites choose:
- push_log: new conversation entries (user messages, tool results,
  surfaced memories, assistant responses)
- push_no_log: system prompt, identity, journal, restore from log,
  compact reload, tests

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
ProofOfConcept 2026-04-09 01:10:40 -04:00
parent 6529aba069
commit c53c4f9071
3 changed files with 21 additions and 22 deletions

View file

@ -765,18 +765,17 @@ impl ContextState {
}
}
pub fn push(&mut self, section: Section, node: AstNode) {
if section == Section::Conversation {
if let Some(ref log) = self.conversation_log {
if let Err(e) = log.append_node(&node) {
eprintln!("warning: log: {:#}", e);
}
/// Push and log to conversation log.
pub fn push_log(&mut self, section: Section, node: AstNode) {
if let Some(ref log) = self.conversation_log {
if let Err(e) = log.append_node(&node) {
eprintln!("warning: log: {:#}", e);
}
}
self.section_mut(section).push(node);
}
/// Push without logging — for restoring from an existing log.
/// Push without logging.
pub fn push_no_log(&mut self, section: Section, node: AstNode) {
self.section_mut(section).push(node);
}
@ -1028,7 +1027,7 @@ mod tests {
/// return the children that were pushed into the branch.
fn parse_into_ctx(chunks: &[&str]) -> (ContextState, Vec<PendingToolCall>) {
let mut ctx = ContextState::new();
ctx.push(Section::Conversation, AstNode::branch(Role::Assistant, vec![]));
ctx.push_no_log(Section::Conversation, AstNode::branch(Role::Assistant, vec![]));
let mut p = ResponseParser::new(0);
let mut calls = Vec::new();
for chunk in chunks {
@ -1092,7 +1091,7 @@ mod tests {
fn test_parser_incremental_feed() {
let text = "<think>thought</think>response";
let mut ctx = ContextState::new();
ctx.push(Section::Conversation, AstNode::branch(Role::Assistant, vec![]));
ctx.push_no_log(Section::Conversation, AstNode::branch(Role::Assistant, vec![]));
let mut p = ResponseParser::new(0);
for ch in text.chars() {
p.feed_token(&ch.to_string(), 0, &mut ctx);
@ -1108,7 +1107,7 @@ mod tests {
fn test_parser_incremental_tool_call() {
let text = "text<tool_call>\n<function=bash>\n<parameter=command>ls</parameter>\n</function>\n</tool_call>more";
let mut ctx = ContextState::new();
ctx.push(Section::Conversation, AstNode::branch(Role::Assistant, vec![]));
ctx.push_no_log(Section::Conversation, AstNode::branch(Role::Assistant, vec![]));
let mut p = ResponseParser::new(0);
let mut tool_calls = 0;
for ch in text.chars() {
@ -1257,9 +1256,9 @@ mod tests {
if !init_tokenizer() { return; }
let mut ctx = ContextState::new();
ctx.push(Section::System, AstNode::system_msg("you are helpful"));
ctx.push(Section::Identity, AstNode::memory("name", "Proof of Concept"));
ctx.push(Section::Conversation, AstNode::user_msg("hi"));
ctx.push_no_log(Section::System, AstNode::system_msg("you are helpful"));
ctx.push_no_log(Section::Identity, AstNode::memory("name", "Proof of Concept"));
ctx.push_no_log(Section::Conversation, AstNode::user_msg("hi"));
assert_eq!(ctx.tokens(), ctx.token_ids().len());
}