sovr-mcp-proxy 7.1.0 → 7.2.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.
@@ -1,40 +1,34 @@
1
1
  /**
2
- * SOVR Semantic Analyzer — Multi-Layer Intent Detection Engine
2
+ * SOVR Semantic Analyzer v2 Deterministic Intent Detection Engine
3
3
  *
4
- * P1-2: Goes beyond regex pattern matching to understand command INTENT.
4
+ * Architecture principle: "AI hallucinations cannot check AI hallucinations."
5
+ * All analysis layers are deterministic — zero LLM dependency.
5
6
  *
6
- * Three analysis layers (evidence-based first, LLM last):
7
- * Layer 1: Rule-based pattern matching (fast, deterministic)
7
+ * Three analysis layers (all evidence-based, all deterministic):
8
+ * Layer 1: Rule-based pattern matching (fast, regex + keyword)
8
9
  * Layer 2: Structural analysis (AST-like decomposition of commands)
9
- * Layer 3: LLM-as-Judge (optional, for ambiguous cases only)
10
+ * Layer 3: Formal verification (path constraints, state machine, type checking)
10
11
  *
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.
12
+ * Design principle per ADR-135+:
13
+ * - "Evidence-based over LLM semantic"
14
+ * - "Use math and deterministic rules to constrain AI, not AI to constrain AI"
15
+ * - LLM is ONLY used for post-hoc audit report generation, NEVER for real-time decisions
13
16
  */
14
17
  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
18
  /** Custom intent rules */
24
19
  customRules: IntentRule[];
25
- /** Enable structural analysis */
20
+ /** Enable structural analysis (Layer 2) */
26
21
  enableStructural: boolean;
22
+ /** Enable formal verification (Layer 3) */
23
+ enableFormalVerification: boolean;
27
24
  /** Sensitivity level */
28
25
  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;
26
+ /** Allowed base directories for file operations */
27
+ allowedPaths: string[];
28
+ /** Known safe SQL tables (for type checking) */
29
+ safeTables: string[];
30
+ /** Maximum command complexity score before auto-block */
31
+ maxComplexity: number;
38
32
  }
