Skip to main content

vv_agent/memory/
summary.rs

1use serde::Serialize;
2
3use crate::types::Message;
4
5mod events;
6mod files;
7mod original;
8mod text;
9
10use events::{build_progress_events, collect_errors, current_work_state};
11use files::collect_file_actions;
12use original::collect_original_user_messages;
13
14#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
15pub struct FileAction {
16    pub path: String,
17    pub action: String,
18    pub summary: String,
19}
20
21#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
22pub struct ErrorFix {
23    pub error: String,
24    pub fix: String,
25    pub file: String,
26}
27
28#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
29pub struct LocalSummary {
30    pub summary_version: String,
31    pub original_user_messages: Vec<String>,
32    pub user_constraints: Vec<String>,
33    pub decisions: Vec<String>,
34    pub files_examined_or_modified: Vec<FileAction>,
35    pub errors_and_fixes: Vec<ErrorFix>,
36    pub progress: Vec<String>,
37    pub key_facts: Vec<String>,
38    pub open_issues: Vec<String>,
39    pub current_work_state: String,
40    pub next_steps: Vec<String>,
41}
42
43impl LocalSummary {
44    pub fn from_messages(messages: &[Message], event_limit: usize) -> Self {
45        Self::from_messages_with_key_facts(messages, event_limit, Vec::new())
46    }
47
48    pub fn summarize_content(content: &str, limit: usize) -> String {
49        text::normalize_excerpt(content, limit)
50    }
51
52    pub(crate) fn from_messages_with_key_facts(
53        messages: &[Message],
54        event_limit: usize,
55        key_facts: Vec<String>,
56    ) -> Self {
57        Self {
58            summary_version: "2.0".to_string(),
59            original_user_messages: collect_original_user_messages(messages),
60            user_constraints: Vec::new(),
61            decisions: Vec::new(),
62            files_examined_or_modified: collect_file_actions(messages),
63            errors_and_fixes: collect_errors(messages),
64            progress: build_progress_events(messages, event_limit),
65            key_facts,
66            open_issues: Vec::new(),
67            current_work_state: current_work_state(messages),
68            next_steps: Vec::new(),
69        }
70    }
71
72    pub fn to_json_string(&self) -> String {
73        serde_json::to_string(self).unwrap_or_else(|_| "{}".to_string())
74    }
75}