import type { EventResult, TraceEntry } from 'claude-code' import Verdicts from './verdicts' /** * What the `tool.check` hook's failure handler answers from the one run it * can read, the failed hook's last: that run's verdict, or a refusal. * * A verdict stands that no link that may hold a person's plugin rewrote * without tightening. A rewritten one, or none at all, met no rule or hook. * * @param last what that run settled on; undefined when it rejected * @param trace that run's `next.trace` * @returns the verdict the handler returns */ export function caughtAnswer( last: EventResult<'tool.check'> | undefined, trace: readonly TraceEntry<'tool.check'>[], ) { const isVouched = last !== undefined && Verdicts.rewrittenByUsers(trace).length === 0 return isVouched ? last : Verdicts.UNCHECKED_DENY }