summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main.rs46
1 files changed, 22 insertions, 24 deletions
diff --git a/src/main.rs b/src/main.rs
index 8f53d9e..a591c07 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -38,8 +38,9 @@ OPTIONS:
38 --show [ID] print a transcript (most recent if no ID) and exit 38 --show [ID] print a transcript (most recent if no ID) and exit
39 --doctor check key, directories, provider and model, then exit 39 --doctor check key, directories, provider and model, then exit
40 --yolo approve every tool call without asking 40 --yolo approve every tool call without asking
41 --provider <NAME> preset: opencode-go, openai, openrouter, ollama, 41 --provider <TYPE> opencode (requires the session header, default) or
42 llamacpp, vllm 42 openai-compatible (any OpenAI-style endpoint; pair with
43 --base-url, e.g. Ollama http://localhost:11434/v1)
43 --lenient tolerate providers that omit [DONE]/usage 44 --lenient tolerate providers that omit [DONE]/usage
44 --system-ca verify TLS with the system trust store 45 --system-ca verify TLS with the system trust store
45 -V, --version print the version and exit 46 -V, --version print the version and exit
@@ -201,7 +202,9 @@ fn take_value(iter: &mut impl Iterator<Item = String>, flag: &str) -> Result<Str
201 { 202 {
202 Ok(value) 203 Ok(value)
203 } 204 }
204 _ => Err(format!("{flag} needs a value (use --{flag}=… for a value starting with -)")), 205 _ => Err(format!(
206 "{flag} needs a value (use {flag}=… for a value starting with -)"
207 )),
205 } 208 }
206} 209}
207 210
@@ -233,28 +236,23 @@ fn run(args: Args) {
233 return; 236 return;
234 } 237 }
235 238
239 let cli = agent686::config::Cli {
240 model: args.model.clone(),
241 base_url: args.base_url.clone(),
242 provider: args.provider.clone(),
243 yolo: args.yolo,
244 lenient: args.lenient,
245 system_ca: args.system_ca,
246 };
247
236 if args.doctor { 248 if args.doctor {
237 let mut config = Config::resolve_lenient( 249 let mut config = Config::resolve_lenient(&cli);
238 args.model,
239 args.base_url,
240 args.yolo,
241 args.provider,
242 args.lenient,
243 args.system_ca,
244 );
245 // `/models` needs the session header too, even though this is not a turn. 250 // `/models` needs the session header too, even though this is not a turn.
246 config.session = session::new_id(); 251 config.session = session::new_id();
247 std::process::exit(doctor::run(&config, args.json)); 252 std::process::exit(doctor::run(&config, args.json));
248 } 253 }
249 254
250 let mut cfg = match Config::resolve( 255 let mut cfg = match Config::resolve(&cli) {
251 args.model,
252 args.base_url,
253 args.yolo,
254 args.provider,
255 args.lenient,
256 args.system_ca,
257 ) {
258 Ok(cfg) => cfg, 256 Ok(cfg) => cfg,
259 Err(message) => { 257 Err(message) => {
260 eprintln!("agent686: {message}"); 258 eprintln!("agent686: {message}");
@@ -708,7 +706,7 @@ fn ago(modified: SystemTime) -> String {
708 706
709/// `--yolo` with no approval and no undo is how a transcript ends up deleting a 707/// `--yolo` with no approval and no undo is how a transcript ends up deleting a
710/// checkout. Git is the documented undo, so `--yolo` needs a repository unless 708/// checkout. Git is the documented undo, so `--yolo` needs a repository unless
711/// asked twice. `$HOME` and `/` are refused outright. 709/// allowed. `$HOME` and `/` are refused outright.
712fn refuse_yolo(cfg: &Config) { 710fn refuse_yolo(cfg: &Config) {
713 if !cfg.yolo { 711 if !cfg.yolo {
714 return; 712 return;
@@ -720,19 +718,19 @@ fn refuse_yolo(cfg: &Config) {
720 let home = std::env::var_os("HOME").map(PathBuf::from); 718 let home = std::env::var_os("HOME").map(PathBuf::from);
721 let at_home = home.as_deref() == Some(cwd.as_path()); 719 let at_home = home.as_deref() == Some(cwd.as_path());
722 let at_root = cwd.parent().is_none(); 720 let at_root = cwd.parent().is_none();
723 if (at_home || at_root) && std::env::var_os("AGENT686_ALLOW_HOME").is_none() { 721 if (at_home || at_root) && !cfg.allow_home {
724 eprintln!( 722 eprintln!(
725 "agent686: refusing --yolo in {} — the model can overwrite anything here. \ 723 "agent686: refusing --yolo in {} — the model can overwrite anything here. \
726 Run inside a project, or set AGENT686_ALLOW_HOME=1.", 724 Run inside a project, or set allow_home in the config.",
727 cwd.display() 725 cwd.display()
728 ); 726 );
729 std::process::exit(2); 727 std::process::exit(2);
730 } 728 }
731 729
732 if !in_git_repo(&cwd) && std::env::var_os("AGENT686_ALLOW_NOGIT").is_none() { 730 if !in_git_repo(&cwd) && !cfg.allow_nogit {
733 eprintln!( 731 eprintln!(
734 "agent686: refusing --yolo outside a git repository ({} has no .git), so \ 732 "agent686: refusing --yolo outside a git repository ({} has no .git), so \
735 there is no undo. Run git init, or set AGENT686_ALLOW_NOGIT=1.", 733 there is no undo. Run git init, or set allow_nogit in the config.",
736 cwd.display() 734 cwd.display()
737 ); 735 );
738 std::process::exit(2); 736 std::process::exit(2);