jevguard-core 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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 seb4ez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,293 @@
1
+ Metadata-Version: 2.4
2
+ Name: jevguard-core
3
+ Version: 1.0.0
4
+ Summary: Deterministic decision runtime, zero-token caching, and certainty calibrator for TypeSafe AI (Jev).
5
+ Author: seb4ez
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/seb4ez/jevguard
8
+ Project-URL: Repository, https://github.com/seb4ez/jevguard.git
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
+ Requires-Python: >=3.9
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Dynamic: license-file
22
+
23
+ # JevGuard: Deterministic Caching and Guardrails for TypeSafe AI (Jev)
24
+
25
+ [![MCP Server](https://img.shields.io/badge/MCP_Server-jevguard--mcp-blue.svg)](https://github.com/seb4ez/jevguard-mcp)
26
+ [![Python 3.9+](https://img.shields.io/badge/Python-3.9+-brightgreen.svg)](https://www.python.org/)
27
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
28
+
29
+ > **Official Model Context Protocol (MCP) Server:** JevGuard includes an official, zero-dependency MCP server designed for autonomous AI agents in Google Antigravity, Cursor IDE, Claude Desktop, and Cline: **[seb4ez/jevguard-mcp](https://github.com/seb4ez/jevguard-mcp)**.
30
+
31
+ JevGuard is an open-source Python library that provides local deterministic caching, state pruning, neutral escape injection, and calibration guardrails around TypeSafe AI's System One decision model. While upstream decision engines produce probabilistic outputs, JevGuard provides a strictly deterministic local layer: canonical JSON sorting, SHA-256 fingerprinting with volatile key masking, SQLite storage, and rule-based calibration checks using only the Python standard library.
32
+
33
+ ## Upstream Latency and Cache Performance (50 Live Verification Requests)
34
+
35
+ The following benchmark report reflects 50 complete test requests executed against the official TypeSafe AI endpoint (`https://api.typesafe.ai/v1/systemone` using model `jev-latest`) from a development workstation. Latency comparisons contrast WAN roundtrips against local in-memory/SQLite cache lookups:
36
+
37
+ ![JevGuard Benchmark Results](benchmark_results.png)
38
+
39
+ | Key Metric | Direct Upstream API | JevGuard Runtime | Empirical Advantage |
40
+ | :--- | :--- | :--- | :--- |
41
+ | **Verification Requests** | 50 live calls tested | 50 live calls tested | 100% transport pass rate across 5 test scenarios |
42
+ | **Average Network Latency** | 784.53 ms | 735.88 ms (pruned) | State pruning reduces wire payload size |
43
+ | **Deterministic Cache Hit** | 763.40 ms (144 tokens charged) | **0.099 ms** (**0 tokens**) | **Sub-millisecond retrieval (0.099 ms vs 763 ms WAN roundtrip); 0 tokens billed** |
44
+ | **Out-of-Scope Protection** | Forced False Positive (`chargeback`) | `UNRESOLVED_OR_OTHER` | Neutral escape injection catches off-topic inputs |
45
+ | **Uncertainty Calibration** | Raw unverified probabilities | `AMBIGUOUS_STATE` alert | Flags bimodal ties and low certainty |
46
+ | **Local Runtime Overhead** | 0 ms | **0.024 ms** | Sub-millisecond execution using pure Python stdlib |
47
+
48
+ ## Why JevGuard
49
+
50
+ TypeSafe AI's Jev model produces sub-second probabilistic evaluations over structured state. In production workflows, raw calls encounter three practical challenges:
51
+
52
+ 1. **Closed-World False Positives**: When categorical choice criteria lack a neutral fallback, the model distributes all probability across defined options. If an unhandled or off-topic input arrives, the model selects the closest available option.
53
+ 2. **Uncalibrated Ambiguity**: When inputs contain conflicting signals, probability distributions flatten. Selecting the top option without checking the runner-up margin leads to decisions made on low confidence.
54
+ 3. **Repeated Query Cost and Cache Misses**: Identical state checks inside agent loops consume network latency and token budgets. If payloads contain dynamic timestamps or request IDs, standard caches miss on every call.
55
+
56
+ ## Features
57
+
58
+ - **Closed-World Escape Injection**: Detects categorical choice rules without a fallback and injects `UNRESOLVED_OR_OTHER`. Off-topic inputs route to this escape option instead of triggering forced choices.
59
+ - **Strict Enum Support**: Set `closed_world=True` on `Choice` or `auto_inject_escapes=False` on the client when building strict enums where additional options must not be introduced.
60
+ - **Certainty and Dispersion Heuristics**: Uses configurable operational defaults (top probability below 0.40 or top-to-runner-up margin below 0.15) to flag indecisive distributions as `AMBIGUOUS_STATE`.
61
+ - **Volatile Metadata Masking**: Automatically ignores ephemeral fields (`timestamp`, `trace_id`, `request_id`, `nonce`) during SHA-256 fingerprinting, ensuring production cache hits across repeated queries.
62
+ - **Sub-Millisecond Overhead**: Pure local CPU computation runs in under 0.20 ms (198 microseconds) per evaluation.
63
+ - **Zero-Token SHA-256 Cache**: Hashes canonical sorted JSON. Identical requests return in under 1 millisecond with zero network overhead and zero token cost.
64
+ - **Concurrent Batch and Async Support**: Built-in `batch_evaluate` with thread pooling and native `async_evaluate` for `asyncio` event loops.
65
+ - **Resilient Network Retries**: Exponential backoff with jitter and `Retry-After` header parsing for HTTP 429 and 5xx server errors.
66
+ - **Episodic SQLite Memory**: Records session interaction turns with transactional serialization and builds rolling summaries without retransmitting raw history.
67
+ - **Zero Dependencies**: Pure Python 3.9+ standard library (`urllib`, `sqlite3`, `hashlib`, `json`, `threading`, `concurrent.futures`). No pip dependencies, no Node.js.
68
+
69
+ ## Installation
70
+
71
+ Install locally with pip:
72
+
73
+ ```bash
74
+ git clone https://github.com/seb4ez/jevguard.git
75
+ cd jevguard
76
+ pip install .
77
+ ```
78
+
79
+ Or copy the `jevguard` directory directly into your project.
80
+
81
+ Set your TypeSafe AI API key:
82
+
83
+ ```bash
84
+ export TYPESAFE_API_KEY="your_typesafe_api_key"
85
+ ```
86
+
87
+ On Windows PowerShell:
88
+
89
+ ```powershell
90
+ $env:TYPESAFE_API_KEY="your_typesafe_api_key"
91
+ ```
92
+
93
+ ## Quickstart
94
+
95
+ ```python
96
+ from jevguard import JevGuardClient, Noul, Score, Choice
97
+
98
+ client = JevGuardClient()
99
+
100
+ state = {
101
+ "ticket_id": "INC-4091",
102
+ "customer_message": "Our payment gateway timed out during credit card settlement.",
103
+ "account_tier": "enterprise",
104
+ "timestamp": 1726778900
105
+ }
106
+
107
+ questions = {
108
+ "is_billing": Noul(instructions="Does this ticket describe an invoice or payment issue?"),
109
+ "severity": Score(
110
+ instructions="Rate incident urgency",
111
+ criteria=["Low", "Medium", "High", "Critical"]
112
+ ),
113
+ "route": Choice(
114
+ instructions="Assign handling team",
115
+ criteria={
116
+ "database_team": "Database connection and replication issues",
117
+ "payment_support": "Gateway timeouts and transaction errors",
118
+ "frontend_ui": "CSS, rendering, and asset bundling issues"
119
+ }
120
+ )
121
+ }
122
+
123
+ response = client.evaluate(state, questions)
124
+
125
+ print(response.nouls["is_billing"].noul) # 0.96
126
+ print(response.scores["severity"].score) # 2.45
127
+ print(response.choices["route"].choice) # "payment_support"
128
+ print(response.choices["route"].status) # "CONFIDENT"
129
+ ```
130
+
131
+ ## Strict Closed-World Enums
132
+
133
+ When building strict finite-state machines where unhandled options must not be injected:
134
+
135
+ ```python
136
+ # Pass closed_world=True to prevent UNRESOLVED_OR_OTHER injection
137
+ approval_choice = Choice(
138
+ instructions="Review status",
139
+ criteria={"APPROVED": "Request accepted", "REJECTED": "Request denied"},
140
+ closed_world=True
141
+ )
142
+
143
+ resp = client.evaluate(state, {"decision": approval_choice})
144
+ ```
145
+
146
+ ## Production Caching with Volatile Metadata
147
+
148
+ JevGuard masks ephemeral fields during fingerprint computation so dynamic timestamps or trace IDs do not bust the cache:
149
+
150
+ ```python
151
+ # First call (cold)
152
+ resp1 = client.evaluate({"query": "Check balance", "timestamp": 1726778900, "trace_id": "t-1"}, questions)
153
+
154
+ # Second call 10 seconds later with new timestamp and trace_id hits local cache
155
+ resp2 = client.evaluate({"query": "Check balance", "timestamp": 1726778910, "trace_id": "t-2"}, questions)
156
+
157
+ print(resp2.cached) # True
158
+ print(resp2.telemetry["latency_total_ms"]) # 0.10 ms
159
+ print(resp2.telemetry["tokens_saved"]) # 159 tokens
160
+ ```
161
+
162
+ > Note: Volatile masking operates on structured dictionary keys (for example `{"timestamp": 123}`). If dynamic timestamps are embedded inside raw unstructured strings (for example `{"log": "2026-09-19T22:00:00Z error"}`), the SHA-256 fingerprint will change. To ensure cache hits, extract dynamic timestamps and request IDs into distinct dictionary keys in `state`.
163
+
164
+ ## Concurrent Batch and Async Execution
165
+
166
+ ```python
167
+ # Synchronous parallel batch evaluation
168
+ items = [
169
+ (state_1, questions),
170
+ (state_2, questions),
171
+ (state_3, questions)
172
+ ]
173
+ results = client.batch_evaluate(items, max_workers=5)
174
+
175
+ # Native asynchronous execution in asyncio event loops (no manual thread wrapping required)
176
+ import asyncio
177
+
178
+ async def main():
179
+ res = await client.async_evaluate(state, questions)
180
+ print(res.choices["route"].choice)
181
+
182
+ asyncio.run(main())
183
+ ```
184
+
185
+ ## Examples
186
+
187
+ Runnable demonstration scripts are included in the `examples/` directory:
188
+
189
+ ```bash
190
+ # 1. SRE Incident Triage: State pruning and multi-question evaluation
191
+ python examples/01_sre_incident_triage.py
192
+
193
+ # 2. Strict Finite State Machine: Enforcing closed_world=True with zero escapes
194
+ python examples/02_strict_finite_state_machine.py
195
+
196
+ # 3. High-Throughput Batch & Caching: Thread pool evaluation and volatile key masking
197
+ python examples/03_high_throughput_batch_caching.py
198
+ ```
199
+
200
+ ## Official Model Context Protocol (MCP) Server
201
+
202
+ JevGuard provides an official, zero-dependency MCP server for AI coding assistants (Google Antigravity, Cursor IDE, Claude Desktop, LibreChat, and Cline):
203
+
204
+ * **Repository**: **[seb4ez/jevguard-mcp](https://github.com/seb4ez/jevguard-mcp)**
205
+ * **Architecture**: 100% Python standard library over JSON-RPC 2.0 stdio with SQLite WAL concurrency and transparent `:memory:` degradation.
206
+ * **Autonomous Agent Tools**:
207
+ - `evaluate_command_safety`: Evaluates shell commands for destructive actions (`ALLOW_AUTONOMOUS`, `REQUIRE_HUMAN_APPROVAL`, `DENY_DESTRUCTIVE`).
208
+ - `verify_code_patch`: Evaluates git diffs for security regressions, broken syntax, or critical system impact under strict, balanced, or permissive risk tolerances.
209
+ - `evaluate_decision`: Evaluates architectural decisions from a list of options with automatic neutral escape injection (`UNRESOLVED_OR_OTHER`) and dispersion gap calibration.
210
+ - `jevguard_evaluate`: Low-level deterministic evaluation pipeline with state pruning and zero-token caching.
211
+ - `jevguard_calibrate`: Standalone certainty and probability dispersion calibrator (`AMBIGUOUS_STATE`).
212
+ - `jevguard_prune_state`: Sanitizes complex state payloads and collapses duplicate whitespace.
213
+ - `jevguard_cache_fingerprint`: Computes canonical SHA-256 fingerprints with volatile key masking.
214
+
215
+ ### Quick Setup for AI Coding Environments
216
+
217
+ #### Cursor IDE (`.cursor/mcp.json`)
218
+ ```json
219
+ {
220
+ "mcpServers": {
221
+ "jevguard": {
222
+ "command": "python",
223
+ "args": ["-m", "jevguard_mcp.server"],
224
+ "env": {
225
+ "TYPESAFE_API_KEY": "your_typesafe_api_key_here"
226
+ }
227
+ }
228
+ }
229
+ }
230
+ ```
231
+
232
+ #### Claude Desktop (`claude_desktop_config.json`)
233
+ ```json
234
+ {
235
+ "mcpServers": {
236
+ "jevguard": {
237
+ "command": "python",
238
+ "args": ["-m", "jevguard_mcp.server"],
239
+ "env": {
240
+ "TYPESAFE_API_KEY": "your_typesafe_api_key_here"
241
+ }
242
+ }
243
+ }
244
+ }
245
+ ```
246
+
247
+ For complete MCP server documentation, empirical benchmark reports, and installation guides, visit the dedicated repository: **[github.com/seb4ez/jevguard-mcp](https://github.com/seb4ez/jevguard-mcp)**.
248
+
249
+ ## Testing & Verification
250
+
251
+ Run the 21 formal subsystem certification tests:
252
+
253
+ ```bash
254
+ python test_suite_21.py
255
+ ```
256
+
257
+ This suite validates all 5 core subsystems under production conditions:
258
+ 1. State Pruner & Normalization (Tests 1 to 5)
259
+ 2. Closed-World Optimizer (Tests 6 to 9)
260
+ 3. Calibration & Dispersion Engine (Tests 10 to 13)
261
+ 4. Volatile Masking & Zero-Token Cache (Tests 14 to 17)
262
+ 5. Resilience, Batch & Async Transport (Tests 18 to 21)
263
+
264
+ Run the 30 comprehensive regression and concurrency tests:
265
+
266
+ ```bash
267
+ python test_jevguard.py
268
+ ```
269
+
270
+ Run the microsecond CPU latency audit:
271
+
272
+ ```bash
273
+ python benchmark.py
274
+ ```
275
+
276
+ Run the live upstream comparative test (requires `TYPESAFE_API_KEY`):
277
+
278
+ ```bash
279
+ python run_live_certification_tests.py
280
+ ```
281
+
282
+ ## Project Status and Validation Transparency
283
+
284
+ JevGuard is an independent, community-driven open-source project (v1.0.0) built strictly with the Python standard library. Initial implementation and test suites were developed iteratively using AI-assisted engineering and local unit test validation.
285
+
286
+ Key design caveats:
287
+ - The local runtime (canonicalization, hashing, state pruning, and calibration checks) is deterministic, whereas the remote TypeSafe AI / Jev service produces probabilistic classifications.
288
+ - Default calibration thresholds (such as top probability below 0.40 or margin below 0.15) represent operational heuristics for tie and uncertainty detection rather than parameters fitted on a specific domain corpus. Users can configure them according to their domain risk tolerance.
289
+ - We welcome external peer review, empirical validation on production datasets, and community contributions.
290
+
291
+ ## License
292
+
293
+ MIT License. See [LICENSE](LICENSE) for details.
@@ -0,0 +1,271 @@
1
+ # JevGuard: Deterministic Caching and Guardrails for TypeSafe AI (Jev)
2
+
3
+ [![MCP Server](https://img.shields.io/badge/MCP_Server-jevguard--mcp-blue.svg)](https://github.com/seb4ez/jevguard-mcp)
4
+ [![Python 3.9+](https://img.shields.io/badge/Python-3.9+-brightgreen.svg)](https://www.python.org/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
6
+
7
+ > **Official Model Context Protocol (MCP) Server:** JevGuard includes an official, zero-dependency MCP server designed for autonomous AI agents in Google Antigravity, Cursor IDE, Claude Desktop, and Cline: **[seb4ez/jevguard-mcp](https://github.com/seb4ez/jevguard-mcp)**.
8
+
9
+ JevGuard is an open-source Python library that provides local deterministic caching, state pruning, neutral escape injection, and calibration guardrails around TypeSafe AI's System One decision model. While upstream decision engines produce probabilistic outputs, JevGuard provides a strictly deterministic local layer: canonical JSON sorting, SHA-256 fingerprinting with volatile key masking, SQLite storage, and rule-based calibration checks using only the Python standard library.
10
+
11
+ ## Upstream Latency and Cache Performance (50 Live Verification Requests)
12
+
13
+ The following benchmark report reflects 50 complete test requests executed against the official TypeSafe AI endpoint (`https://api.typesafe.ai/v1/systemone` using model `jev-latest`) from a development workstation. Latency comparisons contrast WAN roundtrips against local in-memory/SQLite cache lookups:
14
+
15
+ ![JevGuard Benchmark Results](benchmark_results.png)
16
+
17
+ | Key Metric | Direct Upstream API | JevGuard Runtime | Empirical Advantage |
18
+ | :--- | :--- | :--- | :--- |
19
+ | **Verification Requests** | 50 live calls tested | 50 live calls tested | 100% transport pass rate across 5 test scenarios |
20
+ | **Average Network Latency** | 784.53 ms | 735.88 ms (pruned) | State pruning reduces wire payload size |
21
+ | **Deterministic Cache Hit** | 763.40 ms (144 tokens charged) | **0.099 ms** (**0 tokens**) | **Sub-millisecond retrieval (0.099 ms vs 763 ms WAN roundtrip); 0 tokens billed** |
22
+ | **Out-of-Scope Protection** | Forced False Positive (`chargeback`) | `UNRESOLVED_OR_OTHER` | Neutral escape injection catches off-topic inputs |
23
+ | **Uncertainty Calibration** | Raw unverified probabilities | `AMBIGUOUS_STATE` alert | Flags bimodal ties and low certainty |
24
+ | **Local Runtime Overhead** | 0 ms | **0.024 ms** | Sub-millisecond execution using pure Python stdlib |
25
+
26
+ ## Why JevGuard
27
+
28
+ TypeSafe AI's Jev model produces sub-second probabilistic evaluations over structured state. In production workflows, raw calls encounter three practical challenges:
29
+
30
+ 1. **Closed-World False Positives**: When categorical choice criteria lack a neutral fallback, the model distributes all probability across defined options. If an unhandled or off-topic input arrives, the model selects the closest available option.
31
+ 2. **Uncalibrated Ambiguity**: When inputs contain conflicting signals, probability distributions flatten. Selecting the top option without checking the runner-up margin leads to decisions made on low confidence.
32
+ 3. **Repeated Query Cost and Cache Misses**: Identical state checks inside agent loops consume network latency and token budgets. If payloads contain dynamic timestamps or request IDs, standard caches miss on every call.
33
+
34
+ ## Features
35
+
36
+ - **Closed-World Escape Injection**: Detects categorical choice rules without a fallback and injects `UNRESOLVED_OR_OTHER`. Off-topic inputs route to this escape option instead of triggering forced choices.
37
+ - **Strict Enum Support**: Set `closed_world=True` on `Choice` or `auto_inject_escapes=False` on the client when building strict enums where additional options must not be introduced.
38
+ - **Certainty and Dispersion Heuristics**: Uses configurable operational defaults (top probability below 0.40 or top-to-runner-up margin below 0.15) to flag indecisive distributions as `AMBIGUOUS_STATE`.
39
+ - **Volatile Metadata Masking**: Automatically ignores ephemeral fields (`timestamp`, `trace_id`, `request_id`, `nonce`) during SHA-256 fingerprinting, ensuring production cache hits across repeated queries.
40
+ - **Sub-Millisecond Overhead**: Pure local CPU computation runs in under 0.20 ms (198 microseconds) per evaluation.
41
+ - **Zero-Token SHA-256 Cache**: Hashes canonical sorted JSON. Identical requests return in under 1 millisecond with zero network overhead and zero token cost.
42
+ - **Concurrent Batch and Async Support**: Built-in `batch_evaluate` with thread pooling and native `async_evaluate` for `asyncio` event loops.
43
+ - **Resilient Network Retries**: Exponential backoff with jitter and `Retry-After` header parsing for HTTP 429 and 5xx server errors.
44
+ - **Episodic SQLite Memory**: Records session interaction turns with transactional serialization and builds rolling summaries without retransmitting raw history.
45
+ - **Zero Dependencies**: Pure Python 3.9+ standard library (`urllib`, `sqlite3`, `hashlib`, `json`, `threading`, `concurrent.futures`). No pip dependencies, no Node.js.
46
+
47
+ ## Installation
48
+
49
+ Install locally with pip:
50
+
51
+ ```bash
52
+ git clone https://github.com/seb4ez/jevguard.git
53
+ cd jevguard
54
+ pip install .
55
+ ```
56
+
57
+ Or copy the `jevguard` directory directly into your project.
58
+
59
+ Set your TypeSafe AI API key:
60
+
61
+ ```bash
62
+ export TYPESAFE_API_KEY="your_typesafe_api_key"
63
+ ```
64
+
65
+ On Windows PowerShell:
66
+
67
+ ```powershell
68
+ $env:TYPESAFE_API_KEY="your_typesafe_api_key"
69
+ ```
70
+
71
+ ## Quickstart
72
+
73
+ ```python
74
+ from jevguard import JevGuardClient, Noul, Score, Choice
75
+
76
+ client = JevGuardClient()
77
+
78
+ state = {
79
+ "ticket_id": "INC-4091",
80
+ "customer_message": "Our payment gateway timed out during credit card settlement.",
81
+ "account_tier": "enterprise",
82
+ "timestamp": 1726778900
83
+ }
84
+
85
+ questions = {
86
+ "is_billing": Noul(instructions="Does this ticket describe an invoice or payment issue?"),
87
+ "severity": Score(
88
+ instructions="Rate incident urgency",
89
+ criteria=["Low", "Medium", "High", "Critical"]
90
+ ),
91
+ "route": Choice(
92
+ instructions="Assign handling team",
93
+ criteria={
94
+ "database_team": "Database connection and replication issues",
95
+ "payment_support": "Gateway timeouts and transaction errors",
96
+ "frontend_ui": "CSS, rendering, and asset bundling issues"
97
+ }
98
+ )
99
+ }
100
+
101
+ response = client.evaluate(state, questions)
102
+
103
+ print(response.nouls["is_billing"].noul) # 0.96
104
+ print(response.scores["severity"].score) # 2.45
105
+ print(response.choices["route"].choice) # "payment_support"
106
+ print(response.choices["route"].status) # "CONFIDENT"
107
+ ```
108
+
109
+ ## Strict Closed-World Enums
110
+
111
+ When building strict finite-state machines where unhandled options must not be injected:
112
+
113
+ ```python
114
+ # Pass closed_world=True to prevent UNRESOLVED_OR_OTHER injection
115
+ approval_choice = Choice(
116
+ instructions="Review status",
117
+ criteria={"APPROVED": "Request accepted", "REJECTED": "Request denied"},
118
+ closed_world=True
119
+ )
120
+
121
+ resp = client.evaluate(state, {"decision": approval_choice})
122
+ ```
123
+
124
+ ## Production Caching with Volatile Metadata
125
+
126
+ JevGuard masks ephemeral fields during fingerprint computation so dynamic timestamps or trace IDs do not bust the cache:
127
+
128
+ ```python
129
+ # First call (cold)
130
+ resp1 = client.evaluate({"query": "Check balance", "timestamp": 1726778900, "trace_id": "t-1"}, questions)
131
+
132
+ # Second call 10 seconds later with new timestamp and trace_id hits local cache
133
+ resp2 = client.evaluate({"query": "Check balance", "timestamp": 1726778910, "trace_id": "t-2"}, questions)
134
+
135
+ print(resp2.cached) # True
136
+ print(resp2.telemetry["latency_total_ms"]) # 0.10 ms
137
+ print(resp2.telemetry["tokens_saved"]) # 159 tokens
138
+ ```
139
+
140
+ > Note: Volatile masking operates on structured dictionary keys (for example `{"timestamp": 123}`). If dynamic timestamps are embedded inside raw unstructured strings (for example `{"log": "2026-09-19T22:00:00Z error"}`), the SHA-256 fingerprint will change. To ensure cache hits, extract dynamic timestamps and request IDs into distinct dictionary keys in `state`.
141
+
142
+ ## Concurrent Batch and Async Execution
143
+
144
+ ```python
145
+ # Synchronous parallel batch evaluation
146
+ items = [
147
+ (state_1, questions),
148
+ (state_2, questions),
149
+ (state_3, questions)
150
+ ]
151
+ results = client.batch_evaluate(items, max_workers=5)
152
+
153
+ # Native asynchronous execution in asyncio event loops (no manual thread wrapping required)
154
+ import asyncio
155
+
156
+ async def main():
157
+ res = await client.async_evaluate(state, questions)
158
+ print(res.choices["route"].choice)
159
+
160
+ asyncio.run(main())
161
+ ```
162
+
163
+ ## Examples
164
+
165
+ Runnable demonstration scripts are included in the `examples/` directory:
166
+
167
+ ```bash
168
+ # 1. SRE Incident Triage: State pruning and multi-question evaluation
169
+ python examples/01_sre_incident_triage.py
170
+
171
+ # 2. Strict Finite State Machine: Enforcing closed_world=True with zero escapes
172
+ python examples/02_strict_finite_state_machine.py
173
+
174
+ # 3. High-Throughput Batch & Caching: Thread pool evaluation and volatile key masking
175
+ python examples/03_high_throughput_batch_caching.py
176
+ ```
177
+
178
+ ## Official Model Context Protocol (MCP) Server
179
+
180
+ JevGuard provides an official, zero-dependency MCP server for AI coding assistants (Google Antigravity, Cursor IDE, Claude Desktop, LibreChat, and Cline):
181
+
182
+ * **Repository**: **[seb4ez/jevguard-mcp](https://github.com/seb4ez/jevguard-mcp)**
183
+ * **Architecture**: 100% Python standard library over JSON-RPC 2.0 stdio with SQLite WAL concurrency and transparent `:memory:` degradation.
184
+ * **Autonomous Agent Tools**:
185
+ - `evaluate_command_safety`: Evaluates shell commands for destructive actions (`ALLOW_AUTONOMOUS`, `REQUIRE_HUMAN_APPROVAL`, `DENY_DESTRUCTIVE`).
186
+ - `verify_code_patch`: Evaluates git diffs for security regressions, broken syntax, or critical system impact under strict, balanced, or permissive risk tolerances.
187
+ - `evaluate_decision`: Evaluates architectural decisions from a list of options with automatic neutral escape injection (`UNRESOLVED_OR_OTHER`) and dispersion gap calibration.
188
+ - `jevguard_evaluate`: Low-level deterministic evaluation pipeline with state pruning and zero-token caching.
189
+ - `jevguard_calibrate`: Standalone certainty and probability dispersion calibrator (`AMBIGUOUS_STATE`).
190
+ - `jevguard_prune_state`: Sanitizes complex state payloads and collapses duplicate whitespace.
191
+ - `jevguard_cache_fingerprint`: Computes canonical SHA-256 fingerprints with volatile key masking.
192
+
193
+ ### Quick Setup for AI Coding Environments
194
+
195
+ #### Cursor IDE (`.cursor/mcp.json`)
196
+ ```json
197
+ {
198
+ "mcpServers": {
199
+ "jevguard": {
200
+ "command": "python",
201
+ "args": ["-m", "jevguard_mcp.server"],
202
+ "env": {
203
+ "TYPESAFE_API_KEY": "your_typesafe_api_key_here"
204
+ }
205
+ }
206
+ }
207
+ }
208
+ ```
209
+
210
+ #### Claude Desktop (`claude_desktop_config.json`)
211
+ ```json
212
+ {
213
+ "mcpServers": {
214
+ "jevguard": {
215
+ "command": "python",
216
+ "args": ["-m", "jevguard_mcp.server"],
217
+ "env": {
218
+ "TYPESAFE_API_KEY": "your_typesafe_api_key_here"
219
+ }
220
+ }
221
+ }
222
+ }
223
+ ```
224
+
225
+ For complete MCP server documentation, empirical benchmark reports, and installation guides, visit the dedicated repository: **[github.com/seb4ez/jevguard-mcp](https://github.com/seb4ez/jevguard-mcp)**.
226
+
227
+ ## Testing & Verification
228
+
229
+ Run the 21 formal subsystem certification tests:
230
+
231
+ ```bash
232
+ python test_suite_21.py
233
+ ```
234
+
235
+ This suite validates all 5 core subsystems under production conditions:
236
+ 1. State Pruner & Normalization (Tests 1 to 5)
237
+ 2. Closed-World Optimizer (Tests 6 to 9)
238
+ 3. Calibration & Dispersion Engine (Tests 10 to 13)
239
+ 4. Volatile Masking & Zero-Token Cache (Tests 14 to 17)
240
+ 5. Resilience, Batch & Async Transport (Tests 18 to 21)
241
+
242
+ Run the 30 comprehensive regression and concurrency tests:
243
+
244
+ ```bash
245
+ python test_jevguard.py
246
+ ```
247
+
248
+ Run the microsecond CPU latency audit:
249
+
250
+ ```bash
251
+ python benchmark.py
252
+ ```
253
+
254
+ Run the live upstream comparative test (requires `TYPESAFE_API_KEY`):
255
+
256
+ ```bash
257
+ python run_live_certification_tests.py
258
+ ```
259
+
260
+ ## Project Status and Validation Transparency
261
+
262
+ JevGuard is an independent, community-driven open-source project (v1.0.0) built strictly with the Python standard library. Initial implementation and test suites were developed iteratively using AI-assisted engineering and local unit test validation.
263
+
264
+ Key design caveats:
265
+ - The local runtime (canonicalization, hashing, state pruning, and calibration checks) is deterministic, whereas the remote TypeSafe AI / Jev service produces probabilistic classifications.
266
+ - Default calibration thresholds (such as top probability below 0.40 or margin below 0.15) represent operational heuristics for tie and uncertainty detection rather than parameters fitted on a specific domain corpus. Users can configure them according to their domain risk tolerance.
267
+ - We welcome external peer review, empirical validation on production datasets, and community contributions.
268
+
269
+ ## License
270
+
271
+ MIT License. See [LICENSE](LICENSE) for details.
@@ -0,0 +1,63 @@
1
+ """
2
+ JevGuard - High-Performance Deterministic Runtime for TypeSafe AI / Jev.
3
+ Provides closed-world optimization, certainty calibration, state pruning,
4
+ zero-token deterministic caching, and episodic session memory.
5
+ """
6
+
7
+ from .models import (
8
+ Question,
9
+ Noul,
10
+ Score,
11
+ Choice,
12
+ NoulAnswer,
13
+ ScoreAnswer,
14
+ ChoiceAnswer,
15
+ EvaluationResponse,
16
+ EvaluationResult
17
+ )
18
+ from .client import JevGuardClient
19
+ from .optimizer import StatePruner, QuestionOptimizer, ESCAPE_OPTION_KEY
20
+ from .calibrator import ResponseCalibrator, CertaintyCalibrator
21
+ from .cache import DeterministicCache, SemanticCache
22
+ from .memory import EpisodicMemory
23
+ from .exceptions import (
24
+ JevGuardError,
25
+ JevGuardConfigError,
26
+ JevGuardNetworkError,
27
+ JevGuardTimeoutError,
28
+ JevGuardHTTPError,
29
+ JevGuardAuthenticationError,
30
+ JevGuardRateLimitError,
31
+ JevGuardServerError
32
+ )
33
+
34
+ __version__ = "1.0.0"
35
+
36
+ __all__ = [
37
+ "JevGuardClient",
38
+ "Question",
39
+ "Noul",
40
+ "Score",
41
+ "Choice",
42
+ "NoulAnswer",
43
+ "ScoreAnswer",
44
+ "ChoiceAnswer",
45
+ "EvaluationResponse",
46
+ "EvaluationResult",
47
+ "StatePruner",
48
+ "QuestionOptimizer",
49
+ "ResponseCalibrator",
50
+ "CertaintyCalibrator",
51
+ "DeterministicCache",
52
+ "SemanticCache",
53
+ "EpisodicMemory",
54
+ "ESCAPE_OPTION_KEY",
55
+ "JevGuardError",
56
+ "JevGuardConfigError",
57
+ "JevGuardNetworkError",
58
+ "JevGuardTimeoutError",
59
+ "JevGuardHTTPError",
60
+ "JevGuardAuthenticationError",
61
+ "JevGuardRateLimitError",
62
+ "JevGuardServerError"
63
+ ]