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 { EventResult } from 'claude-code' |
| 2 | |
| 3 | import { isSameVerdict } from './is-same-verdict.js' |
| 4 | import { pluginOf } from './plugin-of.js' |
| 5 | import Ranking from './ranking' |
| 6 | |
| 7 | /** |
| 8 | * Whether the verdict reached past the user tier holds whole over the |
| 9 | * chain's answer: a deny, or an ask that names what stands behind it. |
| 10 | * |
| 11 | * It holds over a more permissive answer and over the same decision reworded |
| 12 | * or stripped of what it names; a stricter answer stands. A rule, a hook, a |
| 13 | * setting, a plugin or a ceiling counts, and a host answering the ask; the |
| 14 | * mode's own ask at a dialog never. The run past the user tier holds no |
| 15 | * person's plugin, so a plugin it names is a built-in or an organization's. |
| 16 | * |
| 17 | * @param held what the run past the user tier settled on |
| 18 | * @param answer what the whole chain settled on |
| 19 | * @param approver who answers this evaluation's asks (`e.approver`) |
| 20 | * @returns true when the held verdict is the one to return, as it is |
| 21 | */ |
| 22 | export function holdsOver( |
| 23 | held: EventResult<'tool.check'>, |
| 24 | answer: EventResult<'tool.check'>, |
| 25 | approver: string | undefined, |
| 26 | ): boolean { |
| 27 | const isAsked = held.decision === 'ask' |
| 28 | |
| 29 | return ( |
| 30 | !Ranking.isLooser(held, answer) && |
| 31 | !isSameVerdict(held, answer) && |
| 32 | (held.decision === 'deny' || |
| 33 | held.rule !== undefined || |
| 34 | held.hook !== undefined || |
| 35 | held.setting !== undefined || |
| 36 | pluginOf(held) !== undefined || |
| 37 | held.ceiling !== undefined || |
| 38 | (isAsked && approver === 'host')) |
| 39 | ) |
| 40 | } |