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 { Settings } from 'claude-code' |
| 2 | |
| 3 | import { attempted } from '../attempted' |
| 4 | import Policy from '../policy' |
| 5 | import { toolRegistered } from '../tool-registered' |
| 6 | import type ToolRegistered from '../tool-registered' |
| 7 | import 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 | */ |
| 21 | export 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 | ) |