veritool 1.0.0__tar.gz

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.
Files changed (48) hide show
  1. veritool-1.0.0/LICENSE +201 -0
  2. veritool-1.0.0/PKG-INFO +144 -0
  3. veritool-1.0.0/README.md +120 -0
  4. veritool-1.0.0/bridge/__init__.py +41 -0
  5. veritool-1.0.0/bridge/policy_spec.py +43 -0
  6. veritool-1.0.0/bridge/z3_encoder.py +205 -0
  7. veritool-1.0.0/cli/__init__.py +184 -0
  8. veritool-1.0.0/cli/auto_generator.py +561 -0
  9. veritool-1.0.0/cli/round_trip.py +106 -0
  10. veritool-1.0.0/dashboard/__init__.py +0 -0
  11. veritool-1.0.0/dashboard/app.py +77 -0
  12. veritool-1.0.0/integrations/__init__.py +5 -0
  13. veritool-1.0.0/integrations/autogen.py +65 -0
  14. veritool-1.0.0/integrations/crewai.py +47 -0
  15. veritool-1.0.0/integrations/langchain.py +32 -0
  16. veritool-1.0.0/llm/__init__.py +0 -0
  17. veritool-1.0.0/llm/groq_client.py +117 -0
  18. veritool-1.0.0/llm/prompts.py +40 -0
  19. veritool-1.0.0/policy_store/__init__.py +3 -0
  20. veritool-1.0.0/policy_store/audit.py +77 -0
  21. veritool-1.0.0/policy_store/store.py +120 -0
  22. veritool-1.0.0/pyproject.toml +47 -0
  23. veritool-1.0.0/setup.cfg +4 -0
  24. veritool-1.0.0/tests/test_audit.py +104 -0
  25. veritool-1.0.0/tests/test_auto_generator.py +156 -0
  26. veritool-1.0.0/tests/test_bridge.py +92 -0
  27. veritool-1.0.0/tests/test_coordination.py +137 -0
  28. veritool-1.0.0/tests/test_deletion.py +110 -0
  29. veritool-1.0.0/tests/test_e2e.py +82 -0
  30. veritool-1.0.0/tests/test_groq_client.py +102 -0
  31. veritool-1.0.0/tests/test_integration.py +65 -0
  32. veritool-1.0.0/tests/test_integrations.py +127 -0
  33. veritool-1.0.0/tests/test_orchestrator.py +75 -0
  34. veritool-1.0.0/tests/test_policy_store.py +100 -0
  35. veritool-1.0.0/tests/test_schema.py +69 -0
  36. veritool-1.0.0/tests/test_tahoe.py +121 -0
  37. veritool-1.0.0/verifier/__init__.py +0 -0
  38. veritool-1.0.0/verifier/coordination_policy.py +174 -0
  39. veritool-1.0.0/verifier/deletion_policy.py +38 -0
  40. veritool-1.0.0/verifier/schema.py +121 -0
  41. veritool-1.0.0/verifier/tahoe_policy.py +40 -0
  42. veritool-1.0.0/verifier/verifier.py +50 -0
  43. veritool-1.0.0/veritool.egg-info/PKG-INFO +144 -0
  44. veritool-1.0.0/veritool.egg-info/SOURCES.txt +46 -0
  45. veritool-1.0.0/veritool.egg-info/dependency_links.txt +1 -0
  46. veritool-1.0.0/veritool.egg-info/entry_points.txt +2 -0
  47. veritool-1.0.0/veritool.egg-info/requires.txt +17 -0
  48. veritool-1.0.0/veritool.egg-info/top_level.txt +7 -0
