From 84e70c0e73460e5db1297c47d02d9b76802bfdf7 Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 18 Nov 2026 12:28:29 +0100 Subject: 0.9.1: correctness fixes from the audit - 64 MiB limit detected by file length, so pipelines and redirects are reported - bash temp files removed on every path via a scope guard - validate requires content/new as the schemas declare (present, may be empty) - Session::open folds in model-switch records; resume matches --list - combining mark at a wrap boundary no longer counts as a new row - --flag=value accepted; flag-shaped values rejected - dead code removed; last_reply folded into open (one read per resume) --- src/session.rs | 75 +++++++++++++++++++++++----------------------------------- 1 file changed, 29 insertions(+), 46 deletions(-) (limited to 'src/session.rs') diff --git a/src/session.rs b/src/session.rs index a1da28f..881b1ed 100644 --- a/src/session.rs +++ b/src/session.rs @@ -68,6 +68,9 @@ pub struct Session { pub cwd: String, /// Harness version that created the session, for prefix-change warnings. pub version: String, + /// Last assistant block, for the resume banner. Computed during the same pass + /// that loads messages, so resume does not read the file twice. + pub last_reply: Option, path: PathBuf, file: File, } @@ -121,6 +124,7 @@ impl Session { model: model.to_string(), cwd, version: env!("CARGO_PKG_VERSION").to_string(), + last_reply: None, path, file, }) @@ -138,6 +142,8 @@ impl Session { let mut cwd = String::new(); let mut version = String::new(); let mut messages = Vec::new(); + let mut last_content: Option = None; + let mut last_reasoning: Option = None; for line in raw.split(|&byte| byte == b'\n') { if line.is_empty() { @@ -168,7 +174,29 @@ impl Session { version = v.to_string(); } } + Some("model") => { + if let Some(name) = value.get("model").and_then(|m| m.as_str()) { + model = name.to_string(); + } + } Some("msg") => { + if value.get("role").and_then(|r| r.as_str()) == Some("assistant") { + 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(); + if !content.trim().is_empty() { + last_content = Some(LastReply { content, reasoning }); + } else if !reasoning.trim().is_empty() { + last_reasoning = Some(LastReply { content, reasoning }); + } + } let mut message = value.clone(); if let Some(object) = message.as_object_mut() { object.remove("t"); @@ -194,6 +222,7 @@ impl Session { model, cwd, version, + last_reply: last_content.or(last_reasoning), path, file, }, @@ -237,52 +266,6 @@ pub struct LastReply { 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