zarz 0.3.4-alpha → 0.3.5-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/session.rs DELETED
@@ -1,173 +0,0 @@
1
- use anyhow::Result;
2
- use chrono::{DateTime, Utc};
3
- use serde::{Deserialize, Serialize};
4
- use std::collections::HashMap;
5
- use std::path::PathBuf;
6
-
7
- use crate::intelligence::ProjectIntelligence;
8
-
9
- #[derive(Debug, Clone, Serialize, Deserialize)]
10
- pub struct Message {
11
- pub role: MessageRole,
12
- pub content: String,
13
- }
14
-
15
- #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
16
- pub enum MessageRole {
17
- User,
18
- Assistant,
19
- System,
20
- Tool { server: String, tool: String },
21
- }
22
-
23
- #[derive(Debug)]
24
- pub struct PendingChange {
25
- pub path: PathBuf,
26
- pub original_content: String,
27
- pub new_content: String,
28
- }
29
-
30
- #[derive(Debug)]
31
- pub struct Session {
32
- pub conversation_history: Vec<Message>,
33
- pub current_files: HashMap<PathBuf, String>,
34
- pub pending_changes: Vec<PendingChange>,
35
- pub project_intelligence: ProjectIntelligence,
36
- pub working_directory: PathBuf,
37
- pub storage_id: Option<String>,
38
- pub title: Option<String>,
39
- pub created_at: Option<DateTime<Utc>>,
40
- pub updated_at: Option<DateTime<Utc>>,
41
- }
42
-
43
- impl Session {
44
- pub fn new(working_directory: PathBuf) -> Self {
45
- let project_intelligence = ProjectIntelligence::new(working_directory.clone());
46
-
47
- Self {
48
- conversation_history: Vec::new(),
49
- current_files: HashMap::new(),
50
- pending_changes: Vec::new(),
51
- project_intelligence,
52
- working_directory,
53
- storage_id: None,
54
- title: None,
55
- created_at: None,
56
- updated_at: None,
57
- }
58
- }
59
-
60
- pub fn add_message(&mut self, role: MessageRole, content: String) {
61
- self.conversation_history.push(Message { role, content });
62
- }
63
-
64
- #[allow(dead_code)]
65
- pub fn add_pending_change(&mut self, path: PathBuf, original: String, new_content: String) {
66
- self.pending_changes.push(PendingChange {
67
- path,
68
- original_content: original,
69
- new_content,
70
- });
71
- }
72
-
73
- pub fn clear_pending_changes(&mut self) {
74
- self.pending_changes.clear();
75
- }
76
-
77
- pub fn reset_metadata(&mut self) {
78
- self.storage_id = None;
79
- self.title = None;
80
- self.created_at = None;
81
- self.updated_at = None;
82
- }
83
-
84
- pub fn load_file(&mut self, path: PathBuf, content: String) {
85
- self.current_files.insert(path, content);
86
- }
87
-
88
- #[allow(dead_code)]
89
- pub fn get_file(&self, path: &PathBuf) -> Option<&String> {
90
- self.current_files.get(path)
91
- }
92
-
93
- #[allow(dead_code)]
94
- pub fn get_conversation_context(&self, max_messages: usize) -> Vec<Message> {
95
- let start = if self.conversation_history.len() > max_messages {
96
- self.conversation_history.len() - max_messages
97
- } else {
98
- 0
99
- };
100
-
101
- self.conversation_history[start..].to_vec()
102
- }
103
-
104
- pub fn build_prompt_with_context(&self, include_files: bool) -> String {
105
- let mut prompt = String::new();
106
-
107
- prompt.push_str("Conversation transcript (most recent last):\n\n");
108
-
109
- for message in &self.conversation_history {
110
- match &message.role {
111
- MessageRole::User => {
112
- prompt.push_str("User: ");
113
- prompt.push_str(&message.content);
114
- }
115
- MessageRole::Assistant => {
116
- prompt.push_str("Assistant: ");
117
- prompt.push_str(&message.content);
118
- }
119
- MessageRole::System => {
120
- prompt.push_str("System: ");
121
- prompt.push_str(&message.content);
122
- }
123
- MessageRole::Tool { server, tool } => {
124
- prompt.push_str(&format!(
125
- "Tool[{}.{tool}]: {}",
126
- server,
127
- truncate_for_prompt(&message.content, 4000)
128
- ));
129
- }
130
- }
131
-
132
- prompt.push_str("\n\n");
133
- }
134
-
135
- if include_files && !self.current_files.is_empty() {
136
- prompt.push_str("## Current Files\n\n");
137
-
138
- for (path, content) in &self.current_files {
139
- prompt.push_str(&format!(
140
- "<file path=\"{}\">\n{}\n</file>\n\n",
141
- path.display(),
142
- content
143
- ));
144
- }
145
- }
146
-
147
- prompt
148
- }
149
-
150
- pub fn get_relevant_context(&self, query: &str) -> Result<Vec<PathBuf>> {
151
- self.project_intelligence.get_relevant_context(query)
152
- }
153
-
154
- pub fn search_symbol(&self, name: &str) -> Result<Vec<crate::intelligence::Symbol>> {
155
- self.project_intelligence.find_symbol(name)
156
- }
157
- }
158
-
159
- fn truncate_for_prompt(text: &str, max_chars: usize) -> String {
160
- let mut result = String::new();
161
- let mut count = 0;
162
-
163
- for ch in text.chars() {
164
- if count >= max_chars {
165
- result.push_str("... (truncated)");
166
- return result;
167
- }
168
- result.push(ch);
169
- count += 1;
170
- }
171
-
172
- result
173
- }