@sovr/engine 1.1.1 → 2.0.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.
package/LICENSE ADDED
@@ -0,0 +1,81 @@
1
+ Business Source License 1.1
2
+
3
+ License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved.
4
+ "Business Source License" is a trademark of MariaDB Corporation Ab.
5
+
6
+ Parameters
7
+
8
+ Licensor: SOVR AI
9
+ Licensed Work: @sovr/engine v1.2.0
10
+ The Licensed Work is (c) 2025-2026 SOVR AI.
11
+ Additional Use Grant: You may use the Licensed Work for non-production
12
+ evaluation, development, and testing purposes.
13
+ Change Date: Four years from the date of each version's release.
14
+ Change License: Apache License, Version 2.0
15
+
16
+ Terms
17
+
18
+ The Licensor hereby grants you the right to copy, modify, create derivative
19
+ works, redistribute, and make non-production use of the Licensed Work. The
20
+ Licensor may make an Additional Use Grant, above, permitting limited
21
+ production use.
22
+
23
+ Effective on the Change Date, or the fourth anniversary of the first publicly
24
+ available distribution of a specific version of the Licensed Work under this
25
+ License, whichever comes first, the Licensor hereby grants you rights under
26
+ the terms of the Change License, and the rights granted in the paragraph
27
+ above terminate.
28
+
29
+ If your use of the Licensed Work does not comply with the requirements
30
+ currently in effect as described in this License, you must purchase a
31
+ commercial license from the Licensor, its affiliated entities, or authorized
32
+ resellers, or you must refrain from using the Licensed Work.
33
+
34
+ All copies of the original and modified Licensed Work, and derivative works
35
+ of the Licensed Work, are subject to this License. This License applies
36
+ separately for each version of the Licensed Work and the Change Date may vary
37
+ for each version of the Licensed Work released by Licensor.
38
+
39
+ You must conspicuously display this License on each original or modified copy
40
+ of the Licensed Work. If you receive the Licensed Work in original or
41
+ modified form from a third party, the terms and conditions set forth in this
42
+ License apply to your use of that work.
43
+
44
+ Any use of the Licensed Work in violation of this License will automatically
45
+ terminate your rights under this License for the current and all other
46
+ versions of the Licensed Work.
47
+
48
+ This License does not grant you any right in any trademark or logo of
49
+ Licensor or its affiliates (provided that you may use a trademark or logo of
50
+ Licensor as expressly required by this License).
51
+
52
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
53
+ AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
54
+ EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
55
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
56
+ TITLE.
57
+
58
+ MariaDB hereby grants you permission to use this License's text to license
59
+ your works, and to refer to it using the trademark "Business Source License",
60
+ as long as you comply with the Covenants of Licensor below.
61
+
62
+ Covenants of Licensor
63
+
64
+ In consideration of the right to use this License's text and the "Business
65
+ Source License" name and trademark, Licensor covenants to MariaDB, and to all
66
+ other recipients of the licensed work to be provided by Licensor:
67
+
68
+ 1. To specify as the Change License the GPL Version 2.0 or any later version,
69
+ or a license that is compatible with GPL Version 2.0 or a later version,
70
+ where "compatible" means that software provided under the Change License can
71
+ be included in a program with software provided under GPL Version 2.0 or a
72
+ later version. Licensor may specify additional Change Licenses without
73
+ limitation.
74
+
75
+ 2. To either: (a) specify an additional grant of rights to use that does not
76
+ impose any additional restriction on the right granted in this License, as
77
+ the Additional Use Grant; or (b) insert the text "None".
78
+
79
+ 3. To specify a Change Date.
80
+
81
+ 4. Not to modify this License in any other way.
package/README.md ADDED
@@ -0,0 +1,105 @@
1
+ # @sovr/engine
2
+
3
+ **Unified Policy Engine for SOVR** — the single decision plane for all proxy channels.
4
+
5
+ [![npm](https://img.shields.io/npm/v/@sovr/engine)](https://www.npmjs.com/package/@sovr/engine)
6
+ [![License](https://img.shields.io/badge/license-BSL--1.1-blue)](LICENSE)
7
+
8
+ ## Overview
9
+
10
+ `@sovr/engine` is the core policy evaluation engine that powers all SOVR proxy channels. It provides a unified interface for evaluating actions against policy rules, regardless of the channel (exec, sql, http, mcp).
11
+
12
+ This package is used internally by:
13
+
14
+ - [`sovr-mcp-proxy`](https://www.npmjs.com/package/sovr-mcp-proxy) — MCP transport proxy
15
+ - [`@sovr/proxy-exec`](https://www.npmjs.com/package/@sovr/proxy-exec) — Shell command proxy
16
+ - [`@sovr/proxy-sql`](https://www.npmjs.com/package/@sovr/proxy-sql) — SQL statement proxy
17
+ - [`@sovr/proxy-http`](https://www.npmjs.com/package/@sovr/proxy-http) — HTTP request proxy
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ npm install @sovr/engine
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```typescript
28
+ import { PolicyEngine, evaluate } from '@sovr/engine';
29
+
30
+ const engine = new PolicyEngine({
31
+ rules: [/* your policy rules */],
32
+ failMode: 'fail-close',
33
+ });
34
+
35
+ const result = engine.evaluate({
36
+ channel: 'exec',
37
+ action: 'rm -rf /tmp/data',
38
+ context: { user: 'agent-1' },
39
+ });
40
+
41
+ // result.verdict: 'allow' | 'deny' | 'escalate'
42
+ // result.rule: the matching rule (if any)
43
+ // result.reason: human-readable explanation
44
+ ```
45
+
46
+ ## API
47
+
48
+ ### `PolicyEngine`
49
+
50
+ The main class for policy evaluation.
51
+
52
+ | Method | Description |
53
+ |--------|-------------|
54
+ | `evaluate(request)` | Evaluate an action against all loaded rules |
55
+ | `addRule(rule)` | Add a rule at runtime |
56
+ | `removeRule(id)` | Remove a rule by ID |
57
+ | `listRules()` | List all active rules |
58
+ | `getStats()` | Get evaluation statistics |
59
+
60
+ ### `evaluate(request)`
61
+
62
+ Standalone function for one-shot evaluation without engine instantiation.
63
+
64
+ ### Rule Format
65
+
66
+ ```typescript
67
+ interface PolicyRule {
68
+ id: string;
69
+ description: string;
70
+ channels: ('exec' | 'sql' | 'http' | 'mcp')[];
71
+ action_pattern: string; // regex pattern
72
+ resource_pattern?: string; // optional resource filter
73
+ effect: 'allow' | 'deny' | 'escalate';
74
+ risk_level: 'low' | 'medium' | 'high' | 'critical';
75
+ priority: number; // higher = evaluated first
76
+ }
77
+ ```
78
+
79
+ ### Verdict Format
80
+
81
+ ```typescript
82
+ interface Verdict {
83
+ verdict: 'allow' | 'deny' | 'escalate';
84
+ rule: PolicyRule | null;
85
+ reason: string;
86
+ timestamp: number;
87
+ channel: string;
88
+ }
89
+ ```
90
+
91
+ ## Built-in Rules
92
+
93
+ The engine ships with 15 built-in rules covering common risk patterns across all four channels. See the [sovr-mcp-proxy documentation](https://www.npmjs.com/package/sovr-mcp-proxy) for the complete list.
94
+
95
+ ## License
96
+
97
+ BSL-1.1 (Business Source License 1.1) — See [LICENSE](LICENSE) for details.
98
+
99
+ The Licensed Work is the @sovr/engine software. The Change Date is four years from each version's release. After the Change Date, each version converts to Apache-2.0.
100
+
101
+ ## Links
102
+
103
+ - **Website**: [sovr.inc](https://sovr.inc)
104
+ - **GitHub**: [xie38388/sovr](https://github.com/xie38388/sovr)
105
+ - **npm**: [@sovr/engine](https://www.npmjs.com/package/@sovr/engine)
package/dist/index.d.mts CHANGED
@@ -179,12 +179,34 @@ declare const DEFAULT_RULES: PolicyRule[];
179
179
  * }
180
180
  * ```
181
181
  */
182
+ type EngineTier = 'free' | 'personal' | 'starter' | 'pro' | 'enterprise';
183
+ interface EngineTierLimits {
184
+ evaluationsPerMonth: number;
185
+ irreversibleAllowsPerMonth: number;
186
+ }
182
187
  declare class PolicyEngine {
183
188
  private rules;
184
189
  private defaultVerdict;
185
190
  private auditLog;
186
191
  private onAudit?;
187
- constructor(config: EngineConfig);
192
+ private _tier;
193
+ private _usage;
194
+ constructor(config: EngineConfig & {
195
+ tier?: EngineTier;
196
+ });
197
+ /** Set the current tier (e.g., after API key verification) */
198
+ setTier(tier: EngineTier): void;
199
+ /** Get current tier */
200
+ get tier(): EngineTier;
201
+ /** Get tier limits */
202
+ get tierLimits(): EngineTierLimits;
203
+ /** Get current usage */
204
+ get usage(): {
205
+ evaluations: number;
206
+ irreversibleAllows: number;
207
+ monthKey: string;
208
+ };
209
+ private _resetMonthIfNeeded;
188
210
  /**
189
211
  * Evaluate an action against the policy rules.
190
212
  * Returns a decision with verdict, risk score, and matched rules.
@@ -215,4 +237,4 @@ declare class PolicyEngine {
215
237
  }): void;
216
238
  }
217
239
 
218
- export { type AuditEvent, type Channel, DEFAULT_RULES, type EngineConfig, type EvalRequest, type EvalResult, type ExecContext, type HttpContext, type McpContext, PolicyEngine, type PolicyRule, type RiskLevel, type RuleCondition, type SqlContext, type Verdict, PolicyEngine as default };
240
+ export { type AuditEvent, type Channel, DEFAULT_RULES, type EngineConfig, type EngineTier, type EngineTierLimits, type EvalRequest, type EvalResult, type ExecContext, type HttpContext, type McpContext, PolicyEngine, type PolicyRule, type RiskLevel, type RuleCondition, type SqlContext, type Verdict, PolicyEngine as default };
package/dist/index.d.ts CHANGED
@@ -179,12 +179,34 @@ declare const DEFAULT_RULES: PolicyRule[];
179
179
  * }
180
180
  * ```
181
181
  */
182
+ type EngineTier = 'free' | 'personal' | 'starter' | 'pro' | 'enterprise';
183
+ interface EngineTierLimits {
184
+ evaluationsPerMonth: number;
185
+ irreversibleAllowsPerMonth: number;
186
+ }
182
187
  declare class PolicyEngine {
183
188
  private rules;
184
189
  private defaultVerdict;
185
190
  private auditLog;
186
191
  private onAudit?;
187
- constructor(config: EngineConfig);
192
+ private _tier;
193
+ private _usage;
194
+ constructor(config: EngineConfig & {
195
+ tier?: EngineTier;
196
+ });
197
+ /** Set the current tier (e.g., after API key verification) */
198
+ setTier(tier: EngineTier): void;
199
+ /** Get current tier */
200
+ get tier(): EngineTier;
201
+ /** Get tier limits */
202
+ get tierLimits(): EngineTierLimits;
203
+ /** Get current usage */
204
+ get usage(): {
205
+ evaluations: number;
206
+ irreversibleAllows: number;
207
+ monthKey: string;
208
+ };
209
+ private _resetMonthIfNeeded;
188
210
  /**
189
211
  * Evaluate an action against the policy rules.
190
212
  * Returns a decision with verdict, risk score, and matched rules.
@@ -215,4 +237,4 @@ declare class PolicyEngine {
215
237
  }): void;
216
238
  }
217
239
 
218
- export { type AuditEvent, type Channel, DEFAULT_RULES, type EngineConfig, type EvalRequest, type EvalResult, type ExecContext, type HttpContext, type McpContext, PolicyEngine, type PolicyRule, type RiskLevel, type RuleCondition, type SqlContext, type Verdict, PolicyEngine as default };
240
+ export { type AuditEvent, type Channel, DEFAULT_RULES, type EngineConfig, type EngineTier, type EngineTierLimits, type EvalRequest, type EvalResult, type ExecContext, type HttpContext, type McpContext, PolicyEngine, type PolicyRule, type RiskLevel, type RuleCondition, type SqlContext, type Verdict, PolicyEngine as default };
package/dist/index.js CHANGED
@@ -258,22 +258,75 @@ var RISK_SCORES = {
258
258
  high: 70,
259
259
  critical: 95
260
260
  };
261
+ var ENGINE_TIER_LIMITS = {
262
+ free: { evaluationsPerMonth: 50, irreversibleAllowsPerMonth: 0 },
263
+ personal: { evaluationsPerMonth: 5e3, irreversibleAllowsPerMonth: 500 },
264
+ starter: { evaluationsPerMonth: 5e4, irreversibleAllowsPerMonth: 5e3 },
265
+ pro: { evaluationsPerMonth: 5e5, irreversibleAllowsPerMonth: 5e4 },
266
+ enterprise: { evaluationsPerMonth: -1, irreversibleAllowsPerMonth: -1 }
267
+ };
261
268
  var PolicyEngine = class {
262
269
  rules;
263
270
  defaultVerdict;
264
271
  auditLog;
265
272
  onAudit;
273
+ _tier = "free";
274
+ _usage = { evaluations: 0, irreversibleAllows: 0, monthKey: "" };
266
275
  constructor(config) {
267
276
  this.rules = config.rules.map((r) => ({ ...r, conditions: r.conditions ? [...r.conditions] : void 0 })).sort((a, b) => b.priority - a.priority);
268
277
  this.defaultVerdict = config.default_verdict ?? "allow";
269
278
  this.auditLog = config.audit_log ?? false;
270
279
  this.onAudit = config.on_audit;
280
+ this._tier = config.tier ?? "free";
281
+ const now = /* @__PURE__ */ new Date();
282
+ this._usage.monthKey = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}`;
283
+ }
284
+ /** Set the current tier (e.g., after API key verification) */
285
+ setTier(tier) {
286
+ this._tier = tier;
287
+ }
288
+ /** Get current tier */
289
+ get tier() {
290
+ return this._tier;
291
+ }
292
+ /** Get tier limits */
293
+ get tierLimits() {
294
+ return ENGINE_TIER_LIMITS[this._tier];
295
+ }
296
+ /** Get current usage */
297
+ get usage() {
298
+ return { ...this._usage };
299
+ }
300
+ _resetMonthIfNeeded() {
301
+ const now = /* @__PURE__ */ new Date();
302
+ const mk = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}`;
303
+ if (this._usage.monthKey !== mk) {
304
+ this._usage = { evaluations: 0, irreversibleAllows: 0, monthKey: mk };
305
+ }
271
306
  }
272
307
  /**
273
308
  * Evaluate an action against the policy rules.
274
309
  * Returns a decision with verdict, risk score, and matched rules.
275
310
  */
276
311
  evaluate(request) {
312
+ this._resetMonthIfNeeded();
313
+ this._usage.evaluations++;
314
+ const evalLimit = ENGINE_TIER_LIMITS[this._tier].evaluationsPerMonth;
315
+ if (evalLimit >= 0 && this._usage.evaluations > evalLimit) {
316
+ return {
317
+ decision_id: generateDecisionId(),
318
+ verdict: "deny",
319
+ allowed: false,
320
+ requires_approval: false,
321
+ reason: `Evaluation quota exceeded (${evalLimit}/month for ${this._tier} tier). Upgrade at https://sovr.inc/pricing`,
322
+ risk_score: 0,
323
+ matched_rules: [],
324
+ risk_level: "none",
325
+ channel: request.channel,
326
+ trace_id: request.trace_id || generateTraceId(),
327
+ timestamp: Date.now()
328
+ };
329
+ }
277
330
  const traceId = request.trace_id || generateTraceId();
278
331
  const decisionId = generateDecisionId();
279
332
  const matchedRules = [];
@@ -339,6 +392,14 @@ var PolicyEngine = class {
339
392
  Promise.resolve(this.onAudit(event)).catch(() => {
340
393
  });
341
394
  }
395
+ if (this._tier === "free") {
396
+ return {
397
+ ...result,
398
+ risk_score: 0,
399
+ matched_rules: [],
400
+ reason: "[UPGRADE to Personal+ for detailed evaluation results] https://sovr.inc/pricing"
401
+ };
402
+ }
342
403
  return result;
343
404
  }
344
405
  /**
package/dist/index.mjs CHANGED
@@ -232,22 +232,75 @@ var RISK_SCORES = {
232
232
  high: 70,
233
233
  critical: 95
234
234
  };
235
+ var ENGINE_TIER_LIMITS = {
236
+ free: { evaluationsPerMonth: 50, irreversibleAllowsPerMonth: 0 },
237
+ personal: { evaluationsPerMonth: 5e3, irreversibleAllowsPerMonth: 500 },
238
+ starter: { evaluationsPerMonth: 5e4, irreversibleAllowsPerMonth: 5e3 },
239
+ pro: { evaluationsPerMonth: 5e5, irreversibleAllowsPerMonth: 5e4 },
240
+ enterprise: { evaluationsPerMonth: -1, irreversibleAllowsPerMonth: -1 }
241
+ };
235
242
  var PolicyEngine = class {
236
243
  rules;
237
244
  defaultVerdict;
238
245
  auditLog;
239
246
  onAudit;
247
+ _tier = "free";
248
+ _usage = { evaluations: 0, irreversibleAllows: 0, monthKey: "" };
240
249
  constructor(config) {
241
250
  this.rules = config.rules.map((r) => ({ ...r, conditions: r.conditions ? [...r.conditions] : void 0 })).sort((a, b) => b.priority - a.priority);
242
251
  this.defaultVerdict = config.default_verdict ?? "allow";
243
252
  this.auditLog = config.audit_log ?? false;
244
253
  this.onAudit = config.on_audit;
254
+ this._tier = config.tier ?? "free";
255
+ const now = /* @__PURE__ */ new Date();
256
+ this._usage.monthKey = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}`;
257
+ }
258
+ /** Set the current tier (e.g., after API key verification) */
259
+ setTier(tier) {
260
+ this._tier = tier;
261
+ }
262
+ /** Get current tier */
263
+ get tier() {
264
+ return this._tier;
265
+ }
266
+ /** Get tier limits */
267
+ get tierLimits() {
268
+ return ENGINE_TIER_LIMITS[this._tier];
269
+ }
270
+ /** Get current usage */
271
+ get usage() {
272
+ return { ...this._usage };
273
+ }
274
+ _resetMonthIfNeeded() {
275
+ const now = /* @__PURE__ */ new Date();
276
+ const mk = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}`;
277
+ if (this._usage.monthKey !== mk) {
278
+ this._usage = { evaluations: 0, irreversibleAllows: 0, monthKey: mk };
279
+ }
245
280
  }
246
281
  /**
247
282
  * Evaluate an action against the policy rules.
248
283
  * Returns a decision with verdict, risk score, and matched rules.
249
284
  */
250
285
  evaluate(request) {
286
+ this._resetMonthIfNeeded();
287
+ this._usage.evaluations++;
288
+ const evalLimit = ENGINE_TIER_LIMITS[this._tier].evaluationsPerMonth;
289
+ if (evalLimit >= 0 && this._usage.evaluations > evalLimit) {
290
+ return {
291
+ decision_id: generateDecisionId(),
292
+ verdict: "deny",
293
+ allowed: false,
294
+ requires_approval: false,
295
+ reason: `Evaluation quota exceeded (${evalLimit}/month for ${this._tier} tier). Upgrade at https://sovr.inc/pricing`,
296
+ risk_score: 0,
297
+ matched_rules: [],
298
+ risk_level: "none",
299
+ channel: request.channel,
300
+ trace_id: request.trace_id || generateTraceId(),
301
+ timestamp: Date.now()
302
+ };
303
+ }
251
304
  const traceId = request.trace_id || generateTraceId();
252
305
  const decisionId = generateDecisionId();
253
306
  const matchedRules = [];
@@ -313,6 +366,14 @@ var PolicyEngine = class {
313
366
  Promise.resolve(this.onAudit(event)).catch(() => {
314
367
  });
315
368
  }
369
+ if (this._tier === "free") {
370
+ return {
371
+ ...result,
372
+ risk_score: 0,
373
+ matched_rules: [],
374
+ reason: "[UPGRADE to Personal+ for detailed evaluation results] https://sovr.inc/pricing"
375
+ };
376
+ }
316
377
  return result;
317
378
  }
318
379
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sovr/engine",
3
- "version": "1.1.1",
3
+ "version": "2.0.0",
4
4
  "description": "Unified Policy Engine for SOVR — the single decision plane for all proxy channels",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -14,7 +14,8 @@
14
14
  },
15
15
  "files": [
16
16
  "dist",
17
- "README.md"
17
+ "README.md",
18
+ "LICENSE"
18
19
  ],
19
20
  "scripts": {
20
21
  "build": "tsup src/index.ts --format cjs,esm --dts --clean",
@@ -25,11 +26,11 @@
25
26
  "keywords": [
26
27
  "sovr",
27
28
  "policy-engine",
28
- "ai-firewall",
29
+ "ai-responsibility",
29
30
  "proxy",
30
31
  "rules-engine"
31
32
  ],
32
- "author": "SOVR Inc. <sdk@sovr.inc>",
33
+ "author": "SOVR AI <contact@sovrapp.com>",
33
34
  "license": "BSL-1.1",
34
35
  "repository": {
35
36
  "type": "git",