1use std::path::PathBuf;
2use chrono::{DateTime, Utc};
3use serde::{Deserialize, Serialize};
4
5pub type SessionId = String;
7pub type AgentId = String;
8pub type CorrectionId = String;
9pub type ToolId = String;
10
11#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
14pub enum ImageFormat {
15 Png,
16 Jpeg,
17 Gif,
18 WebP,
19}
20
21#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
22#[serde(rename_all = "lowercase")]
23pub enum Role {
24 User,
25 Assistant,
26 System,
27}
28
29#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
30pub enum ContentType {
31 Json,
32 CliOutput { command: String },
33 Code { language: String, path: PathBuf },
34 PlainText,
35 Image { format: ImageFormat },
36}
37
38#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
39pub enum ModelFamily {
40 AnthropicClaude,
41 OpenAiGpt,
42 GoogleGemini,
43 Local(String),
44}
45
46#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
47pub enum Provider {
48 Anthropic,
50 OpenAI,
52 Google,
54}
55
56#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
57pub enum TaskClassification {
58 Simple,
59 Complex,
60}
61
62#[derive(Debug, Clone, Serialize, Deserialize)]
65pub struct ContentMetadata {
66 pub source: Option<String>,
67 pub path: Option<PathBuf>,
68 pub language: Option<String>,
69}
70
71#[derive(Debug, Clone, Serialize, Deserialize)]
72pub struct Content {
73 pub raw: String,
74 pub content_type: ContentType,
75 pub metadata: ContentMetadata,
76 pub tokens_original: u32,
77}
78
79#[derive(Debug, Clone, Serialize, Deserialize, Default)]
81pub struct Provenance {
82 pub file: Option<PathBuf>,
84 pub line_range: Option<std::ops::Range<usize>>,
86 pub content_hash: Option<String>,
88 pub tool_call_id: Option<String>,
90 pub label: Option<String>,
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize)]
95pub struct CompressedContent {
96 pub data: String,
97 pub tokens_compressed: u32,
98 pub tokens_original: u32,
99 pub stages_applied: Vec<String>,
100 pub compression_ratio: f64,
101 #[serde(default)]
103 pub provenance: Provenance,
104 #[serde(default)]
106 pub verify: Option<VerifyResult>,
107}
108
109#[derive(Debug, Clone, Serialize, Deserialize)]
112pub struct Turn {
113 pub role: Role,
114 pub content: String,
115 pub tokens: u32,
116 pub pinned: bool,
117 pub timestamp: DateTime<Utc>,
118}
119
120pub type ConversationTurn = Turn;
121
122#[derive(Debug, Clone, Serialize, Deserialize)]
123pub struct PinnedSegment {
124 pub turn_index: usize,
125 pub reason: String,
126 pub tokens: u32,
127}
128
129pub type PinEntry = PinnedSegment;
130
131#[derive(Debug, Clone, Serialize, Deserialize)]
132pub struct KvFact {
133 pub key: String,
134 pub value: String,
135 pub source_turn: usize,
136}
137
138pub type Learning = KvFact;
139
140#[derive(Debug, Clone, Serialize, Deserialize)]
141pub struct WindowUsage {
142 pub window_size: u32,
143 pub consumed: u32,
144 pub pinned: u32,
145 pub model_family: ModelFamily,
146}
147
148pub type BudgetState = WindowUsage;
149
150#[derive(Debug, Clone, Serialize, Deserialize)]
151pub struct ToolCall {
152 pub tool_name: String,
153 pub tokens_input: u32,
154 pub tokens_output: u32,
155 pub cost_usd: f64,
156 pub timestamp: DateTime<Utc>,
157}
158
159pub type ToolUsageRecord = ToolCall;
160
161#[derive(Debug, Clone, Serialize, Deserialize)]
162pub struct EditRecord {
163 pub id: CorrectionId,
164 pub timestamp: DateTime<Utc>,
165 pub original: String,
166 pub correction: String,
167 pub context: String,
168}
169
170pub type CorrectionEntry = EditRecord;
171
172#[derive(Debug, Clone, Serialize, Deserialize, Default)]
173pub struct EditHistory {
174 pub entries: Vec<EditRecord>,
175}
176
177pub type CorrectionLog = EditHistory;
178
179#[derive(Debug, Clone, Serialize, Deserialize)]
181pub struct Session {
182 pub id: SessionId,
183 pub project_dir: PathBuf,
184 pub conversation: Vec<Turn>,
185 pub corrections: EditHistory,
186 pub pins: Vec<PinnedSegment>,
187 pub learnings: Vec<KvFact>,
188 pub compressed_summary: String,
189 pub budget: WindowUsage,
190 pub tool_usage: Vec<ToolCall>,
191 pub created_at: DateTime<Utc>,
192 pub updated_at: DateTime<Utc>,
193}
194
195pub type SessionState = Session;
196
197#[derive(Debug, Clone, Serialize, Deserialize, Default)]
199pub struct StageConfig {
200 pub enabled: bool,
201 #[serde(default)]
202 pub options: serde_json::Value,
203}
204
205#[derive(Debug, Clone, Serialize, Deserialize)]
207pub struct VerifyResult {
208 pub passed: bool,
210 pub confidence: f64,
212 pub checks_passed: Vec<String>,
214 pub checks_failed: Vec<(String, String)>,
216 pub fallback_triggered: bool,
218}