| 1 | /** |
| 2 | * Runtime permission overrides that are set synchronously from command line |
| 3 | * This ensures they're available immediately, before services are initialized |
| 4 | */ |
| 5 | |
| 6 | import { ToolPermissionPolicy } from "./types.js"; |
| 7 | |
| 8 | let runtimeOverrides: ToolPermissionPolicy[] | null = null; |
| 9 | |
| 10 | export function setRuntimePermissionOverrides(overrides: { |
| 11 | allow?: string[]; |
| 12 | ask?: string[]; |
| 13 | exclude?: string[]; |
| 14 | }) { |
| 15 | if (!overrides.allow && !overrides.ask && !overrides.exclude) { |
| 16 | runtimeOverrides = null; |
| 17 | return; |
| 18 | } |
| 19 | |
| 20 | const policies: ToolPermissionPolicy[] = []; |
| 21 | |
| 22 | // Convert runtime overrides to policies |
| 23 | if (overrides.exclude) { |
| 24 | for (const tool of overrides.exclude) { |
| 25 | const normalizedName = tool; |
| 26 | policies.push({ tool: normalizedName, permission: "exclude" }); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | if (overrides.ask) { |
| 31 | for (const tool of overrides.ask) { |
| 32 | const normalizedName = tool; |
| 33 | policies.push({ tool: normalizedName, permission: "ask" }); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | if (overrides.allow) { |
| 38 | for (const tool of overrides.allow) { |
| 39 | const normalizedName = tool; |
| 40 | policies.push({ tool: normalizedName, permission: "allow" }); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | runtimeOverrides = policies; |
| 45 | } |
| 46 | |
| 47 | export function getRuntimePermissionOverrides(): ToolPermissionPolicy[] | null { |
| 48 | return runtimeOverrides; |
| 49 | } |