MCPcopy Create free account
hub / github.com/AI45Lab/Code / validate_script_limits

Function validate_script_limits

core/src/config/agent_dir.rs:242–272  ·  view source on GitHub ↗

Reject zero or above-ceiling limits at load (fail closed). Unset fields keep the program tool's defaults.

(
    limits: ScriptToolLimits,
)

Source from the content-addressed store, hash-verified

240/// Reject zero or above-ceiling limits at load (fail closed). Unset fields keep
241/// the program tool's defaults.
242fn validate_script_limits(
243 limits: ScriptToolLimits,
244) -> std::result::Result<ScriptToolLimits, String> {
245 fn check<T: PartialOrd + Copy + std::fmt::Display>(
246 v: Option<T>,
247 max: T,
248 one: T,
249 field: &str,
250 ) -> std::result::Result<(), String> {
251 if let Some(v) = v {
252 if v < one || v > max {
253 return Err(format!("limit {field}={v} is out of range [1, {max}]"));
254 }
255 }
256 Ok(())
257 }
258 check(limits.timeout_ms, SCRIPT_MAX_TIMEOUT_MS, 1, "timeoutMs")?;
259 check(
260 limits.max_tool_calls,
261 SCRIPT_MAX_TOOL_CALLS,
262 1,
263 "maxToolCalls",
264 )?;
265 check(
266 limits.max_output_bytes,
267 SCRIPT_MAX_OUTPUT_BYTES,
268 1,
269 "maxOutputBytes",
270 )?;
271 Ok(limits)
272}
273
274fn load_tools(dir: &Path) -> Result<Vec<ToolSpec>> {
275 let mut out = Vec::new();

Callers 1

load_toolsFunction · 0.85

Calls 1

checkFunction · 0.70

Tested by

no test coverage detected