//#region src/types.d.ts /** * Core types for the tool routing system. * * A "route" maps a forbidden tool usage to an AI Kit alternative. * Routes are the single source of truth consumed by: * - Pre-dispatch compliance checks (check_tool_compliance tool) * - Post-hoc replay scoring (compliance-scorer.ts) * - Prompt-analysis compliance reporting * - Agent instruction generation */ /** Severity level for a routing violation */ type RouteSeverity = 'error' | 'warning' | 'info'; /** Action the caller should take when a route matches */ type RouteAction = 'redirect' | 'warn' | 'allow'; /** * A single tool routing rule. * * Rules match on tool name and optionally on command patterns or heuristics. * When a tool call matches, the compliance system reports the alternative. */ interface ToolRoute { /** Unique rule identifier (kebab-case, e.g. "no-terminal-test") */ readonly id: string; /** The tool name that triggers this route (e.g. "grep_search", "run_in_terminal") */ readonly toolName: string; /** Human-readable description of what this route enforces */ readonly description: string; /** Suggested alternative tool(s) to use instead */ readonly alternative: string; /** Why this routing exists — for user-facing messages */ readonly reason: string; /** Severity when this route is violated */ readonly severity: RouteSeverity; /** Action to take when this route matches */ readonly action: RouteAction; /** * Optional regex patterns to match against the command/input. * Only evaluated when toolName matches AND command context is provided. * Example: ['vitest', 'jest', 'pnpm test'] for run_in_terminal */ readonly commandPatterns?: readonly string[]; /** * Optional heuristic description for human-readable context. * Not evaluated programmatically — used for reporting and documentation. */ readonly heuristic?: string; } /** Result of a single route check */ interface RouteCheckResult { /** Whether the tool usage is compliant */ readonly compliant: boolean; /** The route that matched (undefined if no route matched) */ readonly route?: ToolRoute; /** Suggested alternative tool */ readonly alternative?: string; /** Human-readable message explaining the result */ readonly message?: string; } /** Context provided alongside a tool call for richer checking */ interface ToolCallContext { /** The raw command string (for run_in_terminal checks) */ readonly command?: string; /** Line range start (for read_file checks) */ readonly startLine?: number; /** Line range end (for read_file checks) */ readonly endLine?: number; /** Whether the caller is a subagent */ readonly isSubagent?: boolean; /** Additional arbitrary context */ readonly [key: string]: unknown; } /** Registry of routes with add/remove/check operations */ interface RouteRegistry { /** All registered routes */ readonly routes: readonly ToolRoute[]; /** Check a tool call against all registered routes */ check(toolName: string, context?: ToolCallContext): RouteCheckResult; /** Check a tool call against all registered routes, returning ALL matching violations */ checkAll(toolName: string, context?: ToolCallContext): RouteCheckResult[]; /** Register a new route */ add(route: ToolRoute): void; /** Remove a route by ID */ remove(id: string): boolean; } /** Options for initializing a RouteRegistry */ interface RouteRegistryOptions { /** Initial routes to register (defaults to DEFAULT_ROUTES) */ routes?: readonly ToolRoute[]; } //#endregion //#region src/checker.d.ts /** * Check a single route against a tool call. * Returns a violation result if the route matches, null if compliant. */ declare function checkSingleRoute(route: ToolRoute, toolName: string, context?: ToolCallContext): RouteCheckResult | null; /** * Create a RouteRegistry with the given routes (defaults to DEFAULT_ROUTES). * * The registry provides: * - `check(toolName, context?)` — single-result check (first matching route) * - `checkAll(toolName, context?)` — ALL matching routes * - `add(route)` — register a new route at runtime * - `remove(id)` — deregister a route by ID */ declare function createRouteRegistry(options?: RouteRegistryOptions): RouteRegistry; /** * Convenience function: check a single tool call against DEFAULT_ROUTES. * * @param toolName — the tool being called * @param context — optional context (command, line ranges, etc.) * @returns RouteCheckResult with compliant status and violation details */ declare function checkToolRoute(toolName: string, context?: ToolCallContext): RouteCheckResult; /** * Convenience: get all routes that are violations (for summary/display). */ declare function getViolationSummary(results: RouteCheckResult[]): { total: number; errors: number; warnings: number; redirects: number; }; //#endregion //#region src/prompt.d.ts /** * Generate the FORBIDDEN tool routing markdown table for agent instructions. * * This replaces the hardcoded tables in CLAUDE.md and AGENTS.md. * Usage: * console.log(generateRoutingTable()); // full routing table */ declare function generateRoutingTable(): string; /** * Generate compact routing rules text for the Orchestrator pre-dispatch gate. * Returns a minimal set of instructions an agent should follow. */ declare function generateRoutingRules(): string; /** * Generate forbidden tool names list for programmatic use. */ declare function getForbiddenToolNames(severity?: ToolRoute['severity']): string[]; //#endregion //#region src/routes.d.ts /** * Default tool routing rules. * * This is the SINGLE source of truth for tool routing policies. * Must mirror scaffold/definitions/policies.mjs — update both in sync. * All downstream consumers (compliance-scorer, check_tool_compliance tool, * prompt-analysis, agent instructions) derive from this list. */ declare const DEFAULT_ROUTES: readonly ToolRoute[]; /** * Get routes filtered by severity. */ declare function getRoutesBySeverity(routes: readonly ToolRoute[], severity: ToolRoute['severity']): ToolRoute[]; /** * Get routes for a specific tool name. */ declare function getRoutesForTool(routes: readonly ToolRoute[], toolName: string): ToolRoute[]; //#endregion export { DEFAULT_ROUTES, type RouteAction, type RouteCheckResult, type RouteRegistry, type RouteRegistryOptions, type RouteSeverity, type ToolCallContext, type ToolRoute, checkSingleRoute, checkToolRoute, createRouteRegistry, generateRoutingRules, generateRoutingTable, getForbiddenToolNames, getRoutesBySeverity, getRoutesForTool, getViolationSummary };