1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//! Durable memory data — what one memory is and how storing it can fail. The
//! store, the secret scan, the prompt and the selection call live in the
//! `memory` crate.
use serde::{Deserialize, Serialize};
/// A single durable memory entry — stored as a .md file.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DurableMemory {
/// Short kebab-case slug (used as filename: `memory-dir/<slug>.md`).
pub name: String,
/// One-line summary — used to decide relevance during recall.
pub description: String,
/// Memory type.
#[serde(default)]
pub memory_type: MemoryType,
/// The memory content (body after frontmatter).
pub content: String,
/// Session that produced this memory.
#[serde(default)]
pub source_session_id: String,
/// Confidence score 0.0–1.0. Entries below 0.3 are not saved.
#[serde(default = "default_confidence")]
pub confidence: f64,
/// ISO-8601 timestamp of last write.
#[serde(default)]
pub last_seen: String,
/// Number of times this memory has been surfaced to the model (recall count).
#[serde(default)]
pub recall_count: u32,
}
fn default_confidence() -> f64 {
0.8
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum MemoryType {
/// Who the user is (role, expertise, preferences).
#[default]
User,
/// Guidance the user has given on how you should work.
Feedback,
/// Ongoing work, goals, or constraints not derivable from code/git.
Project,
/// Pointers to external resources (URLs, dashboards, tickets).
Reference,
}
impl MemoryType {
pub fn as_str(&self) -> &'static str {
match self {
MemoryType::User => "user",
MemoryType::Feedback => "feedback",
MemoryType::Project => "project",
MemoryType::Reference => "reference",
}
}
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum MemoryError {
#[error("IO error: {0}")]
Io(String),
#[error("serialization error: {0}")]
Serde(String),
}