@orygn/opa-mcp 0.1.11 → 0.1.12
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/CHANGELOG.md +68 -1
- package/README.md +18 -17
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/lib/rego-ast-types.d.ts +81 -0
- package/dist/lib/rego-ast-types.d.ts.map +1 -0
- package/dist/lib/rego-ast-types.js +9 -0
- package/dist/lib/rego-ast-types.js.map +1 -0
- package/dist/lib/rego-ast-walker.d.ts +21 -0
- package/dist/lib/rego-ast-walker.d.ts.map +1 -0
- package/dist/lib/rego-ast-walker.js +491 -0
- package/dist/lib/rego-ast-walker.js.map +1 -0
- package/dist/lib/rego-counterexample.d.ts +32 -0
- package/dist/lib/rego-counterexample.d.ts.map +1 -0
- package/dist/lib/rego-counterexample.js +75 -0
- package/dist/lib/rego-counterexample.js.map +1 -0
- package/dist/lib/rego-ir.d.ts +117 -0
- package/dist/lib/rego-ir.d.ts.map +1 -0
- package/dist/lib/rego-ir.js +7 -0
- package/dist/lib/rego-ir.js.map +1 -0
- package/dist/lib/rego-property-parser.d.ts +34 -0
- package/dist/lib/rego-property-parser.d.ts.map +1 -0
- package/dist/lib/rego-property-parser.js +60 -0
- package/dist/lib/rego-property-parser.js.map +1 -0
- package/dist/lib/rego-smt-encoder.d.ts +57 -0
- package/dist/lib/rego-smt-encoder.d.ts.map +1 -0
- package/dist/lib/rego-smt-encoder.js +499 -0
- package/dist/lib/rego-smt-encoder.js.map +1 -0
- package/dist/lib/rego-type-inferencer.d.ts +26 -0
- package/dist/lib/rego-type-inferencer.d.ts.map +1 -0
- package/dist/lib/rego-type-inferencer.js +138 -0
- package/dist/lib/rego-type-inferencer.js.map +1 -0
- package/dist/lib/rego-verify-engine.d.ts +37 -0
- package/dist/lib/rego-verify-engine.d.ts.map +1 -0
- package/dist/lib/rego-verify-engine.js +236 -0
- package/dist/lib/rego-verify-engine.js.map +1 -0
- package/dist/lib/rego-z3.d.ts +13 -0
- package/dist/lib/rego-z3.d.ts.map +1 -0
- package/dist/lib/rego-z3.js +29 -0
- package/dist/lib/rego-z3.js.map +1 -0
- package/dist/tools/helpers/index.d.ts.map +1 -1
- package/dist/tools/helpers/index.js +2 -0
- package/dist/tools/helpers/index.js.map +1 -1
- package/dist/tools/helpers/verify.d.ts +4 -0
- package/dist/tools/helpers/verify.d.ts.map +1 -0
- package/dist/tools/helpers/verify.js +75 -0
- package/dist/tools/helpers/verify.js.map +1 -0
- package/dist/tools/index.d.ts +3 -2
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +7 -5
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Intermediate Representation produced by the AST walker and consumed by
|
|
3
|
+
* the SMT encoder. This layer insulates the encoder from OPA AST details:
|
|
4
|
+
* the walker owns all AST knowledge, the encoder owns all Z3 knowledge.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* A value that appears as an operand in a VerifyExpr.
|
|
8
|
+
*
|
|
9
|
+
* input_ref - a path like input.user.role (path = "input.user.role",
|
|
10
|
+
* segments = ["user","role"])
|
|
11
|
+
* local_var - a local variable bound by :=/= in the same clause
|
|
12
|
+
* literal_* - a constant from the policy source
|
|
13
|
+
*/
|
|
14
|
+
export type VerifyValue = {
|
|
15
|
+
kind: 'input_ref';
|
|
16
|
+
path: string;
|
|
17
|
+
segments: string[];
|
|
18
|
+
} | {
|
|
19
|
+
kind: 'local_var';
|
|
20
|
+
name: string;
|
|
21
|
+
} | {
|
|
22
|
+
kind: 'literal_string';
|
|
23
|
+
value: string;
|
|
24
|
+
} | {
|
|
25
|
+
kind: 'literal_number';
|
|
26
|
+
value: number;
|
|
27
|
+
} | {
|
|
28
|
+
kind: 'literal_bool';
|
|
29
|
+
value: boolean;
|
|
30
|
+
} | {
|
|
31
|
+
kind: 'literal_null';
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* A single verifiable expression derived from a rule body expression.
|
|
35
|
+
*
|
|
36
|
+
* All supported operator semantics map cleanly to Z3. The 'unsupported'
|
|
37
|
+
* variant is included so the walker can pass through the reason; the
|
|
38
|
+
* engine treats any clause containing it as inconclusive.
|
|
39
|
+
*/
|
|
40
|
+
export type VerifyExpr = {
|
|
41
|
+
kind: 'eq';
|
|
42
|
+
left: VerifyValue;
|
|
43
|
+
right: VerifyValue;
|
|
44
|
+
} | {
|
|
45
|
+
kind: 'neq';
|
|
46
|
+
left: VerifyValue;
|
|
47
|
+
right: VerifyValue;
|
|
48
|
+
} | {
|
|
49
|
+
kind: 'lt';
|
|
50
|
+
left: VerifyValue;
|
|
51
|
+
right: VerifyValue;
|
|
52
|
+
} | {
|
|
53
|
+
kind: 'lte';
|
|
54
|
+
left: VerifyValue;
|
|
55
|
+
right: VerifyValue;
|
|
56
|
+
} | {
|
|
57
|
+
kind: 'gt';
|
|
58
|
+
left: VerifyValue;
|
|
59
|
+
right: VerifyValue;
|
|
60
|
+
} | {
|
|
61
|
+
kind: 'gte';
|
|
62
|
+
left: VerifyValue;
|
|
63
|
+
right: VerifyValue;
|
|
64
|
+
} | {
|
|
65
|
+
kind: 'startswith';
|
|
66
|
+
str: VerifyValue;
|
|
67
|
+
prefix: VerifyValue;
|
|
68
|
+
} | {
|
|
69
|
+
kind: 'endswith';
|
|
70
|
+
str: VerifyValue;
|
|
71
|
+
suffix: VerifyValue;
|
|
72
|
+
} | {
|
|
73
|
+
kind: 'contains';
|
|
74
|
+
str: VerifyValue;
|
|
75
|
+
sub: VerifyValue;
|
|
76
|
+
} | {
|
|
77
|
+
kind: 'regex_match';
|
|
78
|
+
pattern: VerifyValue;
|
|
79
|
+
str: VerifyValue;
|
|
80
|
+
} | {
|
|
81
|
+
kind: 'bool_check';
|
|
82
|
+
ref: VerifyValue;
|
|
83
|
+
} | {
|
|
84
|
+
kind: 'assign';
|
|
85
|
+
local: string;
|
|
86
|
+
value: VerifyValue;
|
|
87
|
+
} | {
|
|
88
|
+
kind: 'unsupported';
|
|
89
|
+
constructType: string;
|
|
90
|
+
reason: string;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* One clause of a rule -- corresponds to one `rule { body... }` block.
|
|
94
|
+
* Multiple clauses for the same rule name are OR'd together.
|
|
95
|
+
* Expressions within one clause are AND'd together.
|
|
96
|
+
*/
|
|
97
|
+
export interface VerifyRuleClause {
|
|
98
|
+
clauseIndex: number;
|
|
99
|
+
headValue: boolean | number | string | null;
|
|
100
|
+
expressions: VerifyExpr[];
|
|
101
|
+
}
|
|
102
|
+
export interface UnsupportedConstruct {
|
|
103
|
+
constructType: string;
|
|
104
|
+
description: string;
|
|
105
|
+
location?: {
|
|
106
|
+
row: number;
|
|
107
|
+
col: number;
|
|
108
|
+
file?: string;
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
export interface VerifyWalkResult {
|
|
112
|
+
rules: Map<string, VerifyRuleClause[]>;
|
|
113
|
+
defaults: Map<string, boolean | number | string | null>;
|
|
114
|
+
inputPaths: Map<string, string[]>;
|
|
115
|
+
unsupported: UnsupportedConstruct[];
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=rego-ir.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rego-ir.d.ts","sourceRoot":"","sources":["../../src/lib/rego-ir.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,GACvD;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA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;IAAC,GAAG,EAAE,WAAW,CAAA;CAAE,GAC/D;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,GAAG,EAAE,WAAW,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,WAAW,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnE;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC5C,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACxD;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,gBAAgB,EAAE,CAAC,CAAC;IACvC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC,CAAC;IACxD,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAClC,WAAW,EAAE,oBAAoB,EAAE,CAAC;CACrC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Intermediate Representation produced by the AST walker and consumed by
|
|
3
|
+
* the SMT encoder. This layer insulates the encoder from OPA AST details:
|
|
4
|
+
* the walker owns all AST knowledge, the encoder owns all Z3 knowledge.
|
|
5
|
+
*/
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=rego-ir.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rego-ir.js","sourceRoot":"","sources":["../../src/lib/rego-ir.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse and validate user-supplied verification property specs.
|
|
3
|
+
*
|
|
4
|
+
* The property spec drives what the SMT engine proves:
|
|
5
|
+
* always_true - rule evaluates to true for EVERY possible input
|
|
6
|
+
* (engine finds inputs where rule is false, expects UNSAT)
|
|
7
|
+
* never_true - rule is never true for any input
|
|
8
|
+
* (engine finds inputs where rule is true, expects UNSAT)
|
|
9
|
+
* satisfiable - at least one input exists that makes rule true
|
|
10
|
+
* (engine checks SAT directly, any model is a witness)
|
|
11
|
+
*/
|
|
12
|
+
export type PropertyKind = 'always_true' | 'never_true' | 'satisfiable';
|
|
13
|
+
export interface VerifyProperty {
|
|
14
|
+
ruleName: string;
|
|
15
|
+
kind: PropertyKind;
|
|
16
|
+
}
|
|
17
|
+
export interface PropertyParseError {
|
|
18
|
+
field: string;
|
|
19
|
+
message: string;
|
|
20
|
+
}
|
|
21
|
+
export interface PropertyParseResult {
|
|
22
|
+
property: VerifyProperty | null;
|
|
23
|
+
errors: PropertyParseError[];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Parse a raw property object from MCP tool input.
|
|
27
|
+
* Returns errors array (non-empty = invalid).
|
|
28
|
+
*/
|
|
29
|
+
export declare function parseProperty(raw: unknown): PropertyParseResult;
|
|
30
|
+
/**
|
|
31
|
+
* Human-readable description of a property for use in result messages.
|
|
32
|
+
*/
|
|
33
|
+
export declare function describeProperty(property: VerifyProperty): string;
|
|
34
|
+
//# sourceMappingURL=rego-property-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rego-property-parser.d.ts","sourceRoot":"","sources":["../../src/lib/rego-property-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,MAAM,YAAY,GAAG,aAAa,GAAG,YAAY,GAAG,aAAa,CAAC;AAExE,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,YAAY,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,cAAc,GAAG,IAAI,CAAC;IAChC,MAAM,EAAE,kBAAkB,EAAE,CAAC;CAC9B;AAID;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,mBAAmB,CAmC/D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,CASjE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse and validate user-supplied verification property specs.
|
|
3
|
+
*
|
|
4
|
+
* The property spec drives what the SMT engine proves:
|
|
5
|
+
* always_true - rule evaluates to true for EVERY possible input
|
|
6
|
+
* (engine finds inputs where rule is false, expects UNSAT)
|
|
7
|
+
* never_true - rule is never true for any input
|
|
8
|
+
* (engine finds inputs where rule is true, expects UNSAT)
|
|
9
|
+
* satisfiable - at least one input exists that makes rule true
|
|
10
|
+
* (engine checks SAT directly, any model is a witness)
|
|
11
|
+
*/
|
|
12
|
+
const VALID_KINDS = new Set(['always_true', 'never_true', 'satisfiable']);
|
|
13
|
+
/**
|
|
14
|
+
* Parse a raw property object from MCP tool input.
|
|
15
|
+
* Returns errors array (non-empty = invalid).
|
|
16
|
+
*/
|
|
17
|
+
export function parseProperty(raw) {
|
|
18
|
+
const errors = [];
|
|
19
|
+
if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
20
|
+
errors.push({ field: 'property', message: 'Must be an object with "rule" and "kind" fields.' });
|
|
21
|
+
return { property: null, errors };
|
|
22
|
+
}
|
|
23
|
+
const obj = raw;
|
|
24
|
+
if (typeof obj['rule'] !== 'string' || obj['rule'].trim() === '') {
|
|
25
|
+
errors.push({
|
|
26
|
+
field: 'rule',
|
|
27
|
+
message: 'Must be a non-empty string naming the Rego rule to verify.',
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (typeof obj['kind'] !== 'string' || !VALID_KINDS.has(obj['kind'])) {
|
|
31
|
+
errors.push({
|
|
32
|
+
field: 'kind',
|
|
33
|
+
message: `Must be one of: ${[...VALID_KINDS].join(', ')}.`,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (errors.length > 0) {
|
|
37
|
+
return { property: null, errors };
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
property: {
|
|
41
|
+
ruleName: obj['rule'].trim(),
|
|
42
|
+
kind: obj['kind'],
|
|
43
|
+
},
|
|
44
|
+
errors: [],
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Human-readable description of a property for use in result messages.
|
|
49
|
+
*/
|
|
50
|
+
export function describeProperty(property) {
|
|
51
|
+
switch (property.kind) {
|
|
52
|
+
case 'always_true':
|
|
53
|
+
return `"${property.ruleName}" is true for all possible inputs`;
|
|
54
|
+
case 'never_true':
|
|
55
|
+
return `"${property.ruleName}" is never true (always false/undefined) for any input`;
|
|
56
|
+
case 'satisfiable':
|
|
57
|
+
return `"${property.ruleName}" is true for at least one input`;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=rego-property-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rego-property-parser.js","sourceRoot":"","sources":["../../src/lib/rego-property-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAmBH,MAAM,WAAW,GAAG,IAAI,GAAG,CAAe,CAAC,aAAa,EAAE,YAAY,EAAE,aAAa,CAA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MAAM,EAAE,EAAE;KACX,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAwB;IACvD,QAAQ,QAAQ,CAAC,IAAI,EAAE,CAAC;QACtB,KAAK,aAAa;YAChB,OAAO,IAAI,QAAQ,CAAC,QAAQ,mCAAmC,CAAC;QAClE,KAAK,YAAY;YACf,OAAO,IAAI,QAAQ,CAAC,QAAQ,wDAAwD,CAAC;QACvF,KAAK,aAAa;YAChB,OAAO,IAAI,QAAQ,CAAC,QAAQ,kCAAkC,CAAC;IACnE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SMT encoder: translates a VerifyWalkResult into Z3 formulas.
|
|
3
|
+
*
|
|
4
|
+
* The encoder knows Z3 API details but knows nothing about OPA AST.
|
|
5
|
+
* It receives typed IR from the walker and produces Z3 Bool expressions.
|
|
6
|
+
*
|
|
7
|
+
* Design:
|
|
8
|
+
* - One Z3 constant per input path, typed by the type inferencer.
|
|
9
|
+
* - One Z3 constant per local variable, scoped per clause.
|
|
10
|
+
* - Each clause body becomes an AND of its expression formulas.
|
|
11
|
+
* - The full rule formula is an OR of all its clause formulas.
|
|
12
|
+
* - Uninterpreted sorts get a dedicated Z3 uninterpreted sort and
|
|
13
|
+
* can only participate in equality/inequality constraints.
|
|
14
|
+
*/
|
|
15
|
+
import type { init as Z3Init } from 'z3-solver';
|
|
16
|
+
import type { Z3Sort } from './rego-type-inferencer.js';
|
|
17
|
+
import type { VerifyRuleClause } from './rego-ir.js';
|
|
18
|
+
type Z3Context = ReturnType<Awaited<ReturnType<typeof Z3Init>>['Context']>;
|
|
19
|
+
type Z3Bool = ReturnType<Z3Context['Bool']['const']>;
|
|
20
|
+
type Z3AnyExpr = Z3Bool | ReturnType<Z3Context['Int']['const']> | ReturnType<Z3Context['String']['const']>;
|
|
21
|
+
export interface EncoderContext {
|
|
22
|
+
Z3: Z3Context;
|
|
23
|
+
inputVars: Map<string, Z3AnyExpr>;
|
|
24
|
+
sorts: Map<string, Z3Sort>;
|
|
25
|
+
/** Per-call unique prefix for all Z3 constant names. Prevents sort conflicts
|
|
26
|
+
* when the same input path is inferred as different sorts across calls in the
|
|
27
|
+
* same Z3 singleton context (e.g. one policy treats input.x as string, another
|
|
28
|
+
* as int). Each call gets a fresh prefix so constants never collide. */
|
|
29
|
+
callId: string;
|
|
30
|
+
}
|
|
31
|
+
export interface EncodedRule {
|
|
32
|
+
formula: Z3Bool;
|
|
33
|
+
warnings: string[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Create Z3 constants for all input paths based on inferred sorts.
|
|
37
|
+
* Each constant name is prefixed with callId to ensure uniqueness across
|
|
38
|
+
* verification calls in the same Z3 singleton context.
|
|
39
|
+
*/
|
|
40
|
+
export declare function createInputVars(Z3: Z3Context, inputPaths: Map<string, string[]>, sorts: Map<string, Z3Sort>, callId: string): Map<string, Z3AnyExpr>;
|
|
41
|
+
/**
|
|
42
|
+
* Encode a complete rule as a Z3 Bool formula.
|
|
43
|
+
* rule_formula = clause_0 OR clause_1 OR ... OR clause_n
|
|
44
|
+
*/
|
|
45
|
+
export declare function encodeRule(clauses: VerifyRuleClause[], ctx: EncoderContext): EncodedRule;
|
|
46
|
+
/** Convert an input path like "input.user.role" to a valid Z3 var name. */
|
|
47
|
+
export declare function pathToVarName(path: string): string;
|
|
48
|
+
/** Reconstruct a nested JSON object from flat Z3 var name → value pairs. */
|
|
49
|
+
export declare function varNameToPath(varName: string): string;
|
|
50
|
+
type Z3Re = ReturnType<Z3Context['Re']['toRe']>;
|
|
51
|
+
/**
|
|
52
|
+
* Compile a PCRE/RE2 pattern string to a Z3 regex expression.
|
|
53
|
+
* Falls back to exact literal match for unrecognized constructs.
|
|
54
|
+
*/
|
|
55
|
+
export declare function compilePcreToZ3Re(Z3: Z3Context, pattern: string): Z3Re;
|
|
56
|
+
export {};
|
|
57
|
+
//# sourceMappingURL=rego-smt-encoder.d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