aboutsummaryrefslogtreecommitdiffstats
path: root/src/session.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/session.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/session.rs b/src/session.rs
index 6416b56..d017eda 100644
--- a/src/session.rs
+++ b/src/session.rs
@@ -66,6 +66,8 @@ pub struct Session {
66 pub model: String, 66 pub model: String,
67 /// Directory the session was started in; the system prompt is frozen with it. 67 /// Directory the session was started in; the system prompt is frozen with it.
68 pub cwd: String, 68 pub cwd: String,
69 /// Harness version that created the session, for prefix-change warnings.
70 pub version: String,
69 path: PathBuf, 71 path: PathBuf,
70 file: File, 72 file: File,
71} 73}
@@ -107,6 +109,7 @@ impl Session {
107 "session": id, 109 "session": id,
108 "model": model, 110 "model": model,
109 "cwd": cwd, 111 "cwd": cwd,
112 "version": env!("CARGO_PKG_VERSION"),
110 "created": now_ms(), 113 "created": now_ms(),
111 "system": system, 114 "system": system,
112 }); 115 });
@@ -117,6 +120,7 @@ impl Session {
117 id, 120 id,
118 model: model.to_string(), 121 model: model.to_string(),
119 cwd, 122 cwd,
123 version: env!("CARGO_PKG_VERSION").to_string(),
120 path, 124 path,
121 file, 125 file,
122 }) 126 })
@@ -133,6 +137,7 @@ impl Session {
133 let mut system = Value::Null; 137 let mut system = Value::Null;
134 let mut session_id = id.to_string(); 138 let mut session_id = id.to_string();
135 let mut cwd = String::new(); 139 let mut cwd = String::new();
140 let mut version = String::new();
136 let mut messages = Vec::new(); 141 let mut messages = Vec::new();
137 142
138 for line in reader.lines() { 143 for line in reader.lines() {
@@ -159,6 +164,9 @@ impl Session {
159 if let Some(c) = value.get("cwd").and_then(|c| c.as_str()) { 164 if let Some(c) = value.get("cwd").and_then(|c| c.as_str()) {
160 cwd = c.to_string(); 165 cwd = c.to_string();
161 } 166 }
167 if let Some(v) = value.get("version").and_then(|v| v.as_str()) {
168 version = v.to_string();
169 }
162 } 170 }
163 Some("msg") => { 171 Some("msg") => {
164 let mut message = value.clone(); 172 let mut message = value.clone();
@@ -185,6 +193,7 @@ impl Session {
185 id: session_id, 193 id: session_id,
186 model, 194 model,
187 cwd, 195 cwd,
196 version,
188 path, 197 path,
189 file, 198 file,
190 }, 199 },
@@ -213,6 +222,14 @@ impl Session {
213 pub fn path(&self) -> &PathBuf { 222 pub fn path(&self) -> &PathBuf {
214 &self.path 223 &self.path
215 } 224 }
225
226 /// Records a model switch so `--list` shows what the last turn used. Appending
227 /// is legal; the header itself is never rewritten.
228 pub fn record_model(&mut self, model: &str) -> Result<(), String> {
229 let line = json!({ "t": "model", "model": model, "at": now_ms() });
230 writeln!(self.file, "{line}").map_err(|e| e.to_string())?;
231 self.file.flush().map_err(|e| e.to_string())
232 }
216} 233}
217 234
218pub fn exists(id: &str) -> bool { 235pub fn exists(id: &str) -> bool {
@@ -271,6 +288,11 @@ fn scan(path: &PathBuf) -> (String, usize) {
271 } 288 }
272 } 289 }
273 Some("msg") => messages += 1, 290 Some("msg") => messages += 1,
291 Some("model") => {
292 if let Some(name) = value.get("model").and_then(|m| m.as_str()) {
293 model = name.to_string();
294 }
295 }
274 _ => {} 296 _ => {}
275 } 297 }
276 } 298 }