Log full agent context window on completion

Save all context sections (system, identity, journal, conversation)
to per-agent log files for both subconscious and unconscious agents.

Co-Authored-By: ProofOfConcept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-10 03:28:00 -04:00
parent be44a3bb0d
commit b4dfd3c092
4 changed files with 55 additions and 15 deletions

View file

@ -76,9 +76,8 @@ impl ChannelLog {
/// Return last N lines without consuming.
pub fn recv_history(&self, count: usize) -> String {
self.messages.iter()
.rev().take(count)
.collect::<Vec<_>>().into_iter().rev()
let start = self.messages.len().saturating_sub(count);
self.messages.range(start..)
.map(|s| s.as_str())
.collect::<Vec<_>>()
.join("\n")
@ -122,8 +121,9 @@ pub fn load_disk_log(log_dir: &std::path::Path, channel: &str) -> ChannelLog {
// Read all lines, keep only the last DEFAULT_CAPACITY
let lines: Vec<String> = reader.lines().flatten().collect();
for line in lines.into_iter().rev().take(DEFAULT_CAPACITY).collect::<Vec<_>>().into_iter().rev() {
log.push(line);
let start = lines.len().saturating_sub(DEFAULT_CAPACITY);
for line in &lines[start..] {
log.push(line.clone());
}
// Mark all loaded lines as consumed (they're history, not new)
log.consumed = log.total;