vv_agent/memory/session/
entry.rs1use serde::{Deserialize, Serialize};
2
3pub(super) const SESSION_MEMORY_CATEGORIES: &[&str] = &[
4 "user_intent",
5 "decision",
6 "file_change",
7 "error_fix",
8 "key_fact",
9];
10
11#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
12pub struct SessionMemoryEntry {
13 pub category: String,
14 pub content: String,
15 pub source_cycle: i32,
16 pub importance: u8,
17}
18
19impl SessionMemoryEntry {
20 pub fn new(
21 category: impl Into<String>,
22 content: impl Into<String>,
23 source_cycle: i32,
24 importance: u8,
25 ) -> Self {
26 Self::normalized(category.into(), content.into(), source_cycle, importance)
27 }
28
29 fn normalized(category: String, content: String, source_cycle: i32, importance: u8) -> Self {
30 let normalized_category = normalize_category(&category);
31 Self {
32 category: normalized_category,
33 content: content.trim().to_string(),
34 source_cycle,
35 importance: importance.clamp(1, 10),
36 }
37 }
38}
39
40fn normalize_category(category: &str) -> String {
41 let category = category.trim().to_ascii_lowercase();
42 if SESSION_MEMORY_CATEGORIES.contains(&category.as_str()) {
43 category
44 } else {
45 "key_fact".to_string()
46 }
47}
48
49pub(super) fn entry_key(entry: &SessionMemoryEntry) -> (String, String) {
50 (
51 entry.category.clone(),
52 entry
53 .content
54 .split_whitespace()
55 .collect::<Vec<_>>()
56 .join(" ")
57 .to_ascii_lowercase(),
58 )
59}