veritool-1.0.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by
174
+ reason of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [2026] [Pranav-d33]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,144 @@
1
+ Metadata-Version: 2.4
2
+ Name: veritool
3
+ Version: 1.0.0
4
+ Summary: Formal verification framework for LLM tool-calling. Z3 + Lean 4.
5
+ License-Expression: Apache-2.0
6
+ Project-URL: Homepage, https://github.com/Pranav-d33/z3-lean-4-static-verifier-for-LLM-tool-calling
7
+ Requires-Python: >=3.11
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: z3-solver>=4.13
11
+ Provides-Extra: groq
12
+ Requires-Dist: groq>=0.12; extra == "groq"
13
+ Provides-Extra: dashboard
14
+ Requires-Dist: streamlit>=1.28; extra == "dashboard"
15
+ Requires-Dist: pandas>=2.0; extra == "dashboard"
16
+ Provides-Extra: dev
17
+ Requires-Dist: pytest>=8; extra == "dev"
18
+ Requires-Dist: pyfakefs>=6; extra == "dev"
19
+ Requires-Dist: veritool[groq]; extra == "dev"
20
+ Requires-Dist: veritool[dashboard]; extra == "dev"
21
+ Provides-Extra: all
22
+ Requires-Dist: veritool[dev]; extra == "all"
23
+ Dynamic: license-file
24
+
25
+ # VeriTool
26
+
27
+ Formal verification framework for LLM tool-calling. Z3 + Lean 4.
28
+
29
+ ```
30
+ LLM → Interceptor → Z3 Policy Check → UNSAT = permit | SAT = block + counterexample
31
+
32
+ Auto-generator — NL descriptions → formal specs (Lean + Z3)
33
+ ```
34
+
35
+ ## Quick Install
36
+
37
+ ```bash
38
+ pip install z3-solver pytest
39
+ pip install -e ".[all]" # includes dashboard, pandas, streamlit
40
+ lean --version && lean Lean/Policy.lean
41
+ veritool --help
42
+ ```
43
+
44
+ ## CLI Usage
45
+
46
+ ```
47
+ veritool create "no file named payroll.csv may be deleted" # NL → formal policy
48
+ veritool check tahoe --model Tahoe --price 45000 # decision for a case
49
+ veritool test tahoe # run round-trip test matrix
50
+ veritool run Tahoe 40000 --verbose # unified check+explain
51
+ veritool status # active policies summary
52
+ veritool hot-reload # reload without restart
53
+ veritool rollback tahoe # undo last revision
54
+ veritool verify all # full round-trip sweep
55
+ veritool dashboard # launch Streamlit UI
56
+ veritool wrap "def fn(**kw): ..." --tool-name submit_order # wrap function as tool
57
+ ```
58
+
59
+ ## Demo
60
+
61
+ ```bash
62
+ python demo_tahoe.py # price floor checks
63
+ python demo_deletion.py # file scope checks
64
+ ```
65
+
66
+ ## Supported Policy Types
67
+
68
+ | Type | Description | Example Violation |
69
+ |---|---|---|
70
+ | `price_floor` | Minimum price per item | `price < floor_price(model)` |
71
+ | `file_access` / `deletion` | Allowed file scope | `¬in_scope(target)` |
72
+ | `sql_safety` | Allowed query patterns | `¬allowed_query_pattern(query)` |
73
+ | `rate_limit` | Max calls per API key | `current_count ≥ max_per_minute(key)` |
74
+ | `role_hours` | Admin action time windows | `role=admin ∧ hour > 22` |
75
+ | `api_access` | Endpoint allowlist | `¬endpoint_allowed(path)` |
76
+ | `generic` | Custom constraints | user-defined |
77
+
78
+ ## Multi-Agent Coordination
79
+
80
+ ```python
81
+ from verifier.coordination_policy import CoordinationVerifier, Invariant
82
+
83
+ verifier = CoordinationVerifier()
84
+ verifier.add_invariant("seq", Invariant.SEQUENTIAL_ACCESS, resource="db")
85
+ verifier.add_invariant("lock", Invariant.LOCK_REQUIRED, resource="db")
86
+ ```
87
+
88
+ Supported invariants: `SEQUENTIAL_ACCESS`, `LOCK_REQUIRED`, `APPROVAL_REQUIRED`, `MONOTONIC_ACCESS`, `ROLE_BASED_ACCESS`.
89
+
90
+ ## LLM Integration
91
+
92
+ ```python
93
+ from integrations.langchain_interceptor import LangChainVerifier
94
+ from integrations.crewaI_guard import CrewAIVerifier
95
+ from integrations.autogen_middleware import AutoGenMiddleware
96
+ ```
97
+
98
+ All three wrappers intercept tool calls and block violations before runtime.
99
+
100
+ ## Tests
101
+
102
+ ```bash
103
+ make test # all tests
104
+ make test-fast # stop at first failure
105
+ make verify # Lean theorem compilation check
106
+ make dashboard # Streamlit monitoring UI
107
+ ```
108
+
109
+ 183 tests covering all modules.
110
+
111
+ ## Project Structure
112
+
113
+ ```
114
+ ├── cli/ # CLI commands + auto-generator + round-trip
115
+ ├── bridge/ # PolicySpec type system + Z3 encoder
116
+ ├── verifier/ # Policy checkers + coordination verifier
117
+ ├── policy_store/ # Versioned store + audit trail
118
+ ├── dashboard/ # Streamlit monitoring UI
119
+ ├── integrations/ # LangChain, CrewAI, AutoGen wrappers
120
+ ├── Lean/Policy.lean # Ground-truth theorems
121
+ ├── Makefile # test, verify, demo, dashboard targets
122
+ └── tests/ # 183 tests — run with `make test`
123
+ ```
124
+
125
+ ## Fail-Closed Design
126
+
127
+ Unknown inputs are rejected at every layer:
128
+
129
+ | Layer | Unknown Behavior |
130
+ |---|---|
131
+ | Schema validation | Rejected — out-of-enum |
132
+ | Z3 policy check | Rejected — ForAll default-false |
133
+ | Lean theorem | Unprovable — `Option Nat` returns `none` |
134
+ | Coordination verifier | Rejected — unregistered agents |
135
+
136
+ ## Architecture
137
+
138
+ ```
139
+ LLM output → Interceptor → Schema validation → Z3 check → Coordinator → [block/permit]
140
+
141
+ Policy Store (versioned)
142
+
143
+ Audit Trail (JSONL)
144
+ ```
@@ -0,0 +1,120 @@
1
+ # VeriTool
2
+
3
+ Formal verification framework for LLM tool-calling. Z3 + Lean 4.
4
+
5
+ ```
6
+ LLM → Interceptor → Z3 Policy Check → UNSAT = permit | SAT = block + counterexample
7
+
8
+ Auto-generator — NL descriptions → formal specs (Lean + Z3)
9
+ ```
10
+
11
+ ## Quick Install
12
+
13
+ ```bash
14
+ pip install z3-solver pytest
15
+ pip install -e ".[all]" # includes dashboard, pandas, streamlit
16
+ lean --version && lean Lean/Policy.lean
17
+ veritool --help
18
+ ```
19
+
20
+ ## CLI Usage
21
+
22
+ ```
23
+ veritool create "no file named payroll.csv may be deleted" # NL → formal policy
24
+ veritool check tahoe --model Tahoe --price 45000 # decision for a case
25
+ veritool test tahoe # run round-trip test matrix
26
+ veritool run Tahoe 40000 --verbose # unified check+explain
27
+ veritool status # active policies summary
28
+ veritool hot-reload # reload without restart
29
+ veritool rollback tahoe # undo last revision
30
+ veritool verify all # full round-trip sweep
31
+ veritool dashboard # launch Streamlit UI
32
+ veritool wrap "def fn(**kw): ..." --tool-name submit_order # wrap function as tool
33
+ ```
34
+
35
+ ## Demo
36
+
37
+ ```bash
38
+ python demo_tahoe.py # price floor checks
39
+ python demo_deletion.py # file scope checks
40
+ ```
41
+
42
+ ## Supported Policy Types
43
+
44
+ | Type | Description | Example Violation |
45
+ |---|---|---|
46
+ | `price_floor` | Minimum price per item | `price < floor_price(model)` |
47
+ | `file_access` / `deletion` | Allowed file scope | `¬in_scope(target)` |
48
+ | `sql_safety` | Allowed query patterns | `¬allowed_query_pattern(query)` |
49
+ | `rate_limit` | Max calls per API key | `current_count ≥ max_per_minute(key)` |
50
+ | `role_hours` | Admin action time windows | `role=admin ∧ hour > 22` |
51
+ | `api_access` | Endpoint allowlist | `¬endpoint_allowed(path)` |
52
+ | `generic` | Custom constraints | user-defined |
53
+
54
+ ## Multi-Agent Coordination
55
+
56
+ ```python
57
+ from verifier.coordination_policy import CoordinationVerifier, Invariant
58
+
59
+ verifier = CoordinationVerifier()
60
+ verifier.add_invariant("seq", Invariant.SEQUENTIAL_ACCESS, resource="db")
61
+ verifier.add_invariant("lock", Invariant.LOCK_REQUIRED, resource="db")
62
+ ```
63
+
64
+ Supported invariants: `SEQUENTIAL_ACCESS`, `LOCK_REQUIRED`, `APPROVAL_REQUIRED`, `MONOTONIC_ACCESS`, `ROLE_BASED_ACCESS`.
65
+
66
+ ## LLM Integration
67
+
68
+ ```python
69
+ from integrations.langchain_interceptor import LangChainVerifier
70
+ from integrations.crewaI_guard import CrewAIVerifier
71
+ from integrations.autogen_middleware import AutoGenMiddleware
72
+ ```
73
+
74
+ All three wrappers intercept tool calls and block violations before runtime.
75
+
76
+ ## Tests
77
+
78
+ ```bash
79
+ make test # all tests
80
+ make test-fast # stop at first failure
81
+ make verify # Lean theorem compilation check
82
+ make dashboard # Streamlit monitoring UI
83
+ ```
84
+
85
+ 183 tests covering all modules.
86
+
87
+ ## Project Structure
88
+
89
+ ```
90
+ ├── cli/ # CLI commands + auto-generator + round-trip
91
+ ├── bridge/ # PolicySpec type system + Z3 encoder
92
+ ├── verifier/ # Policy checkers + coordination verifier
93
+ ├── policy_store/ # Versioned store + audit trail
94
+ ├── dashboard/ # Streamlit monitoring UI
95
+ ├── integrations/ # LangChain, CrewAI, AutoGen wrappers
96
+ ├── Lean/Policy.lean # Ground-truth theorems
97
+ ├── Makefile # test, verify, demo, dashboard targets
98
+ └── tests/ # 183 tests — run with `make test`
99
+ ```
100
+
101
+ ## Fail-Closed Design
102
+
103
+ Unknown inputs are rejected at every layer:
104
+
105
+ | Layer | Unknown Behavior |
106
+ |---|---|
107
+ | Schema validation | Rejected — out-of-enum |
108
+ | Z3 policy check | Rejected — ForAll default-false |
109
+ | Lean theorem | Unprovable — `Option Nat` returns `none` |
110
+ | Coordination verifier | Rejected — unregistered agents |
111
+
112
+ ## Architecture
113
+
114
+ ```
115
+ LLM output → Interceptor → Schema validation → Z3 check → Coordinator → [block/permit]
116
+
117
+ Policy Store (versioned)
118
+
119
+ Audit Trail (JSONL)
120
+ ```
@@ -0,0 +1,41 @@
1
+ from bridge.policy_spec import PolicySpec, NatType, StringType, FinsetType, FunctionDef, BridgeError
2
+ from bridge.z3_encoder import check_policy, compile_policy
3
+
4
+ TAHOE_SPEC = PolicySpec(
5
+ name="tahoe",
6
+ _policy_type="tahoe",
7
+ params={"model": StringType, "price": NatType},
8
+ functions=[
9
+ FunctionDef("floor_price", StringType, NatType,
10
+ mapping={"Tahoe": 45000, "Malibu": 25000}, default=0),
11
+ ],
12
+ violation_expr="price < floor_price(model)",
13
+ description="Tahoe/Malibu minimum price policy",
14
+ )
15
+
16
+ DELETION_SPEC = PolicySpec(
17
+ name="deletion",
18
+ _policy_type="deletion",
19
+ params={"target": StringType},
20
+ violation_expr="Not(in_scope(target))",
21
+ _allowed_scope=["/project/temp", "/project/output"],
22
+ description="File deletion frame policy requiring target in allowed scope",
23
+ )
24
+
25
+
26
+ def bridge_check(policy_name: str, params: dict | None = None, timeout_ms: int = 5000) -> dict:
27
+ spec_map = {
28
+ "tahoe": TAHOE_SPEC,
29
+ "deletion": DELETION_SPEC,
30
+ }
31
+ spec = spec_map.get(policy_name)
32
+ if spec is None:
33
+ return {"status": "error", "reason": f"Unknown policy: {policy_name}"}
34
+ return check_policy(spec, params=params, timeout_ms=timeout_ms)
35
+
36
+
37
+ __all__ = [
38
+ "PolicySpec", "NatType", "StringType", "FinsetType", "FunctionDef", "BridgeError",
39
+ "check_policy", "compile_policy",
40
+ "TAHOE_SPEC", "DELETION_SPEC", "bridge_check",
41
+ ]
@@ -0,0 +1,43 @@
1
+ from dataclasses import dataclass, field
2
+ from typing import Any
3
+
4
+
5
+ class BridgeError(Exception):
6
+ pass
7
+
8
+
9
+ @dataclass(frozen=True)
10
+ class TypeSpec:
11
+ name: str
12
+
13
+
14
+ NatType = TypeSpec("Nat")
15
+ StringType = TypeSpec("String")
16
+ BoolType = TypeSpec("Bool")
17
+
18
+
19
+ @dataclass(frozen=True)
20
+ class FinsetType:
21
+ elem_type: TypeSpec
22
+
23
+
24
+ @dataclass(frozen=True)
25
+ class FunctionDef:
26
+ name: str
27
+ arg_type: TypeSpec
28
+ return_type: TypeSpec
29
+ mapping: dict[str, Any] = field(default_factory=dict)
30
+ default: Any = 0
31
+
32
+
33
+ @dataclass(frozen=True)
34
+ class PolicySpec:
35
+ name: str
36
+ params: dict[str, TypeSpec] = field(default_factory=dict)
37
+ functions: list[FunctionDef] = field(default_factory=list)
38
+ violation_expr: str = ""
39
+ description: str = ""
40
+ _tool_name: str = ""
41
+ _allowed_scope: list[str] = field(default_factory=list)
42
+ _param_name: str = "value"
43
+ _policy_type: str = "generic"