Expand description
Append-only view of a session’s chat history.
The core Phase A invariant is that [Session::messages] is the pure
record of what happened and is never mutated by compression,
experimental dedup / snippet strategies, or pairing repair. This
module provides a typestate-style wrapper, History, whose only
mutating method is append — making it a compile-time error for a
new caller to acquire a &mut Vec<Message> and rewrite the buffer
in place.
§Scope
This is a foundation for the visibility tightening described in the
refactor plan. The public [Session::messages] field stays pub for
now so the crate keeps building across every caller (19 files, ~51
usages at the time of this refactor). New code paths should reach for
[Session::history] instead. Future PRs can tighten messages to
pub(crate) — each remaining direct-mutation site then surfaces as
a compile error and is migrated onto this typestate.
§Examples
use codetether_agent::session::Session;
let session = Session::new().await.unwrap();
let view = session.history();
assert!(view.is_empty());use codetether_agent::provider::{ContentPart, Message, Role};
use codetether_agent::session::history::History;
let mut buf: Vec<Message> = Vec::new();
let mut history = History::new(&mut buf);
history.append(Message {
role: Role::User,
content: vec![ContentPart::Text {
text: "hello".to_string(),
}],
});
assert_eq!(history.view().len(), 1);Structs§
- History
- Append-only handle to a chat-history buffer.