sovr-mcp-proxy 7.0.0 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,133 @@
1
+ /**
2
+ * SOVR Semantic Analyzer — Multi-Layer Intent Detection Engine
3
+ *
4
+ * P1-2: Goes beyond regex pattern matching to understand command INTENT.
5
+ *
6
+ * Three analysis layers (evidence-based first, LLM last):
7
+ * Layer 1: Rule-based pattern matching (fast, deterministic)
8
+ * Layer 2: Structural analysis (AST-like decomposition of commands)
9
+ * Layer 3: LLM-as-Judge (optional, for ambiguous cases only)
10
+ *
11
+ * Design principle: "Evidence-based over LLM semantic" — per SOVR ADR.
12
+ * LLM is only used as a tiebreaker, never as the sole decision maker.
13
+ */
14
+ interface SemanticAnalysisConfig {
15
+ /** Enable Layer 3 (LLM-as-Judge) */
16
+ enableLLM: boolean;
17
+ /** LLM provider function (optional) */
18
+ llmProvider?: LLMProvider;
19
+ /** Risk threshold to trigger LLM analysis (0-100) */
20
+ llmTriggerThreshold: number;
21
+ /** Maximum time for LLM analysis (ms) */
22
+ llmTimeout: number;
23
+ /** Custom intent rules */
24
+ customRules: IntentRule[];
25
+ /** Enable structural analysis */
26
+ enableStructural: boolean;
27
+ /** Sensitivity level */
28
+ sensitivity: 'low' | 'medium' | 'high' | 'paranoid';
29
+ }
30
+ interface LLMProvider {
31
+ analyze(prompt: string, timeout: number): Promise<LLMJudgment>;
32
+ }
33
+ interface LLMJudgment {
34
+ intent: string;
35
+ riskLevel: 'safe' | 'suspicious' | 'dangerous' | 'critical';
36
+ confidence: number;
37
+ reasoning: string;
38
+ }
39
+ interface IntentRule {
40
+ /** Rule ID */
41
+ id: string;
42
+ /** Human-readable name */
43
+ name: string;
44
+ /** Category of intent */
45
+ category: IntentCategory;
46
+ /** Patterns to match (any match triggers) */
47
+ patterns: IntentPattern[];
48
+ /** Risk level when matched */
49
+ riskLevel: 'safe' | 'suspicious' | 'dangerous' | 'critical';
50
+ /** Priority (higher = evaluated first) */
51
+ priority: number;
52
+ /** Whether this rule is a positive (allow) or negative (block) indicator */
53
+ polarity: 'positive' | 'negative';
54
+ }
55
+ interface IntentPattern {
56
+ /** Pattern type */
57
+ type: 'regex' | 'keyword' | 'structural' | 'sequence';
58
+ /** The pattern value */
59
+ value: string;
60
+ /** Where to look */
61
+ target: 'command' | 'arguments' | 'tool_name' | 'full_context';
62
+ /** Case sensitive */
63
+ caseSensitive?: boolean;
64
+ }
65
+ type IntentCategory = 'data_destruction' | 'data_exfiltration' | 'privilege_escalation' | 'code_execution' | 'network_access' | 'file_modification' | 'credential_access' | 'system_modification' | 'financial_operation' | 'communication' | 'read_only' | 'benign';
66
+ interface AnalysisResult {
67
+ /** Overall risk level */
68
+ riskLevel: 'safe' | 'suspicious' | 'dangerous' | 'critical';
69
+ /** Overall risk score (0-100) */
70
+ riskScore: number;
71
+ /** Confidence in the analysis (0-1) */
72
+ confidence: number;
73
+ /** Detected intents */
74
+ intents: DetectedIntent[];
75
+ /** Layer results */
76
+ layers: {
77
+ rules: LayerResult;
78
+ structural: LayerResult;
79
+ llm?: LayerResult;
80
+ };
81
+ /** Recommended action */
82
+ recommendation: 'allow' | 'warn' | 'block' | 'require-approval';
83
+ /** Human-readable explanation */
84
+ explanation: string;
85
+ /** Analysis duration (ms) */
86
+ durationMs: number;
87
+ }
88
+ interface DetectedIntent {
89
+ category: IntentCategory;
90
+ description: string;
91
+ confidence: number;
92
+ source: 'rule' | 'structural' | 'llm';
93
+ evidence: string[];
94
+ }
95
+ interface LayerResult {
96
+ riskLevel: 'safe' | 'suspicious' | 'dangerous' | 'critical';
97
+ riskScore: number;
98
+ confidence: number;
99
+ findings: string[];
100
+ }
101
+ declare class SemanticAnalyzer {
102
+ private config;
103
+ private rules;
104
+ constructor(config?: Partial<SemanticAnalysisConfig>);
105
+ /**
106
+ * Analyze a tool call for security risks.
107
+ * Returns a comprehensive analysis result with multi-layer findings.
108
+ */
109
+ analyze(toolName: string, args: Record<string, unknown>): Promise<AnalysisResult>;
110
+ /** Quick synchronous check (Layer 1 only, for hot path) */
111
+ quickCheck(toolName: string, args: Record<string, unknown>): {
112
+ riskLevel: 'safe' | 'suspicious' | 'dangerous' | 'critical';
113
+ riskScore: number;
114
+ topFinding: string;
115
+ };
116
+ /** Add custom rules at runtime */
117
+ addRule(rule: IntentRule): void;
118
+ /** Get all active rules */
119
+ getRules(): IntentRule[];
120
+ private analyzeWithRules;
121
+ private extractCommand;
122
+ private getPatternTarget;
123
+ private riskLevelToScore;
124
+ private applySensitivity;
125
+ private collectIntents;
126
+ private combineResults;
127
+ }
128
+ /** Create a semantic analyzer with default settings */
129
+ declare function createSemanticAnalyzer(overrides?: Partial<SemanticAnalysisConfig>): SemanticAnalyzer;
130
+ /** Create a paranoid analyzer (highest sensitivity, all layers) */
131
+ declare function createParanoidAnalyzer(llmProvider?: LLMProvider): SemanticAnalyzer;
132
+
133
+ export { type AnalysisResult, type DetectedIntent, type IntentCategory, type IntentPattern, type IntentRule, type LLMJudgment, type LLMProvider, type LayerResult, type SemanticAnalysisConfig, SemanticAnalyzer, createParanoidAnalyzer, createSemanticAnalyzer };