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 / caught / register-caught.ts
30 lines · 1.0 KBRaw
1import type { Settings } from 'claude-code'
2
3import { attempted } from '../attempted'
4import Policy from '../policy'
5import { toolRegistered } from '../tool-registered'
6import type ToolRegistered from '../tool-registered'
7import type Types from './types'
8
9/**
10 * The `tool.register` hook's failure handler: the failed hook's last run
11 * when it made one, else the hook's own decision made again.
12 *
13 * Its policy read fails closed and cannot throw: a read that rejects, or
14 * throws where it is made, refuses a caller in the user tier.
15 *
16 * @param e the tool being added
17 * @param next the handler's continuation, with the caller's origin
18 * @param read the handler's own read of managed policy
19 * @returns the registration's answer
20 */
21export const registerCaught = <E, R>(
22 e: E,
23 next: Types.CaughtNext<E, R> & ToolRegistered.RegisterNext<E, R>,
24 read: () => Promise<Settings>,
25) =>
26 next.called
27 ? next(e)
28 : toolRegistered(e, next, () =>
29 Policy.decidedByPolicy(attempted(read), Policy.hasMcpAllowlist),
30 )