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, ToolInfo, ValueOrDeny } from 'claude-code' |
| 2 | |
| 3 | import { isOrgTool } from './is-org-tool' |
| 4 | |
| 5 | /** |
| 6 | * A `tool.list` answer with the managed servers' tools as the organization's |
| 7 | * tiers listed them, and every other tool as the user tier left it. |
| 8 | * |
| 9 | * A refusal from either listing, or no policy to read, leaves the |
| 10 | * organization's listing standing whole (fail closed). |
| 11 | * |
| 12 | * @param policy the managed settings, or undefined when the read failed |
| 13 | * @param real the listing past the user tier (`next.to(e, "append")`) |
| 14 | * @param seen the listing through every tier (`next(e)`) |
| 15 | * @returns the merged answer |
| 16 | */ |
| 17 | export function managedToolsRestored( |
| 18 | policy: Settings | undefined, |
| 19 | real: ValueOrDeny<ToolInfo[]>, |
| 20 | seen: ValueOrDeny<ToolInfo[]>, |
| 21 | ): ValueOrDeny<ToolInfo[]> { |
| 22 | const isWhole = |
| 23 | policy === undefined || real.value === undefined || seen.value === undefined |
| 24 | |
| 25 | return isWhole |
| 26 | ? real |
| 27 | : { |
| 28 | value: [ |
| 29 | ...real.value.filter(tool => isOrgTool(policy, tool.name)), |
| 30 | ...seen.value.filter(tool => !isOrgTool(policy, tool.name)), |
| 31 | ], |
| 32 | } |
| 33 | } |