summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs57
1 files changed, 56 insertions, 1 deletions
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.
21OPTIONS: 21OPTIONS:
22 -m, --model <ID> model id (default: deepseek-v4.1-flash) 22 -m, --model <ID> model id (default: deepseek-v4.1-flash)
23 --base-url <URL> provider base URL 23 --base-url <URL> provider base URL
24 --session <ID> resume a specific session 24 --session <ID> resume a session, creating it if the id is new
25 -c, --continue resume the most recent session 25 -c, --continue resume the most recent session
26 --list list sessions and exit
26 --yolo approve every tool call without asking 27 --yolo approve every tool call without asking
27 -h, --help this text 28 -h, --help this text
28 29
@@ -39,6 +40,7 @@ fn main() {
39 let mut base_url = None; 40 let mut base_url = None;
40 let mut resume = None; 41 let mut resume = None;
41 let mut continue_last = false; 42 let mut continue_last = false;
43 let mut list = false;
42 let mut yolo = false; 44 let mut yolo = false;
43 45
44 let mut args = std::env::args().skip(1); 46 let mut args = std::env::args().skip(1);
@@ -48,6 +50,7 @@ fn main() {
48 "--base-url" => base_url = args.next(), 50 "--base-url" => base_url = args.next(),
49 "--session" | "--resume" => resume = args.next(), 51 "--session" | "--resume" => resume = args.next(),
50 "-c" | "--continue" => continue_last = true, 52 "-c" | "--continue" => continue_last = true,
53 "--list" => list = true,
51 "--yolo" => yolo = true, 54 "--yolo" => yolo = true,
52 "-h" | "--help" => { 55 "-h" | "--help" => {
53 print!("{HELP}"); 56 print!("{HELP}");
@@ -64,6 +67,11 @@ fn main() {
64 67
65 signal::install(); 68 signal::install();
66 69
70 if list {
71 print_sessions();
72 return;
73 }
74
67 let mut cfg = match Config::resolve(model, base_url, yolo) { 75 let mut cfg = match Config::resolve(model, base_url, yolo) {
68 Ok(cfg) => cfg, 76 Ok(cfg) => cfg,
69 Err(message) => { 77 Err(message) => {
@@ -189,6 +197,16 @@ fn open_session(
189 }; 197 };
190 198
191 match id { 199 match id {
200 Some(id) if !session::exists(&id) => {
201 let system = agent::system_prompt();
202 let session = Session::create_as(id, &cfg.model, &system)?;
203 eprintln!(
204 "agent686: new session {} ({})",
205 session.id,
206 session.path().display()
207 );
208 Ok((session, agent::new_history(system)))
209 }
192 Some(id) => { 210 Some(id) => {
193 let (session, system, messages) = Session::open(&id)?; 211 let (session, system, messages) = Session::open(&id)?;
194 if !session.model.is_empty() && session.model != cfg.model { 212 if !session.model.is_empty() && session.model != cfg.model {
@@ -241,3 +259,40 @@ fn warn_if_changed(watched: &Option<(PathBuf, SystemTime)>, warned: &mut bool) {
241 } 259 }
242 } 260 }
243} 261}
262
263fn print_sessions() {
264 let sessions = match session::list() {
265 Ok(sessions) => sessions,
266 Err(error) => {
267 eprintln!("agent686: {error}");
268 return;
269 }
270 };
271 if sessions.is_empty() {
272 println!("no sessions");
273 return;
274 }
275 println!("{:<34} {:<22} {:>5} {:>4}", "SESSION", "MODEL", "MSGS", "AGE");
276 for info in sessions {
277 println!(
278 "{:<34} {:<22} {:>5} {:>4}",
279 info.id,
280 info.model,
281 info.messages,
282 ago(info.modified)
283 );
284 }
285}
286
287fn ago(modified: SystemTime) -> String {
288 let seconds = SystemTime::now()
289 .duration_since(modified)
290 .map(|d| d.as_secs())
291 .unwrap_or(0);
292 match seconds {
293 0..=59 => format!("{seconds}s"),
294 60..=3599 => format!("{}m", seconds / 60),
295 3600..=86_399 => format!("{}h", seconds / 3600),
296 _ => format!("{}d", seconds / 86_400),
297 }
298}