refactor: remove legacy plural log entries
This commit is contained in:
@@ -429,39 +429,43 @@ fn extract_assistant_text(entries: &[serde_json::Value]) -> String {
|
||||
let mut out = String::new();
|
||||
for value in entries {
|
||||
// The wire payload is the JSON form of `session_store::LogEntry`.
|
||||
// Walk Assistant items inside each entry that can carry them:
|
||||
// post-compaction `SegmentStart.history` (seed) and per-LLM-call
|
||||
// `AssistantItems` deltas.
|
||||
// Walk current singular assistant items and the seeded history in
|
||||
// post-compaction `SegmentStart` entries.
|
||||
let Ok(entry) = serde_json::from_value::<LogEntry>(value.clone()) else {
|
||||
continue;
|
||||
};
|
||||
let logged_items = match entry {
|
||||
LogEntry::SegmentStart { history, .. } => history,
|
||||
LogEntry::AssistantItems { items, .. } => items,
|
||||
_ => continue,
|
||||
};
|
||||
for logged in logged_items {
|
||||
let item: Item = logged.into();
|
||||
if let Item::Message {
|
||||
role: Role::Assistant,
|
||||
content,
|
||||
..
|
||||
} = item
|
||||
{
|
||||
for part in content {
|
||||
if let ContentPart::Text { text } = part {
|
||||
if !out.is_empty() {
|
||||
out.push_str("\n\n");
|
||||
}
|
||||
out.push_str(&text);
|
||||
}
|
||||
match entry {
|
||||
LogEntry::SegmentStart { history, .. } => {
|
||||
for logged in history {
|
||||
push_assistant_text(&mut out, logged);
|
||||
}
|
||||
}
|
||||
LogEntry::AssistantItem { item, .. } => push_assistant_text(&mut out, item),
|
||||
_ => continue,
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
fn push_assistant_text(out: &mut String, logged: session_store::LoggedItem) {
|
||||
let item: Item = logged.into();
|
||||
if let Item::Message {
|
||||
role: Role::Assistant,
|
||||
content,
|
||||
..
|
||||
} = item
|
||||
{
|
||||
for part in content {
|
||||
if let ContentPart::Text { text } = part {
|
||||
if !out.is_empty() {
|
||||
out.push_str("\n\n");
|
||||
}
|
||||
out.push_str(&text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn summarize_scope(record: &SpawnedPodRecord) -> String {
|
||||
if record.scope_delegated.is_empty() {
|
||||
return "(none)".into();
|
||||
|
||||
@@ -35,14 +35,6 @@ fn history_from_sink(handle: &PodHandle) -> Vec<Item> {
|
||||
LogEntry::SystemItem { item, .. } => {
|
||||
items.push(item.to_history_item());
|
||||
}
|
||||
LogEntry::AssistantItems { items: i, .. }
|
||||
| LogEntry::ToolResults { items: i, .. }
|
||||
| LogEntry::HookInjectedItems { items: i, .. } => {
|
||||
items.extend(i.into_iter().map(Item::from));
|
||||
}
|
||||
LogEntry::SystemItems { items: si, .. } => {
|
||||
items.extend(si.iter().map(|s| s.to_history_item()));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,18 +158,18 @@ fn serve_history(listener: UnixListener, items: Vec<Item>) -> JoinHandle<()> {
|
||||
};
|
||||
let (_r, w) = stream.into_split();
|
||||
let mut writer = JsonLineWriter::new(w);
|
||||
// Wrap the assistant items in a single
|
||||
// `LogEntry::AssistantItems` entry — that's the only kind
|
||||
// that contributes assistant text via `extract_assistant_text`.
|
||||
let logged: Vec<session_store::LoggedItem> =
|
||||
items.iter().map(session_store::LoggedItem::from).collect();
|
||||
let entry = session_store::LogEntry::AssistantItems {
|
||||
ts: 0,
|
||||
items: logged,
|
||||
};
|
||||
let entry_value = serde_json::to_value(&entry).unwrap();
|
||||
let entries: Vec<serde_json::Value> = items
|
||||
.iter()
|
||||
.map(|item| {
|
||||
let entry = session_store::LogEntry::AssistantItem {
|
||||
ts: 0,
|
||||
item: session_store::LoggedItem::from(item),
|
||||
};
|
||||
serde_json::to_value(&entry).unwrap()
|
||||
})
|
||||
.collect();
|
||||
let event = Event::Snapshot {
|
||||
entries: vec![entry_value],
|
||||
entries,
|
||||
greeting: Greeting {
|
||||
pod_name: "child".into(),
|
||||
cwd: "/tmp".into(),
|
||||
|
||||
Reference in New Issue
Block a user