spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / sec-default / hooks / held-verdict / caught-answer.ts
25 lines · 858 BRaw
1import type { EventResult, TraceEntry } from 'claude-code'
2
3import Verdicts from './verdicts'
4
5/**
6 * What the `tool.check` hook's failure handler answers from the one run it
7 * can read, the failed hook's last: that run's verdict, or a refusal.
8 *
9 * A deny stands, and so does a verdict no link that may hold a person's
10 * plugin loosened. A loosened one, or none at all, met no deny rule.
11 *
12 * @param last what that run settled on; undefined when it rejected
13 * @param trace that run's `next.trace`
14 * @returns the verdict the handler returns
15 */
16export function caughtAnswer(
17 last: EventResult<'tool.check'> | undefined,
18 trace: readonly TraceEntry<'tool.check'>[],
19) {
20 const isVouched =
21 last !== undefined &&
22 (last.decision === 'deny' || Verdicts.loosenedByUsers(trace).length === 0)
23
24 return isVouched ? last : Verdicts.UNCHECKED_DENY
25}