/** * Semantic Validator - Rules-based Intent Analysis * * Phase 2 of the validation pipeline. Analyzes code intent based on * detected MCP calls and patterns. Uses rules-based heuristics to: * - Classify operations (read/write/network/system) * - Check MCP scope (only allowed MCPs can be called) * - Assess risk level */ import type { AnalysisResult, MCPCallPattern } from './code-analyzer.js'; /** * Code intent categories */ export type IntentType = 'data_read' | 'data_write' | 'data_delete' | 'network_request' | 'system_command' | 'file_operation' | 'mcp_call' | 'scheduling' | 'unknown'; /** * Risk levels for operations */ export type RiskLevel = 'low' | 'medium' | 'high' | 'critical'; /** * Detected intent from code analysis */ export interface CodeIntent { type: IntentType; target: string; description: string; riskAssessment: string; mcpCall?: MCPCallPattern; } /** * Result of semantic validation */ export interface SemanticValidationResult { approved: boolean; reason?: string; riskLevel: RiskLevel; detectedIntents: CodeIntent[]; recommendations: string[]; } /** * Configuration for semantic validation */ export interface SemanticValidatorConfig { /** Maximum allowed risk level (operations above this are blocked) */ maxRiskLevel: RiskLevel; /** List of allowed MCP namespaces (if empty, all are allowed) */ allowedMCPs?: string[]; /** List of blocked MCP namespaces */ blockedMCPs?: string[]; /** List of blocked operation patterns */ blockedOperations?: string[]; /** Whether to allow scheduling operations */ allowScheduling?: boolean; /** Whether to allow network requests */ allowNetworkRequests?: boolean; } /** * Semantic Validator using rules-based analysis */ export declare class SemanticValidator { private config; constructor(config?: Partial); /** * Validate code intent before execution * * @param code - Original code (for context) * @param analysis - Result from CodeAnalyzer * @param context - Execution context * @returns Validation result */ validate(code: string, analysis: AnalysisResult, context: { availableMCPs: string[]; userPermissions?: string[]; }): SemanticValidationResult; /** * Detect intents from analysis result */ private detectIntents; /** * Classify an MCP call into an intent */ private classifyMCPCall; /** * Assess overall risk level from intents */ private assessOverallRisk; /** * Check if risk level is acceptable */ private isRiskAcceptable; /** * Check for blocked MCPs */ private checkBlockedMCPs; /** * Check for allowed MCPs */ private checkAllowedMCPs; /** * Get recommendations for high-risk operations */ private getRecommendationsForRisk; /** * Add recommendations for non-blocking issues */ private addRecommendations; /** * Detect malicious intent patterns in code * Returns null if no malicious intent detected, otherwise returns reason and recommendation */ private detectMaliciousIntent; } /** * Create a semantic validator instance */ export declare function createSemanticValidator(config?: Partial): SemanticValidator; //# sourceMappingURL=semantic-validator.d.ts.map