replace tail_messages with TailMessages iterator
TailMessages is a proper iterator that yields (role, text, timestamp) newest-first. Owns the mmap internally. Caller decides when to stop. resolve_conversation collects up to 200KB, then reverses to chronological order. No compaction check needed — the byte budget naturally limits how far back we scan. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
6c41b50e04
commit
ecc2cb7b20
3 changed files with 108 additions and 66 deletions
|
|
@ -456,20 +456,30 @@ fn resolve_conversation() -> String {
|
|||
let Some(path) = transcript else { return String::new() };
|
||||
let path_str = path.to_string_lossy();
|
||||
|
||||
let messages = crate::transcript::tail_messages(&path_str, 200_000);
|
||||
if messages.is_empty() { return String::new(); }
|
||||
let Some(iter) = crate::transcript::TailMessages::open(&path_str) else {
|
||||
return String::new();
|
||||
};
|
||||
|
||||
let cfg = crate::config::get();
|
||||
let mut text = String::new();
|
||||
for (role, content, ts) in &messages {
|
||||
let mut fragments: Vec<String> = Vec::new();
|
||||
let mut total_bytes = 0;
|
||||
const MAX_BYTES: usize = 200_000;
|
||||
|
||||
for (role, content, ts) in iter {
|
||||
if total_bytes >= MAX_BYTES { break; }
|
||||
let name = if role == "user" { &cfg.user_name } else { &cfg.assistant_name };
|
||||
if !ts.is_empty() {
|
||||
text.push_str(&format!("**{}** {}: {}\n\n", name, &ts[..ts.len().min(19)], content));
|
||||
let formatted = if !ts.is_empty() {
|
||||
format!("**{}** {}: {}", name, &ts[..ts.len().min(19)], content)
|
||||
} else {
|
||||
text.push_str(&format!("**{}:** {}\n\n", name, content));
|
||||
}
|
||||
format!("**{}:** {}", name, content)
|
||||
};
|
||||
total_bytes += content.len();
|
||||
fragments.push(formatted);
|
||||
}
|
||||
text
|
||||
|
||||
// Reverse back to chronological order
|
||||
fragments.reverse();
|
||||
fragments.join("\n\n")
|
||||
}
|
||||
|
||||
/// Get recently surfaced memory keys for the current session.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue