Batching nudges: parallel-calls prompt line, codemode hint, tool-call count

This commit is contained in:
hermes committed 2026-10-12 12:33:52 +00:00
1 parent 8b5d24436f
commit a30b3a3e73
5 files changed
+120 -4

No files matched your search

+9 -4
View File
@@ -13,7 +13,7 @@ use rquickjs::{AsyncContext, AsyncRuntime, Function, function::Async};
use serde_json::{Value, json};
use std::collections::BTreeMap;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::time::{Duration, Instant};
const MEM: usize = 256 << 20;
@@ -177,6 +177,7 @@ async fn run(
stop: Arc<AtomicBool>,
) -> ToolResult {
let t0 = Instant::now();
let ncalls = Arc::new(AtomicUsize::new(0));
let fail = |e: String| ToolResult::err(format!("Script failed\n\nScript error: {e}"));
let rt = match AsyncRuntime::new() {
Ok(r) => r,
@@ -206,11 +207,12 @@ async fn run(
let started = ctx
.with(|ctx| {
let g = ctx.globals();
let (r2, n2, c2) = (reg.clone(), names.clone(), cx.clone());
let (r2, n2, c2, k2) = (reg.clone(), names.clone(), cx.clone(), ncalls.clone());
let call = Function::new(
ctx.clone(),
Async(move |name: String, args: String| {
let (reg, names, cx) = (r2.clone(), n2.clone(), c2.clone());
k2.fetch_add(1, Ordering::Relaxed);
async move {
let real = names.get(&name).cloned().unwrap_or(name);
let r = match serde_json::from_str::<Value>(&args) {
@@ -314,10 +316,13 @@ async fn run(
f.display()
);
}
let n_calls = ncalls.load(Ordering::Relaxed);
match err {
None => ToolResult::ok(format!("Script completed in {ms}ms\n\n{body}")),
None => ToolResult::ok(format!(
"Script completed in {ms}ms, {n_calls} tool calls\n\n{body}"
)),
Some(e) => ToolResult::err(format!(
"Script failed after {ms}ms\n\n{body}Script error: {e}"
"Script failed after {ms}ms, {n_calls} tool calls\n\n{body}Script error: {e}"
)),
}
}