diff options
Diffstat (limited to '')
| -rw-r--r-- | src/main.rs | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/src/main.rs b/src/main.rs index 4bc3550..29b4280 100644 --- a/src/main.rs +++ b/src/main.rs | |||
| @@ -1,10 +1,11 @@ | |||
| 1 | use std::io::{BufRead, IsTerminal, Write}; | 1 | use std::io::{BufRead, Write}; |
| 2 | use std::path::PathBuf; | 2 | use std::path::PathBuf; |
| 3 | use std::time::SystemTime; | 3 | use std::time::SystemTime; |
| 4 | 4 | ||
| 5 | use serde_json::Value; | 5 | use serde_json::Value; |
| 6 | 6 | ||
| 7 | use agent686::config::Config; | 7 | use agent686::config::Config; |
| 8 | use agent686::line::Editor; | ||
| 8 | use agent686::session::{self, Session}; | 9 | use agent686::session::{self, Session}; |
| 9 | use agent686::ui::Approver; | 10 | use agent686::ui::Approver; |
| 10 | use agent686::{agent, signal}; | 11 | use agent686::{agent, signal}; |
| @@ -16,7 +17,12 @@ USAGE: | |||
| 16 | agent686 [OPTIONS] [PROMPT...] | 17 | agent686 [OPTIONS] [PROMPT...] |
| 17 | 18 | ||
| 18 | With a prompt it runs one turn and exits. Without one it reads prompts from | 19 | With a prompt it runs one turn and exits. Without one it reads prompts from |
| 19 | stdin, one per line. Commands: /paste, /exit, /help. | 20 | stdin. In a terminal: up/down for history, ctrl-a/e/u/w/k to edit, ctrl-d to |
| 21 | exit, ctrl-c to abandon the line. Commands: /paste, /exit, /help. | ||
| 22 | |||
| 23 | /cmd | ||
| 24 | /paste read a block of lines until a lone `.` | ||
| 25 | /exit quit | ||
| 20 | 26 | ||
| 21 | OPTIONS: | 27 | OPTIONS: |
| 22 | -m, --model <ID> model id (default: deepseek-v4.1-flash) | 28 | -m, --model <ID> model id (default: deepseek-v4.1-flash) |
| @@ -109,7 +115,8 @@ fn main() { | |||
| 109 | return; | 115 | return; |
| 110 | } | 116 | } |
| 111 | 117 | ||
| 112 | let interactive = std::io::stdin().is_terminal(); | 118 | let mut editor = Editor::new(); |
| 119 | let interactive = editor.is_interactive(); | ||
| 113 | if interactive { | 120 | if interactive { |
| 114 | eprintln!( | 121 | eprintln!( |
| 115 | "agent686 · {} · session {}{}", | 122 | "agent686 · {} · session {}{}", |
| @@ -117,22 +124,21 @@ fn main() { | |||
| 117 | cfg.session, | 124 | cfg.session, |
| 118 | if cfg.yolo { " · yolo" } else { "" } | 125 | if cfg.yolo { " · yolo" } else { "" } |
| 119 | ); | 126 | ); |
| 120 | eprintln!("one prompt per line · /paste · /exit"); | 127 | eprintln!("type a prompt · up/down history · ctrl-d exit · /help"); |
| 121 | } | 128 | } |
| 122 | 129 | ||
| 123 | let stdin = std::io::stdin(); | 130 | let stdin = std::io::stdin(); |
| 124 | let mut line = String::new(); | 131 | let mut line = String::new(); |
| 125 | loop { | 132 | loop { |
| 126 | if interactive { | 133 | let mut text = match editor.read("> ") { |
| 127 | print!("> "); | 134 | Ok(Some(text)) => text, |
| 128 | let _ = std::io::stdout().flush(); | 135 | Ok(None) => break, |
| 129 | } | 136 | Err(error) => { |
| 130 | line.clear(); | 137 | eprintln!("agent686: input: {error}"); |
| 131 | if stdin.lock().read_line(&mut line).unwrap_or(0) == 0 { | 138 | break; |
| 132 | break; | 139 | } |
| 133 | } | 140 | }; |
| 134 | let mut text = line.trim_end().to_string(); | 141 | if text.trim().is_empty() { |
| 135 | if text.is_empty() { | ||
| 136 | continue; | 142 | continue; |
| 137 | } | 143 | } |
| 138 | 144 | ||
