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
| 1 | import type { Args, Settings } from 'claude-code' |
| 2 | |
| 3 | import { attempted } from '../attempted' |
| 4 | import HeldVerdict from '../held-verdict' |
| 5 | import Policy from '../policy' |
| 6 | import type Types from './types' |
| 7 | |
| 8 | /** |
| 9 | * The `tool.check` hook's failure handler: the failed hook's last run when |
| 10 | * it vouches for itself, else a refusal; never over the tool's ceiling. |
| 11 | * |
| 12 | * Its own policy read fails closed and cannot throw: a read that rejects, |
| 13 | * or throws where it is made, counts as deny rules holding. |
| 14 | * |
| 15 | * @param e the question |
| 16 | * @param next the handler's continuation, with that run's trace |
| 17 | * @param read the handler's own read of managed policy |
| 18 | * @returns the verdict; nothing only when that run rejected and policy |
| 19 | * lets plugins override deny rules |
| 20 | */ |
| 21 | export async function checkCaught( |
| 22 | e: Args<'tool.check'>, |
| 23 | next: Types.CheckNext, |
| 24 | read: () => Promise<Settings>, |
| 25 | ) { |
| 26 | const last = await next(e).catch(() => undefined) |
| 27 | |
| 28 | const shouldVouch = await Policy.decidedByPolicy( |
| 29 | attempted(read), |
| 30 | Policy.denyRulesHold, |
| 31 | ) |
| 32 | |
| 33 | return HeldVerdict.underCeiling( |
| 34 | shouldVouch ? HeldVerdict.caughtAnswer(last, next.trace) : last, |
| 35 | e.ceiling, |
| 36 | ) |
| 37 | } |