1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
use std::io::{BufRead, IsTerminal, Write};
use std::sync::atomic::AtomicBool;
use agent686::{agent, config::Config, ui};
const HELP: &str = "\
agent686 — a small coding agent
USAGE:
agent686 [OPTIONS] [PROMPT...]
With a prompt it runs one turn and exits; without one it reads prompts from
stdin, one per line. /exit quits.
OPTIONS:
-m, --model <ID> model id (default: deepseek-v4.1-flash)
--base-url <URL> provider base URL, e.g. http://127.0.0.1:8080/v1
--session <ID> reuse a session id, including for the provider header
-h, --help this text
ENVIRONMENT:
OPENCODE_API_KEY credential (falls back to ~/.config/agent686/key)
AGENT686_MODEL default model id
AGENT686_BASE_URL default provider base URL
";
fn main() {
let mut prompt: Option<String> = None;
let mut model = None;
let mut base_url = None;
let mut session = None;
let mut args = std::env::args().skip(1);
while let Some(arg) = args.next() {
match arg.as_str() {
"-m" | "--model" => model = args.next(),
"--base-url" => base_url = args.next(),
"--session" => session = args.next(),
"-h" | "--help" => {
print!("{HELP}");
return;
}
flag if flag.starts_with('-') && flag.len() > 1 => {
eprintln!("agent686: unknown flag {flag}\n");
print!("{HELP}");
std::process::exit(2);
}
word => {
prompt = Some(match prompt.take() {
Some(existing) => format!("{existing} {word}"),
None => word.to_string(),
})
}
}
}
let cfg = match Config::resolve(model, base_url, session) {
Ok(cfg) => cfg,
Err(message) => {
eprintln!("agent686: {message}");
std::process::exit(2);
}
};
let cancel = AtomicBool::new(false);
let mut history = agent::new_history();
// One-shot mode: a prompt on the command line means one turn, then exit.
if let Some(prompt) = prompt {
let mut sink = ui::Renderer::new(ui::stdout_is_tty());
match agent::run_turn(&cfg, &mut history, &prompt, &cancel, &mut sink) {
Ok(outcome) => note_tool_calls(&outcome),
Err(error) => {
eprintln!("agent686: {error}");
std::process::exit(1);
}
}
return;
}
let interactive = std::io::stdin().is_terminal();
if interactive {
eprintln!(
"agent686 · {} · session {}{}",
cfg.model,
cfg.session,
if is_local(&cfg.base_url) { " · local" } else { "" }
);
eprintln!("one prompt per line · /exit to quit");
}
let stdin = std::io::stdin();
let mut line = String::new();
loop {
if interactive {
print!("> ");
let _ = std::io::stdout().flush();
}
line.clear();
if stdin.lock().read_line(&mut line).unwrap_or(0) == 0 {
break;
}
let text = line.trim_end();
if text.is_empty() {
continue;
}
if text == "/exit" || text == "/quit" {
break;
}
let mut sink = ui::Renderer::new(ui::stdout_is_tty());
match agent::run_turn(&cfg, &mut history, text, &cancel, &mut sink) {
Ok(outcome) => note_tool_calls(&outcome),
Err(error) => eprintln!("agent686: {error}"),
}
}
}
fn note_tool_calls(outcome: &agent686::provider::Outcome) {
if outcome.tool_calls.is_empty() {
return;
}
let names: Vec<&str> = outcome
.tool_calls
.iter()
.map(|call| call.name.as_str())
.collect();
eprintln!(
"agent686: model asked for {} tool call(s) [{}]; tools arrive in milestone 2",
names.len(),
names.join(", ")
);
}
fn is_local(base_url: &str) -> bool {
base_url.contains("127.0.0.1") || base_url.contains("localhost")
}
|