From 8ae5bd48cf233315b5f36a7a6b39002a5e77f74b Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 15 Nov 2026 18:00:12 +0100 Subject: 0.7.0: resume shows where you left off; no approval for unparsable calls - --continue prints the last answer, or the last reasoning block if there was none - tool arguments are validated before prompting, so an empty bash call becomes an error for the model instead of a blank approval - empty placeholder tool calls are dropped and reported - sessions tolerate invalid UTF-8 lines from a torn write - AGENT686_DEBUG_STREAM=1 dumps SSE frames --- src/session.rs | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 7 deletions(-) (limited to 'src/session.rs') diff --git a/src/session.rs b/src/session.rs index d017eda..8e0ef02 100644 --- a/src/session.rs +++ b/src/session.rs @@ -130,8 +130,8 @@ impl Session { /// that was frozen when the session started. pub fn open(id: &str) -> Result<(Session, Value, Vec), String> { let path = sessions_dir().join(format!("{id}.jsonl")); - let file = File::open(&path).map_err(|e| format!("{}: {e}", path.display()))?; - let reader = BufReader::new(file.try_clone().map_err(|e| e.to_string())?); + let raw = std::fs::read(&path).map_err(|e| format!("{}: {e}", path.display()))?; + let _ = File::open(&path); let mut model = String::new(); let mut system = Value::Null; @@ -140,14 +140,15 @@ impl Session { let mut version = String::new(); let mut messages = Vec::new(); - for line in reader.lines() { - let line = line.map_err(|e| e.to_string())?; - if line.trim().is_empty() { + for line in raw.split(|&byte| byte == b'\n') { + if line.is_empty() { continue; } - let value: Value = match serde_json::from_str(&line) { + // Lossy decoding: a torn write can split a multi-byte character, and + // one bad byte must not make the whole transcript unopenable. + let text = String::from_utf8_lossy(line); + let value: Value = match serde_json::from_str(&text) { Ok(v) => v, - // A torn last line is expected after kill -9; ignore it. Err(_) => continue, }; match value.get("t").and_then(|t| t.as_str()) { @@ -232,6 +233,57 @@ impl Session { } } +pub struct LastReply { + pub content: String, + pub reasoning: String, +} + +/// The last thing the agent said, for the resume banner. Prefers a real answer; +/// falls back to reasoning when the last block had no content. +pub fn last_reply(id: &str) -> Option { + let raw = std::fs::read(sessions_dir().join(format!("{id}.jsonl"))).ok()?; + let mut with_content: Option = None; + let mut with_reasoning: Option = None; + + for line in raw.split(|&byte| byte == b'\n') { + if line.is_empty() { + continue; + } + let text = String::from_utf8_lossy(line); + let Ok(value) = serde_json::from_str::(&text) else { + continue; + }; + if value.get("role").and_then(|role| role.as_str()) != Some("assistant") { + continue; + } + let content = value + .get("content") + .and_then(|c| c.as_str()) + .unwrap_or("") + .to_string(); + let reasoning = value + .get("_reasoning") + .and_then(|r| r.as_str()) + .unwrap_or("") + .to_string(); + let reply = LastReply { + content, + reasoning, + }; + if !reply.content.trim().is_empty() { + with_content = Some(LastReply { + content: reply.content.clone(), + reasoning: reply.reasoning.clone(), + }); + } + if !reply.reasoning.trim().is_empty() { + with_reasoning = Some(reply); + } + } + + with_content.or(with_reasoning) +} + pub fn exists(id: &str) -> bool { sessions_dir().join(format!("{id}.jsonl")).is_file() } -- cgit v1.2.3