From f192c40b2a3643a9ab97303310db8dbc7547ee35 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 15 Nov 2026 14:59:31 +0100 Subject: Robustness: retry with backoff, explained errors, --list, --session creates - four attempts on 408/425/429/500/502/503/504 and transport errors, honouring Retry-After - backoff is interruptible so Ctrl-C is not held for up to 8s - context overflow, auth failure and rate limit messages say what to do - --list shows id/model/messages/age without needing a key - --session creates the session when the id does not exist - probes recorded: session header is mandatory, consecutive user messages allowed --- src/main.rs | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index c53ebb6..4bc3550 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,8 +21,9 @@ stdin, one per line. Commands: /paste, /exit, /help. OPTIONS: -m, --model model id (default: deepseek-v4.1-flash) --base-url provider base URL - --session resume a specific session + --session resume a session, creating it if the id is new -c, --continue resume the most recent session + --list list sessions and exit --yolo approve every tool call without asking -h, --help this text @@ -39,6 +40,7 @@ fn main() { let mut base_url = None; let mut resume = None; let mut continue_last = false; + let mut list = false; let mut yolo = false; let mut args = std::env::args().skip(1); @@ -48,6 +50,7 @@ fn main() { "--base-url" => base_url = args.next(), "--session" | "--resume" => resume = args.next(), "-c" | "--continue" => continue_last = true, + "--list" => list = true, "--yolo" => yolo = true, "-h" | "--help" => { print!("{HELP}"); @@ -64,6 +67,11 @@ fn main() { signal::install(); + if list { + print_sessions(); + return; + } + let mut cfg = match Config::resolve(model, base_url, yolo) { Ok(cfg) => cfg, Err(message) => { @@ -189,6 +197,16 @@ fn open_session( }; match id { + Some(id) if !session::exists(&id) => { + let system = agent::system_prompt(); + let session = Session::create_as(id, &cfg.model, &system)?; + eprintln!( + "agent686: new session {} ({})", + session.id, + session.path().display() + ); + Ok((session, agent::new_history(system))) + } Some(id) => { let (session, system, messages) = Session::open(&id)?; if !session.model.is_empty() && session.model != cfg.model { @@ -241,3 +259,40 @@ fn warn_if_changed(watched: &Option<(PathBuf, SystemTime)>, warned: &mut bool) { } } } + +fn print_sessions() { + let sessions = match session::list() { + Ok(sessions) => sessions, + Err(error) => { + eprintln!("agent686: {error}"); + return; + } + }; + if sessions.is_empty() { + println!("no sessions"); + return; + } + println!("{:<34} {:<22} {:>5} {:>4}", "SESSION", "MODEL", "MSGS", "AGE"); + for info in sessions { + println!( + "{:<34} {:<22} {:>5} {:>4}", + info.id, + info.model, + info.messages, + ago(info.modified) + ); + } +} + +fn ago(modified: SystemTime) -> String { + let seconds = SystemTime::now() + .duration_since(modified) + .map(|d| d.as_secs()) + .unwrap_or(0); + match seconds { + 0..=59 => format!("{seconds}s"), + 60..=3599 => format!("{}m", seconds / 60), + 3600..=86_399 => format!("{}h", seconds / 3600), + _ => format!("{}d", seconds / 86_400), + } +} -- cgit v1.2.3