mask: boundary kept in Agent, advances only when context > compact_at/3; recorded per request, stats replays it
ci / check (pull_request) Canceled after 0s
ci / check (push) Canceled after 0s

This commit is contained in:
hermes committed 2026-10-01 22:35:47 +00:00
1 parent 166d9fec87
commit c74b45cbeb
4 files changed
+147 -20

No files matched your search

+31 -3
View File
@@ -17,6 +17,10 @@ pub struct Entry {
/// API usage of the request that produced this assistant message (absent in older files).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub usage: Option<hx_ai::Usage>,
/// Tool-result masking boundary (assistant turns) of the request that produced this assistant
/// message; absent in older files, where the stepwise rule applied.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub mask: Option<usize>,
}
pub struct Session {
@@ -72,6 +76,17 @@ impl Session {
message: Message,
model: Option<String>,
usage: Option<hx_ai::Usage>,
) -> std::io::Result<u64> {
self.append_masked(message, model, usage, None)
}
/// Like `append_full`, also recording the masking boundary the request used.
pub fn append_masked(
&mut self,
message: Message,
model: Option<String>,
usage: Option<hx_ai::Usage>,
mask: Option<usize>,
) -> std::io::Result<u64> {
let id = self.entries.last().map_or(0, |e| e.id + 1);
let e = Entry {
@@ -80,6 +95,7 @@ impl Session {
message,
model,
usage,
mask,
};
let mut f = std::fs::OpenOptions::new()
.create(true)
@@ -121,20 +137,32 @@ impl Session {
.collect()
}
/// Messages on the path root..=head.
pub fn messages(&self) -> Vec<Message> {
fn branch(&self) -> Vec<&Entry> {
let mut out = vec![];
let mut cur = self.head;
while let Some(id) = cur {
let Some(e) = self.entries.iter().find(|e| e.id == id) else {
break;
};
out.push(e.message.clone());
out.push(e);
cur = e.parent;
}
out.reverse();
out
}
/// Messages on the path root..=head.
pub fn messages(&self) -> Vec<Message> {
self.branch()
.into_iter()
.map(|e| e.message.clone())
.collect()
}
/// Recorded masking boundary per message on the path (aligned with `messages()`).
pub fn masks(&self) -> Vec<Option<usize>> {
self.branch().into_iter().map(|e| e.mask).collect()
}
}
/// `<hx home>/sessions/<slug of cwd>`.