39
33
  interface IntentRule {
40
34
  /** Rule ID */
@@ -76,7 +70,7 @@ interface AnalysisResult {
76
70
  layers: {
77
71
  rules: LayerResult;
78
72
  structural: LayerResult;
79
- llm?: LayerResult;
73
+ formal?: LayerResult;
80
74
  };
81
75
  /** Recommended action */
82
76
  recommendation: 'allow' | 'warn' | 'block' | 'require-approval';
@@ -89,7 +83,7 @@ interface DetectedIntent {
89
83
  category: IntentCategory;
90
84
  description: string;
91
85
  confidence: number;
92
- source: 'rule' | 'structural' | 'llm';
86
+ source: 'rule' | 'structural' | 'formal';
93
87
  evidence: string[];
94
88
  }
95
89
  interface LayerResult {
@@ -98,13 +92,121 @@ interface LayerResult {
98
92
  confidence: number;
99
93
  findings: string[];
100
94
  }
95
+ /** State machine states for command safety */
96
+ type SafetyState = 'safe' | 'elevated' | 'destructive' | 'irreversible';
97
+ interface StateTransition {
98
+ from: SafetyState;
99
+ trigger: string;
100
+ to: SafetyState;
101
+ pattern: RegExp;
102
+ }
103
+ interface PathConstraint {
104
+ /** Path being accessed */
105
+ path: string;
106
+ /** Operation type */
107
+ operation: 'read' | 'write' | 'delete' | 'execute';
108
+ /** Whether the path is within allowed boundaries */
109
+ withinBounds: boolean;
110
+ /** Violation reason if out of bounds */
111
+ violation?: string;
112
+ }
113
+ interface SQLTypeCheck {
114
+ /** SQL statement type */
115
+ statementType: 'SELECT' | 'INSERT' | 'UPDATE' | 'DELETE' | 'DROP' | 'CREATE' | 'ALTER' | 'TRUNCATE' | 'UNKNOWN';
116
+ /** Whether WHERE clause exists (for UPDATE/DELETE) */
117
+ hasWhereClause: boolean;
118
+ /** Tables referenced */
119
+ tables: string[];
120
+ /** Whether tables are in safe list */
121
+ tablesAreSafe: boolean;
122
+ /** Violations found */
123
+ violations: string[];
124
+ }
125
+ interface FormalVerificationResult {
126
+ /** Path constraint violations */
127
+ pathViolations: PathConstraint[];
128
+ /** Safety state machine final state */
129
+ finalState: SafetyState;
130
+ /** State transitions taken */
131
+ transitions: {
132
+ trigger: string;
133
+ from: SafetyState;
134
+ to: SafetyState;
135
+ }[];
136
+ /** SQL type check results */
137
+ sqlCheck?: SQLTypeCheck;
138
+ /** Command complexity score */
139
+ complexityScore: number;
140
+ /** Whether complexity exceeds threshold */
141
+ complexityExceeded: boolean;
142
+ /** Overall formal risk score */
143
+ riskScore: number;
144
+ /** Formal verification findings */
145
+ findings: string[];
146
+ }
147
+ declare const BUILTIN_RULES: IntentRule[];
148
+ interface CommandStructure {
149
+ /** Pipe segments */
150
+ pipes: string[];
151
+ /** Redirect targets */
152
+ redirections: string[];
153
+ /** Subshell/command substitution instances */
154
+ subshells: string[];
155
+ /** File paths referenced */
156
+ filePaths: string[];
157
+ /** Network targets (URLs, IPs) */
158
+ networkTargets: string[];
159
+ /** Environment variables referenced */
160
+ envVars: string[];
161
+ /** Complexity score */
162
+ complexity: number;
163
+ }
164
+ declare function analyzeStructure(command: string): CommandStructure;
165
+ declare function structuralRiskAssessment(structure: CommandStructure): LayerResult;
166
+ /**
167
+ * Path Constraint Solver — proves whether file operations stay within allowed boundaries.
168
+ * Pure string analysis, no filesystem access needed.
169
+ */
170
+ declare function verifyPathConstraints(command: string, filePaths: string[], allowedPaths: string[]): PathConstraint[];
171
+ /**
172
+ * SQL Type Checker — verifies SQL statement safety through structural analysis.
173
+ * No database connection needed — pure syntax analysis.
174
+ */
175
+ declare function checkSQLType(sql: string, safeTables: string[]): SQLTypeCheck;
176
+ /**
177
+ * Run the safety state machine on a command.
178
+ * Returns the final state and all transitions taken.
179
+ */
180
+ declare function runStateMachine(command: string): {
181
+ finalState: SafetyState;
182
+ transitions: {
183
+ trigger: string;
184
+ from: SafetyState;
185
+ to: SafetyState;
186
+ }[];
187
+ };
188
+ /**
189
+ * Full formal verification — combines path constraints, state machine, and SQL type checking.
190
+ */
191
+ declare function formalVerify(command: string, args: Record<string, unknown>, structure: CommandStructure, config: SemanticAnalysisConfig): FormalVerificationResult;
192
+ /**
193
+ * Maps rule findings and structural findings to correct IntentCategory.
194
+ * This was the bug: previously everything was mapped to 'code_execution'.
195
+ * Now we properly extract the category from the matched rule.
196
+ */
197
+ /** Map a rule finding back to its IntentCategory */
198
+ declare function findRuleCategoryByName(ruleName: string, rules: IntentRule[]): IntentCategory;
199
+ /** Map structural findings to IntentCategory based on content analysis */
200
+ declare function classifyStructuralFinding(finding: string): IntentCategory;
201
+ /** Map formal verification findings to IntentCategory */
202
+ declare function classifyFormalFinding(finding: string): IntentCategory;
101
203
  declare class SemanticAnalyzer {
102
204
  private config;
103
205
  private rules;
104
206
  constructor(config?: Partial<SemanticAnalysisConfig>);
105
207
  /**
106
208
  * Analyze a tool call for security risks.
107
- * Returns a comprehensive analysis result with multi-layer findings.
209
+ * All three layers are deterministic zero LLM dependency.
108
210
  */
109
211
  analyze(toolName: string, args: Record<string, unknown>): Promise<AnalysisResult>;
110
212
  /** Quick synchronous check (Layer 1 only, for hot path) */
@@ -122,12 +224,24 @@ declare class SemanticAnalyzer {
122
224
  private getPatternTarget;
123
225
  private riskLevelToScore;
124
226
  private applySensitivity;
227
+ /**
228
+ * Collect intents with CORRECT IntentCategory mapping.
229
+ *
230
+ * BUG FIX: Previously all intents were mapped to 'code_execution'.
231
+ * Now we properly extract the category from:
232
+ * - Rule findings → look up the matched rule's category
233
+ * - Structural findings → classify based on finding content
234
+ * - Formal findings → classify based on violation type
235
+ */
125
236
  private collectIntents;
126
237
  private combineResults;
127
238
  }
128
239
  /** Create a semantic analyzer with default settings */
129
240
  declare function createSemanticAnalyzer(overrides?: Partial<SemanticAnalysisConfig>): SemanticAnalyzer;
130
- /** Create a paranoid analyzer (highest sensitivity, all layers) */
131
- declare function createParanoidAnalyzer(llmProvider?: LLMProvider): SemanticAnalyzer;
241
+ /** Create a paranoid analyzer (highest sensitivity, all layers, strictest constraints) */
242
+ declare function createParanoidAnalyzer(config?: {
243
+ allowedPaths?: string[];
244
+ safeTables?: string[];
245
+ }): SemanticAnalyzer;
132
246
 
133
- export { type AnalysisResult, type DetectedIntent, type IntentCategory, type IntentPattern, type IntentRule, type LLMJudgment, type LLMProvider, type LayerResult, type SemanticAnalysisConfig, SemanticAnalyzer, createParanoidAnalyzer, createSemanticAnalyzer };
247
+ export { type AnalysisResult, BUILTIN_RULES, type CommandStructure, type DetectedIntent, type FormalVerificationResult, type IntentCategory, type IntentPattern, type IntentRule, type LayerResult, type PathConstraint, type SQLTypeCheck, type SafetyState, type SemanticAnalysisConfig, SemanticAnalyzer, type StateTransition, analyzeStructure, checkSQLType, classifyFormalFinding, classifyStructuralFinding, createParanoidAnalyzer, createSemanticAnalyzer, findRuleCategoryByName, formalVerify, runStateMachine, structuralRiskAssessment, verifyPathConstraints };
@@ -1,40 +1,34 @@
1
1
  /**
2
- * SOVR Semantic Analyzer — Multi-Layer Intent Detection Engine
2
+ * SOVR Semantic Analyzer v2 Deterministic Intent Detection Engine
3
3
  *
4
- * P1-2: Goes beyond regex pattern matching to understand command INTENT.
4
+ * Architecture principle: "AI hallucinations cannot check AI hallucinations."
5
+ * All analysis layers are deterministic — zero LLM dependency.
5
6
  *
6
- * Three analysis layers (evidence-based first, LLM last):
7
- * Layer 1: Rule-based pattern matching (fast, deterministic)
7
+ * Three analysis layers (all evidence-based, all deterministic):
8
+ * Layer 1: Rule-based pattern matching (fast, regex + keyword)
8
9
  * Layer 2: Structural analysis (AST-like decomposition of commands)
9
- * Layer 3: LLM-as-Judge (optional, for ambiguous cases only)
10
+ * Layer 3: Formal verification (path constraints, state machine, type checking)
10
11
  *
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.
12
+ * Design principle per ADR-135+:
13
+ * - "Evidence-based over LLM semantic"
14
+ * - "Use math and deterministic rules to constrain AI, not AI to constrain AI"
15
+ * - LLM is ONLY used for post-hoc audit report generation, NEVER for real-time decisions
13
16
  */
14
17
  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
18
  /** Custom intent rules */
24
19
  customRules: IntentRule[];
25
- /** Enable structural analysis */
20
+ /** Enable structural analysis (Layer 2) */
26
21
  enableStructural: boolean;
22
+ /** Enable formal verification (Layer 3) */
23
+ enableFormalVerification: boolean;
27
24
  /** Sensitivity level */
28
25
  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;
26
+ /** Allowed base directories for file operations */
27
+ allowedPaths: string[];
28
+ /** Known safe SQL tables (for type checking) */
29
+ safeTables: string[];
30
+ /** Maximum command complexity score before auto-block */
31
+ maxComplexity: number;
38
32
  }
39
33
  interface IntentRule {
40
34
  /** Rule ID */
@@ -76,7 +70,7 @@ interface AnalysisResult {
76
70
  layers: {
77
71
  rules: LayerResult;
78
72
  structural: LayerResult;
79
- llm?: LayerResult;
73
+ formal?: LayerResult;
80
74
  };
81
75
  /** Recommended action */
82
76
  recommendation: 'allow' | 'warn' | 'block' | 'require-approval';
@@ -89,7 +83,7 @@ interface DetectedIntent {
89
83
  category: IntentCategory;
90
84
  description: string;
91
85
  confidence: number;
92
- source: 'rule' | 'structural' | 'llm';
86
+ source: 'rule' | 'structural' | 'formal';
93
87
  evidence: string[];
94
88
  }
95
89
  interface LayerResult {
@@ -98,13 +92,121 @@ interface LayerResult {
98
92
  confidence: number;
99
93
  findings: string[];
100
94
  }
95
+ /** State machine states for command safety */
96
+ type SafetyState = 'safe' | 'elevated' | 'destructive' | 'irreversible';
97
+ interface StateTransition {
98
+ from: SafetyState;
99
+ trigger: string;
100
+ to: SafetyState;
101
+ pattern: RegExp;
102
+ }
103
+ interface PathConstraint {
104
+ /** Path being accessed */
105
+ path: string;
106
+ /** Operation type */
107
+ operation: 'read' | 'write' | 'delete' | 'execute';
108
+ /** Whether the path is within allowed boundaries */
109
+ withinBounds: boolean;
110
+ /** Violation reason if out of bounds */
111
+ violation?: string;
112
+ }
113
+ interface SQLTypeCheck {
114
+ /** SQL statement type */
115
+ statementType: 'SELECT' | 'INSERT' | 'UPDATE' | 'DELETE' | 'DROP' | 'CREATE' | 'ALTER' | 'TRUNCATE' | 'UNKNOWN';
116
+ /** Whether WHERE clause exists (for UPDATE/DELETE) */
117
+ hasWhereClause: boolean;
118
+ /** Tables referenced */
119
+ tables: string[];
120
+ /** Whether tables are in safe list */
121
+ tablesAreSafe: boolean;
122
+ /** Violations found */
123
+ violations: string[];
124
+ }
125
+ interface FormalVerificationResult {
126
+ /** Path constraint violations */
127
+ pathViolations: PathConstraint[];
128
+ /** Safety state machine final state */
129
+ finalState: SafetyState;
130
+ /** State transitions taken */
131
+ transitions: {
132
+ trigger: string;
133
+ from: SafetyState;
134
+ to: SafetyState;
135
+ }[];
136
+ /** SQL type check results */
137
+ sqlCheck?: SQLTypeCheck;
138
+ /** Command complexity score */
139
+ complexityScore: number;
140
+ /** Whether complexity exceeds threshold */
141
+ complexityExceeded: boolean;
142
+ /** Overall formal risk score */
143
+ riskScore: number;
144
+ /** Formal verification findings */
145
+ findings: string[];
146
+ }
147
+ declare const BUILTIN_RULES: IntentRule[];
148
+ interface CommandStructure {
149
+ /** Pipe segments */
150
+ pipes: string[];
151
+ /** Redirect targets */
152
+ redirections: string[];
153
+ /** Subshell/command substitution instances */
154
+ subshells: string[];
155
+ /** File paths referenced */
156
+ filePaths: string[];
157
+ /** Network targets (URLs, IPs) */
158
+ networkTargets: string[];
159
+ /** Environment variables referenced */
160
+ envVars: string[];
161
+ /** Complexity score */
162
+ complexity: number;
163
+ }
164
+ declare function analyzeStructure(command: string): CommandStructure;
165
+ declare function structuralRiskAssessment(structure: CommandStructure): LayerResult;
166
+ /**
167
+ * Path Constraint Solver — proves whether file operations stay within allowed boundaries.
168
+ * Pure string analysis, no filesystem access needed.
169
+ */
170
+ declare function verifyPathConstraints(command: string, filePaths: string[], allowedPaths: string[]): PathConstraint[];
171
+ /**
172
+ * SQL Type Checker — verifies SQL statement safety through structural analysis.
173
+ * No database connection needed — pure syntax analysis.
174
+ */
175
+ declare function checkSQLType(sql: string, safeTables: string[]): SQLTypeCheck;
176
+ /**
177
+ * Run the safety state machine on a command.
178
+ * Returns the final state and all transitions taken.
179
+ */
180
+ declare function runStateMachine(command: string): {
181
+ finalState: SafetyState;
182
+ transitions: {
183
+ trigger: string;
184
+ from: SafetyState;
185
+ to: SafetyState;
186
+ }[];
187
+ };
188
+ /**
189
+ * Full formal verification — combines path constraints, state machine, and SQL type checking.
190
+ */
191
+ declare function formalVerify(command: string, args: Record<string, unknown>, structure: CommandStructure, config: SemanticAnalysisConfig): FormalVerificationResult;
192
+ /**
193
+ * Maps rule findings and structural findings to correct IntentCategory.
194
+ * This was the bug: previously everything was mapped to 'code_execution'.
195
+ * Now we properly extract the category from the matched rule.
196
+ */
197
+ /** Map a rule finding back to its IntentCategory */
198
+ declare function findRuleCategoryByName(ruleName: string, rules: IntentRule[]): IntentCategory;
199
+ /** Map structural findings to IntentCategory based on content analysis */
200
+ declare function classifyStructuralFinding(finding: string): IntentCategory;
201
+ /** Map formal verification findings to IntentCategory */
202
+ declare function classifyFormalFinding(finding: string): IntentCategory;
101
203
  declare class SemanticAnalyzer {
102
204
  private config;
103
205
  private rules;
104
206
  constructor(config?: Partial<SemanticAnalysisConfig>);
105
207
  /**
106
208
  * Analyze a tool call for security risks.
107
- * Returns a comprehensive analysis result with multi-layer findings.
209
+ * All three layers are deterministic zero LLM dependency.
108
210
  */
109
211
  analyze(toolName: string, args: Record<string, unknown>): Promise<AnalysisResult>;
110
212
  /** Quick synchronous check (Layer 1 only, for hot path) */
@@ -122,12 +224,24 @@ declare class SemanticAnalyzer {
122
224
  private getPatternTarget;
123
225
  private riskLevelToScore;
124
226
  private applySensitivity;
227
+ /**
228
+ * Collect intents with CORRECT IntentCategory mapping.
229
+ *
230
+ * BUG FIX: Previously all intents were mapped to 'code_execution'.
231
+ * Now we properly extract the category from:
232
+ * - Rule findings → look up the matched rule's category
233
+ * - Structural findings → classify based on finding content
234
+ * - Formal findings → classify based on violation type
235
+ */
125
236
  private collectIntents;
126
237
  private combineResults;
127
238
  }
128
239
  /** Create a semantic analyzer with default settings */
129
240
  declare function createSemanticAnalyzer(overrides?: Partial<SemanticAnalysisConfig>): SemanticAnalyzer;
130
- /** Create a paranoid analyzer (highest sensitivity, all layers) */
131
- declare function createParanoidAnalyzer(llmProvider?: LLMProvider): SemanticAnalyzer;
241
+ /** Create a paranoid analyzer (highest sensitivity, all layers, strictest constraints) */
242
+ declare function createParanoidAnalyzer(config?: {
243
+ allowedPaths?: string[];
244
+ safeTables?: string[];
245
+ }): SemanticAnalyzer;
132
246
 
133
- export { type AnalysisResult, type DetectedIntent, type IntentCategory, type IntentPattern, type IntentRule, type LLMJudgment, type LLMProvider, type LayerResult, type SemanticAnalysisConfig, SemanticAnalyzer, createParanoidAnalyzer, createSemanticAnalyzer };
247
+ export { type AnalysisResult, BUILTIN_RULES, type CommandStructure, type DetectedIntent, type FormalVerificationResult, type IntentCategory, type IntentPattern, type IntentRule, type LayerResult, type PathConstraint, type SQLTypeCheck, type SafetyState, type SemanticAnalysisConfig, SemanticAnalyzer, type StateTransition, analyzeStructure, checkSQLType, classifyFormalFinding, classifyStructuralFinding, createParanoidAnalyzer, createSemanticAnalyzer, findRuleCategoryByName, formalVerify, runStateMachine, structuralRiskAssessment, verifyPathConstraints };