From d48aa4f0bce28159b6c5ee6bd0085a7f5a82e962 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 15 Nov 2026 15:43:07 +0100 Subject: 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. --- src/agent.rs | 15 ++++++++++++--- src/provider.rs | 31 +++++++++++++++++++++++-------- src/tools/shell.rs | 5 +++-- src/ui.rs | 8 ++++++-- 4 files changed, 44 insertions(+), 15 deletions(-) (limited to 'src') 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( push(session, history, user, None); let schemas = tools::schemas(); + let client = provider::agent(); let mut steps = 0usize; let mut last: Option = None; let mut aborted = false; @@ -197,7 +198,14 @@ pub fn run_turn( steps += 1; let mut renderer = Renderer::new(); - let mut outcome = match provider::chat(cfg, history, &schemas, cancel, &mut renderer) { + let mut outcome = match provider::chat_with( + &client, + cfg, + history, + &schemas, + cancel, + &mut renderer, + ) { Ok(outcome) => outcome, Err(Error::Aborted) => { aborted = true; @@ -236,7 +244,7 @@ pub fn run_turn( let result = if aborted { ToolOutcome::Failed("aborted by the user before this call ran".into()) } else { - execute(&call, approver, cancel) + execute(&call, approver, cancel, steps) }; if result.denied() { denied += 1; @@ -320,9 +328,10 @@ fn execute( call: &provider::ToolCall, approver: &mut Approver, cancel: &AtomicBool, + step: usize, ) -> ToolOutcome { let args: Value = serde_json::from_str(&call.arguments).unwrap_or_else(|_| json!({})); - ui::tool_line(&call.name, &args); + ui::tool_line(step, &call.name, &args); match tools::approval(&call.name) { 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,12 +196,35 @@ fn explain(status: u16, message: &str) -> String { message.to_string() } +/// One client per turn: rebuilding it per step pays a TLS handshake on every +/// request, which is noticeable on an i686 core. +pub fn agent() -> ureq::Agent { + ureq::Agent::config_builder() + .http_status_as_error(false) + .timeout_connect(Some(Duration::from_secs(10))) + .timeout_recv_response(Some(Duration::from_secs(180))) + .timeout_per_read(Some(Duration::from_secs(180))) + .build() + .into() +} + pub fn chat( cfg: &Config, messages: &[Value], tools: &[Value], cancel: &AtomicBool, sink: &mut dyn Sink, +) -> Result { + chat_with(&agent(), cfg, messages, tools, cancel, sink) +} + +pub fn chat_with( + agent: &ureq::Agent, + cfg: &Config, + messages: &[Value], + tools: &[Value], + cancel: &AtomicBool, + sink: &mut dyn Sink, ) -> Result { // serde_json::Value orders objects by key, so the serialised bytes are // stable for the same input. That is what keeps the provider's prompt cache @@ -217,14 +240,6 @@ pub fn chat( } let bytes = serde_json::to_vec(&body).map_err(|e| Error::Transport(e.to_string()))?; - let agent: ureq::Agent = ureq::Agent::config_builder() - .http_status_as_error(false) - .timeout_connect(Some(Duration::from_secs(10))) - .timeout_recv_response(Some(Duration::from_secs(180))) - .timeout_per_read(Some(Duration::from_secs(180))) - .build() - .into(); - let started = Instant::now(); let mut resp = { 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( .process_group(0); unsafe { command.pre_exec(|| { + // rlim_t is u32 on i686 and u64 on x86-64. let limit = libc::rlimit { - rlim_cur: MAX_OUTPUT_BYTES, - rlim_max: MAX_OUTPUT_BYTES, + rlim_cur: MAX_OUTPUT_BYTES as libc::rlim_t, + rlim_max: MAX_OUTPUT_BYTES as libc::rlim_t, }; if libc::setrlimit(libc::RLIMIT_FSIZE, &limit) != 0 { return Err(std::io::Error::last_os_error()); diff --git a/src/ui.rs b/src/ui.rs index d7716a9..69e7aa9 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -83,7 +83,7 @@ impl Sink for Renderer { } } -pub fn tool_line(name: &str, args: &serde_json::Value) { +pub fn tool_line(step: usize, name: &str, args: &serde_json::Value) { let detail = match name { "bash" => args .get("cmd") @@ -106,7 +106,11 @@ pub fn tool_line(name: &str, args: &serde_json::Value) { .unwrap_or("") .to_string(), }; - println!("{} {}", paint("1;36", &format!("● {name}")), detail); + println!( + "{} {}", + paint("1;36", &format!("● [{step}] {name}")), + detail + ); let _ = std::io::stdout().flush(); } -- cgit v1.2.3