/** * PermissionManager - Manages tool-level permissions * * Provides fine-grained control over which tools can execute and when * user approval is required. * * @example * ```typescript * const permissions = new PermissionManager({ * defaultLevel: 'always', * rules: [ * { toolName: 'bash', level: 'once', description: 'Shell commands' }, * { toolName: 'write_file', level: 'session', description: 'File writes' }, * { toolName: 'delete_*', level: 'deny', description: 'Delete operations' }, * ], * onPermissionRequest: async (request) => { * return await askUser(`Allow ${request.toolName}?`); * }, * }); * ``` */ import type { PermissionLevel, ToolPermission, PermissionCheckResult, PermissionManagerOptions, PermissionEventHandler } from './types.js'; /** * PermissionManager handles tool-level permission checks */ export declare class PermissionManager { private readonly enabled; private readonly defaultLevel; private readonly rules; private readonly wildcardRules; private readonly handler?; private readonly previewGenerator; private readonly eventHandlers; /** * Track session-level permissions that have been granted */ private readonly sessionGrants; constructor(options?: PermissionManagerOptions); /** * Add a permission rule */ addRule(rule: ToolPermission): this; /** * Remove a permission rule by tool name */ removeRule(toolName: string): boolean; /** * Get a permission rule by tool name */ getRule(toolName: string): ToolPermission | undefined; /** * Get all permission rules */ getAllRules(): ToolPermission[]; /** * Check if a tool has permission to execute * * @param toolName - Name of the tool * @param input - Tool input arguments * @returns Permission check result */ check(toolName: string, input: Record): Promise; /** * Check and handle permission, returning whether to proceed * * Convenience method that combines check() with handling */ checkAndProceed(toolName: string, input: Record): Promise<{ proceed: boolean; result: PermissionCheckResult; }>; /** * Ask the user for permission */ private askPermission; /** * Grant session-level permission for a tool * * This allows the tool to execute for the remainder of the session * without asking again. */ grantSession(toolName: string): void; /** * Revoke session-level permission for a tool */ revokeSession(toolName: string): boolean; /** * Clear all session-level permissions */ clearSessionGrants(): void; /** * Get all tools with session-level permission */ getSessionGrants(): string[]; /** * Check if a tool has session-level permission */ hasSessionGrant(toolName: string): boolean; /** * Set the permission level for a tool * * Convenience method for adding/updating a rule */ setLevel(toolName: string, level: PermissionLevel, description?: string): this; /** * Get the effective permission level for a tool */ getLevel(toolName: string): PermissionLevel; /** * Register an event handler */ onEvent(handler: PermissionEventHandler): () => void; /** * Emit an event */ private emit; /** * Get the number of rules */ get size(): number; /** * Check if permissions are enabled */ get isEnabled(): boolean; }