aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main.rs41
-rw-r--r--src/tools/mod.rs6
-rw-r--r--src/ui.rs6
3 files changed, 36 insertions, 17 deletions
diff --git a/src/main.rs b/src/main.rs
index ba296d9..786b070 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -5,12 +5,12 @@
5 * https://git.2137697.xyz/agent686 5 * https://git.2137697.xyz/agent686
6 */ 6 */
7 7
8use serde_json::json;
8use std::io::{BufRead, IsTerminal, Write}; 9use std::io::{BufRead, IsTerminal, Write};
9use std::path::Path; 10use std::path::Path;
10use serde_json::json;
11use std::time::UNIX_EPOCH;
12use std::path::PathBuf; 11use std::path::PathBuf;
13use std::time::SystemTime; 12use std::time::SystemTime;
13use std::time::UNIX_EPOCH;
14 14
15use serde_json::Value; 15use serde_json::Value;
16 16
@@ -149,9 +149,7 @@ fn parse_args() -> Result<Args, String> {
149 "--" => literal = true, 149 "--" => literal = true,
150 "-m" | "--model" => args.model = Some(take_value(&mut iter, "--model")?), 150 "-m" | "--model" => args.model = Some(take_value(&mut iter, "--model")?),
151 "--base-url" => args.base_url = Some(take_value(&mut iter, "--base-url")?), 151 "--base-url" => args.base_url = Some(take_value(&mut iter, "--base-url")?),
152 "--session" | "--resume" => { 152 "--session" | "--resume" => args.session = Some(take_value(&mut iter, "--session")?),
153 args.session = Some(take_value(&mut iter, "--session")?)
154 }
155 "-c" | "--continue" => args.continue_last = true, 153 "-c" | "--continue" => args.continue_last = true,
156 "--list" => args.list = true, 154 "--list" => args.list = true,
157 "--show" => { 155 "--show" => {
@@ -203,10 +201,7 @@ fn parse_args() -> Result<Args, String> {
203 201
204fn take_value(iter: &mut impl Iterator<Item = String>, flag: &str) -> Result<String, String> { 202fn take_value(iter: &mut impl Iterator<Item = String>, flag: &str) -> Result<String, String> {
205 match iter.next() { 203 match iter.next() {
206 Some(value) 204 Some(value) if !value.trim().is_empty() && !(value.starts_with('-') && value.len() > 1) => {
207 if !value.trim().is_empty()
208 && !(value.starts_with('-') && value.len() > 1) =>
209 {
210 Ok(value) 205 Ok(value)
211 } 206 }
212 _ => Err(format!( 207 _ => Err(format!(
@@ -510,7 +505,10 @@ fn undo(checkpoint: Option<&str>) {
510/// `/compact`: summarise the conversation and start again from the summary, in 505/// `/compact`: summarise the conversation and start again from the summary, in
511/// the same session id. The only sanctioned rewrite of the transcript (ADR 0003). 506/// the same session id. The only sanctioned rewrite of the transcript (ADR 0003).
512fn compact(cfg: &Config, session: &mut Session, history: &mut Vec<Value>) { 507fn compact(cfg: &Config, session: &mut Session, history: &mut Vec<Value>) {
513 let system = history.first().cloned().unwrap_or_else(|| agent::system_prompt()); 508 let system = history
509 .first()
510 .cloned()
511 .unwrap_or_else(|| agent::system_prompt());
514 let mut messages = history.clone(); 512 let mut messages = history.clone();
515 messages.push(json!({ 513 messages.push(json!({
516 "role": "user", 514 "role": "user",
@@ -540,7 +538,10 @@ fn compact(cfg: &Config, session: &mut Session, history: &mut Vec<Value>) {
540 return; 538 return;
541 } 539 }
542 *history = new_history; 540 *history = new_history;
543 eprintln!("agent686: compacted into a {}-character summary", summary.len()); 541 eprintln!(
542 "agent686: compacted into a {}-character summary",
543 summary.len()
544 );
544} 545}
545 546
546fn list_models(cfg: &Config) { 547fn list_models(cfg: &Config) {
@@ -676,7 +677,10 @@ fn print_sessions(json: bool) {
676 }) 677 })
677 }) 678 })
678 .collect(); 679 .collect();
679 println!("{}", serde_json::to_string(&rows).unwrap_or_else(|_| "[]".into())); 680 println!(
681 "{}",
682 serde_json::to_string(&rows).unwrap_or_else(|_| "[]".into())
683 );
680 return; 684 return;
681 } 685 }
682 if sessions.is_empty() { 686 if sessions.is_empty() {
@@ -917,7 +921,13 @@ fn render_message(message: &Value, color: bool) -> String {
917 "2", 921 "2",
918 &format!( 922 &format!(
919 " └ {}", 923 " └ {}",
920 first_lines(message.get("content").and_then(|c| c.as_str()).unwrap_or(""), 4) 924 first_lines(
925 message
926 .get("content")
927 .and_then(|c| c.as_str())
928 .unwrap_or(""),
929 4
930 )
921 ), 931 ),
922 color 932 color
923 ) 933 )
@@ -957,7 +967,10 @@ fn print_last_reply(session: &Session) {
957 "{}", 967 "{}",
958 style( 968 style(
959 "2", 969 "2",
960 &format!("… {} more line(s); `agent686 --show` for the transcript", lines.len() - limit), 970 &format!(
971 "… {} more line(s); `agent686 --show` for the transcript",
972 lines.len() - limit
973 ),
961 true 974 true
962 ) 975 )
963 ); 976 );
diff --git a/src/tools/mod.rs b/src/tools/mod.rs
index 43176c3..05af611 100644
--- a/src/tools/mod.rs
+++ b/src/tools/mod.rs
@@ -104,7 +104,11 @@ pub fn validate(name: &str, args: &Value) -> Result<(), String> {
104} 104}
105 105
106/// Tools that execute immediately. 106/// Tools that execute immediately.
107pub fn run(name: &str, args: &Value, cancel: &std::sync::atomic::AtomicBool) -> Result<String, String> { 107pub fn run(
108 name: &str,
109 args: &Value,
110 cancel: &std::sync::atomic::AtomicBool,
111) -> Result<String, String> {
108 match name { 112 match name {
109 "read" => fs::read(args), 113 "read" => fs::read(args),
110 "grep" => fs::grep(args), 114 "grep" => fs::grep(args),
diff --git a/src/ui.rs b/src/ui.rs
index 9931a7d..1ffe34c 100644
--- a/src/ui.rs
+++ b/src/ui.rs
@@ -307,8 +307,10 @@ impl Approver {
307 return true; 307 return true;
308 } 308 }
309 // Bash prompts every call by design, so "always" is not offered here. 309 // Bash prompts every call by design, so "always" is not offered here.
310 self.ask(&format!("run: {}", crate::provider::truncate(cmd, 200)), false) 310 self.ask(
311 == Answer::Yes 311 &format!("run: {}", crate::provider::truncate(cmd, 200)),
312 false,
313 ) == Answer::Yes
312 } 314 }
313} 315}
314 316