diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-15 15:43:07 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-15 15:43:07 +0100 |
| commit | d48aa4f0bce28159b6c5ee6bd0085a7f5a82e962 (patch) | |
| tree | 464c7290c0ac16237353ea059f932979a3e197ce /src | |
| parent | 0.4.5: CLI validation, instruction scope, resume context, prompt hygiene (diff) | |
| download | agent686-d48aa4f0bce28159b6c5ee6bd0085a7f5a82e962.tar.gz agent686-d48aa4f0bce28159b6c5ee6bd0085a7f5a82e962.zip | |
0.5.0: visible step counter, one client per turn, docs corrected
Also fixes a 32-bit-only rlim_t mismatch found by building the target.
Diffstat (limited to 'src')
| -rw-r--r-- | src/agent.rs | 15 | ||||
| -rw-r--r-- | src/provider.rs | 31 | ||||
| -rw-r--r-- | src/tools/shell.rs | 5 | ||||
| -rw-r--r-- | src/ui.rs | 8 |
4 files changed, 44 insertions, 15 deletions
diff --git a/src/agent.rs b/src/agent.rs index a8ad717..d574934 100644 --- a/src/agent.rs +++ b/src/agent.rs | |||
| @@ -183,6 +183,7 @@ pub fn run_turn( | |||
| 183 | push(session, history, user, None); | 183 | push(session, history, user, None); |
| 184 | 184 | ||
| 185 | let schemas = tools::schemas(); | 185 | let schemas = tools::schemas(); |
| 186 | let client = provider::agent(); | ||
| 186 | let mut steps = 0usize; | 187 | let mut steps = 0usize; |
| 187 | let mut last: Option<Outcome> = None; | 188 | let mut last: Option<Outcome> = None; |
| 188 | let mut aborted = false; | 189 | let mut aborted = false; |
| @@ -197,7 +198,14 @@ pub fn run_turn( | |||
| 197 | 198 | ||
| 198 | steps += 1; | 199 | steps += 1; |
| 199 | let mut renderer = Renderer::new(); | 200 | let mut renderer = Renderer::new(); |
| 200 | let mut outcome = match provider::chat(cfg, history, &schemas, cancel, &mut renderer) { | 201 | let mut outcome = match provider::chat_with( |
| 202 | &client, | ||
| 203 | cfg, | ||
| 204 | history, | ||
| 205 | &schemas, | ||
| 206 | cancel, | ||
| 207 | &mut renderer, | ||
| 208 | ) { | ||
| 201 | Ok(outcome) => outcome, | 209 | Ok(outcome) => outcome, |
| 202 | Err(Error::Aborted) => { | 210 | Err(Error::Aborted) => { |
| 203 | aborted = true; | 211 | aborted = true; |
| @@ -236,7 +244,7 @@ pub fn run_turn( | |||
| 236 | let result = if aborted { | 244 | let result = if aborted { |
| 237 | ToolOutcome::Failed("aborted by the user before this call ran".into()) | 245 | ToolOutcome::Failed("aborted by the user before this call ran".into()) |
| 238 | } else { | 246 | } else { |
| 239 | execute(&call, approver, cancel) | 247 | execute(&call, approver, cancel, steps) |
| 240 | }; | 248 | }; |
| 241 | if result.denied() { | 249 | if result.denied() { |
| 242 | denied += 1; | 250 | denied += 1; |
| @@ -320,9 +328,10 @@ fn execute( | |||
| 320 | call: &provider::ToolCall, | 328 | call: &provider::ToolCall, |
| 321 | approver: &mut Approver, | 329 | approver: &mut Approver, |
| 322 | cancel: &AtomicBool, | 330 | cancel: &AtomicBool, |
| 331 | step: usize, | ||
| 323 | ) -> ToolOutcome { | 332 | ) -> ToolOutcome { |
| 324 | let args: Value = serde_json::from_str(&call.arguments).unwrap_or_else(|_| json!({})); | 333 | let args: Value = serde_json::from_str(&call.arguments).unwrap_or_else(|_| json!({})); |
| 325 | ui::tool_line(&call.name, &args); | 334 | ui::tool_line(step, &call.name, &args); |
| 326 | 335 | ||
| 327 | match tools::approval(&call.name) { | 336 | match tools::approval(&call.name) { |
| 328 | Approval::Never => match tools::run(&call.name, &args, cancel) { | 337 | Approval::Never => match tools::run(&call.name, &args, cancel) { |
diff --git a/src/provider.rs b/src/provider.rs index b45282e..1b9e220 100644 --- a/src/provider.rs +++ b/src/provider.rs | |||
| @@ -196,6 +196,18 @@ fn explain(status: u16, message: &str) -> String { | |||
| 196 | message.to_string() | 196 | message.to_string() |
| 197 | } | 197 | } |
| 198 | 198 | ||
| 199 | /// One client per turn: rebuilding it per step pays a TLS handshake on every | ||
| 200 | /// request, which is noticeable on an i686 core. | ||
| 201 | pub fn agent() -> ureq::Agent { | ||
| 202 | ureq::Agent::config_builder() | ||
| 203 | .http_status_as_error(false) | ||
| 204 | .timeout_connect(Some(Duration::from_secs(10))) | ||
| 205 | .timeout_recv_response(Some(Duration::from_secs(180))) | ||
| 206 | .timeout_per_read(Some(Duration::from_secs(180))) | ||
| 207 | .build() | ||
| 208 | .into() | ||
| 209 | } | ||
| 210 | |||
| 199 | pub fn chat( | 211 | pub fn chat( |
| 200 | cfg: &Config, | 212 | cfg: &Config, |
| 201 | messages: &[Value], | 213 | messages: &[Value], |
| @@ -203,6 +215,17 @@ pub fn chat( | |||
| 203 | cancel: &AtomicBool, | 215 | cancel: &AtomicBool, |
| 204 | sink: &mut dyn Sink, | 216 | sink: &mut dyn Sink, |
| 205 | ) -> Result<Outcome, Error> { | 217 | ) -> Result<Outcome, Error> { |
| 218 | chat_with(&agent(), cfg, messages, tools, cancel, sink) | ||
| 219 | } | ||
| 220 | |||
| 221 | pub fn chat_with( | ||
| 222 | agent: &ureq::Agent, | ||
| 223 | cfg: &Config, | ||
| 224 | messages: &[Value], | ||
| 225 | tools: &[Value], | ||
| 226 | cancel: &AtomicBool, | ||
| 227 | sink: &mut dyn Sink, | ||
| 228 | ) -> Result<Outcome, Error> { | ||
| 206 | // serde_json::Value orders objects by key, so the serialised bytes are | 229 | // serde_json::Value orders objects by key, so the serialised bytes are |
| 207 | // stable for the same input. That is what keeps the provider's prompt cache | 230 | // stable for the same input. That is what keeps the provider's prompt cache |
| 208 | // warm. Do not add anything session-varying here. | 231 | // warm. Do not add anything session-varying here. |
| @@ -217,14 +240,6 @@ pub fn chat( | |||
| 217 | } | 240 | } |
| 218 | let bytes = serde_json::to_vec(&body).map_err(|e| Error::Transport(e.to_string()))?; | 241 | let bytes = serde_json::to_vec(&body).map_err(|e| Error::Transport(e.to_string()))?; |
| 219 | 242 | ||
| 220 | let agent: ureq::Agent = ureq::Agent::config_builder() | ||
| 221 | .http_status_as_error(false) | ||
| 222 | .timeout_connect(Some(Duration::from_secs(10))) | ||
| 223 | .timeout_recv_response(Some(Duration::from_secs(180))) | ||
| 224 | .timeout_per_read(Some(Duration::from_secs(180))) | ||
| 225 | .build() | ||
| 226 | .into(); | ||
| 227 | |||
| 228 | let started = Instant::now(); | 243 | let started = Instant::now(); |
| 229 | let mut resp = { | 244 | let mut resp = { |
| 230 | let mut attempt = 0usize; | 245 | let mut attempt = 0usize; |
diff --git a/src/tools/shell.rs b/src/tools/shell.rs index 29d2375..6f095c6 100644 --- a/src/tools/shell.rs +++ b/src/tools/shell.rs | |||
| @@ -61,9 +61,10 @@ pub fn bash( | |||
| 61 | .process_group(0); | 61 | .process_group(0); |
| 62 | unsafe { | 62 | unsafe { |
| 63 | command.pre_exec(|| { | 63 | command.pre_exec(|| { |
| 64 | // rlim_t is u32 on i686 and u64 on x86-64. | ||
| 64 | let limit = libc::rlimit { | 65 | let limit = libc::rlimit { |
| 65 | rlim_cur: MAX_OUTPUT_BYTES, | 66 | rlim_cur: MAX_OUTPUT_BYTES as libc::rlim_t, |
| 66 | rlim_max: MAX_OUTPUT_BYTES, | 67 | rlim_max: MAX_OUTPUT_BYTES as libc::rlim_t, |
| 67 | }; | 68 | }; |
| 68 | if libc::setrlimit(libc::RLIMIT_FSIZE, &limit) != 0 { | 69 | if libc::setrlimit(libc::RLIMIT_FSIZE, &limit) != 0 { |
| 69 | return Err(std::io::Error::last_os_error()); | 70 | return Err(std::io::Error::last_os_error()); |
| @@ -83,7 +83,7 @@ impl Sink for Renderer { | |||
| 83 | } | 83 | } |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | pub fn tool_line(name: &str, args: &serde_json::Value) { | 86 | pub fn tool_line(step: usize, name: &str, args: &serde_json::Value) { |
| 87 | let detail = match name { | 87 | let detail = match name { |
| 88 | "bash" => args | 88 | "bash" => args |
| 89 | .get("cmd") | 89 | .get("cmd") |
| @@ -106,7 +106,11 @@ pub fn tool_line(name: &str, args: &serde_json::Value) { | |||
| 106 | .unwrap_or("") | 106 | .unwrap_or("") |
| 107 | .to_string(), | 107 | .to_string(), |
| 108 | }; | 108 | }; |
| 109 | println!("{} {}", paint("1;36", &format!("● {name}")), detail); | 109 | println!( |
| 110 | "{} {}", | ||
| 111 | paint("1;36", &format!("● [{step}] {name}")), | ||
| 112 | detail | ||
| 113 | ); | ||
| 110 | let _ = std::io::stdout().flush(); | 114 | let _ = std::io::stdout().flush(); |
| 111 | } | 115 | } |
| 112 | 116 | ||
