diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-15 15:41:46 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-15 15:41:46 +0100 |
| commit | 3b1351018d3184caa5b5ca25cc13e5da1fc02229 (patch) | |
| tree | 99bdc95ba444a5c4d2d3f09c4e5c04ff16108f8f /src/ui.rs | |
| parent | 0.4.4: file-tool correctness (diff) | |
| download | agent686-3b1351018d3184caa5b5ca25cc13e5da1fc02229.tar.gz agent686-3b1351018d3184caa5b5ca25cc13e5da1fc02229.zip | |
0.4.5: CLI validation, instruction scope, resume context, prompt hygiene
- session ids validated; missing flag values and conflicting flags are usage errors
- -- terminator; usage goes to stderr
- doctor sends a real session header
- sessions record their starting cwd and warn when resumed elsewhere
- AGENTS.md stops at the git root; no parent-directory injection
- typeahead flush, Ctrl-C during prompts, NO_COLOR/TERM=dumb
Diffstat (limited to '')
| -rw-r--r-- | src/ui.rs | 18 |
1 files changed, 17 insertions, 1 deletions
| @@ -14,7 +14,13 @@ pub fn stdin_is_tty() -> bool { | |||
| 14 | 14 | ||
| 15 | fn color() -> bool { | 15 | fn color() -> bool { |
| 16 | static COLOR: OnceLock<bool> = OnceLock::new(); | 16 | static COLOR: OnceLock<bool> = OnceLock::new(); |
| 17 | *COLOR.get_or_init(stdout_is_tty) | 17 | *COLOR.get_or_init(|| { |
| 18 | stdout_is_tty() | ||
| 19 | && std::env::var_os("NO_COLOR").is_none() | ||
| 20 | && std::env::var("TERM") | ||
| 21 | .map(|term| term != "dumb") | ||
| 22 | .unwrap_or(true) | ||
| 23 | }) | ||
| 18 | } | 24 | } |
| 19 | 25 | ||
| 20 | fn paint(code: &str, text: &str) -> String { | 26 | fn paint(code: &str, text: &str) -> String { |
| @@ -177,10 +183,20 @@ impl Approver { | |||
| 177 | print!("\n{} {} ", question, paint("2", hint)); | 183 | print!("\n{} {} ", question, paint("2", hint)); |
| 178 | let _ = std::io::stdout().flush(); | 184 | let _ = std::io::stdout().flush(); |
| 179 | 185 | ||
| 186 | // Typeahead from before the prompt appeared must not answer it: a "y" | ||
| 187 | // typed during streaming would otherwise approve a command unseen. | ||
| 188 | unsafe { | ||
| 189 | libc::tcflush(libc::STDIN_FILENO, libc::TCIFLUSH); | ||
| 190 | } | ||
| 191 | |||
| 180 | let mut line = String::new(); | 192 | let mut line = String::new(); |
| 181 | if std::io::stdin().read_line(&mut line).unwrap_or(0) == 0 { | 193 | if std::io::stdin().read_line(&mut line).unwrap_or(0) == 0 { |
| 182 | return Answer::No; | 194 | return Answer::No; |
| 183 | } | 195 | } |
| 196 | // Ctrl-C during the prompt arrives as a signal, not a keystroke. | ||
| 197 | if crate::signal::CANCEL.load(std::sync::atomic::Ordering::Relaxed) { | ||
| 198 | return Answer::No; | ||
| 199 | } | ||
| 184 | match line.trim().to_ascii_lowercase().as_str() { | 200 | match line.trim().to_ascii_lowercase().as_str() { |
| 185 | "y" | "yes" => Answer::Yes, | 201 | "y" | "yes" => Answer::Yes, |
| 186 | "a" | "always" if allow_always => Answer::Always, | 202 | "a" | "always" if allow_always => Answer::Always, |
