diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-18 12:45:05 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-18 12:45:05 +0100 |
| commit | 226c44dc770dd0ea42e322af4d0edd6c14ce14db (patch) | |
| tree | e41318cd028770a1d16408712a5549ef59e36622 /src/session.rs | |
| parent | 0.10.0: --json, /models /model /forget, git-repo gate for --yolo (diff) | |
| download | agent686-226c44dc770dd0ea42e322af4d0edd6c14ce14db.tar.gz agent686-226c44dc770dd0ea42e322af4d0edd6c14ce14db.zip | |
0.11.0: /undo via git checkpoints, /compact, provider presets, leniency, system CA
- /undo resets to a git checkpoint taken before each turn
- /compact summarises and rewrites the transcript (ADR 0003, the one sanctioned rewrite)
- --provider presets for six OpenAI-compatible gateways, local ones lenient by default
- --lenient and --system-ca
- proxies already honoured via ureq; documented
Diffstat (limited to '')
| -rw-r--r-- | src/session.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/session.rs b/src/session.rs index 881b1ed..8fc6d29 100644 --- a/src/session.rs +++ b/src/session.rs | |||
| @@ -252,6 +252,31 @@ impl Session { | |||
| 252 | &self.path | 252 | &self.path |
| 253 | } | 253 | } |
| 254 | 254 | ||
| 255 | /// Rewrites the transcript from scratch: a fresh header plus the given | ||
| 256 | /// messages. This is the one sanctioned rewrite, called only by `/compact` | ||
| 257 | /// (see ADR 0003); everything else appends. | ||
| 258 | pub fn rewrite(&mut self, system: &Value, messages: &[Value]) -> Result<(), String> { | ||
| 259 | use std::io::{Seek, SeekFrom, Write}; | ||
| 260 | self.file.set_len(0).map_err(|e| e.to_string())?; | ||
| 261 | self.file.seek(SeekFrom::Start(0)).map_err(|e| e.to_string())?; | ||
| 262 | let header = json!({ | ||
| 263 | "t": "header", | ||
| 264 | "session": self.id, | ||
| 265 | "model": self.model, | ||
| 266 | "cwd": self.cwd, | ||
| 267 | "version": self.version, | ||
| 268 | "created": now_ms(), | ||
| 269 | "system": system, | ||
| 270 | }); | ||
| 271 | writeln!(self.file, "{header}").map_err(|e| e.to_string())?; | ||
| 272 | for message in messages { | ||
| 273 | let mut line = message.as_object().cloned().unwrap_or_default(); | ||
| 274 | line.insert("t".into(), json!("msg")); | ||
| 275 | writeln!(self.file, "{}", Value::Object(line)).map_err(|e| e.to_string())?; | ||
| 276 | } | ||
| 277 | self.file.flush().map_err(|e| e.to_string()) | ||
| 278 | } | ||
| 279 | |||
| 255 | /// Records a model switch so `--list` shows what the last turn used. Appending | 280 | /// Records a model switch so `--list` shows what the last turn used. Appending |
| 256 | /// is legal; the header itself is never rewritten. | 281 | /// is legal; the header itself is never rewritten. |
| 257 | pub fn record_model(&mut self, model: &str) -> Result<(), String> { | 282 | pub fn record_model(&mut self, model: &str) -> Result<(), String> { |
