plugins/hooks/tool_guardrails/tool_guardrails
Tool loop guardrails — circuit breaker for stuck tool loops. Detects repeated same-tool failures, identical-argument retries, no-progress idempotent loops, and total failure counts. Escalates: warn → block tool → halt loop.
Values
pub fn block_tool(
state: hooks.LoopState,
tool_name: String,
) -> hooks.LoopState
Block a tool for the remainder of this turn.
pub fn escalation(
state: hooks.LoopState,
same_tool_warn: Int,
same_tool_block: Int,
same_args_block: Int,
total_halt: Int,
no_progress_warn: Int,
no_progress_block: Int,
) -> hooks.Escalation
Determine what escalation action to take based on current state.
pub fn is_blocked(
state: hooks.LoopState,
tool_name: String,
) -> Bool
Check if a tool is currently blocked.
pub fn no_progress_count(state: hooks.LoopState) -> Int
Count consecutive occurrences of the same (tool, args, result) tuple at the end of the recent results ring buffer.
pub fn record_failure(
state: hooks.LoopState,
tool_name: String,
args: String,
) -> hooks.LoopState
Record a tool failure. Increments counters for escalation detection.
pub fn record_success(
state: hooks.LoopState,
tool_name: String,
args: String,
result: String,
) -> hooks.LoopState
Record a successful tool execution. Resets all failure counters. Tracks results for idempotent tools to detect no-progress loops.