cortexhub 0.5.2__tar.gz → 0.5.9__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 (64) hide show
  1. {cortexhub-0.5.2 → cortexhub-0.5.9}/PKG-INFO +1 -1
  2. {cortexhub-0.5.2 → cortexhub-0.5.9}/pyproject.toml +1 -1
  3. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/backend/client.py +69 -1
  4. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/client.py +406 -61
  5. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/constants.py +23 -2
  6. cortexhub-0.5.9/src/cortexhub/policy/absence.py +78 -0
  7. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/policy/effects.py +10 -0
  8. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/policy/evaluator.py +169 -36
  9. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/signing.py +1 -1
  10. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/telemetry/otel.py +0 -25
  11. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/tool.py +10 -0
  12. cortexhub-0.5.9/src/cortexhub/version.py +27 -0
  13. cortexhub-0.5.2/src/cortexhub/version.py +0 -15
  14. {cortexhub-0.5.2 → cortexhub-0.5.9}/.gitignore +0 -0
  15. {cortexhub-0.5.2 → cortexhub-0.5.9}/LICENSE +0 -0
  16. {cortexhub-0.5.2 → cortexhub-0.5.9}/README.md +0 -0
  17. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/__init__.py +0 -0
  18. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/audit/__init__.py +0 -0
  19. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/audit/events.py +0 -0
  20. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/backend/__init__.py +0 -0
  21. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/config.py +0 -0
  22. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/context/__init__.py +0 -0
  23. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/context/enricher.py +0 -0
  24. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/errors.py +0 -0
  25. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/__init__.py +0 -0
  26. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/injection.py +0 -0
  27. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/__init__.py +0 -0
  28. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/LICENSE +0 -0
  29. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/LICENSES_SOURCES +0 -0
  30. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/README.md +0 -0
  31. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/accuracy.json +0 -0
  32. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/attribute_ruler/patterns +0 -0
  33. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/config.cfg +0 -0
  34. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/lemmatizer/lookups/lookups.bin +0 -0
  35. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/meta.json +0 -0
  36. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/ner/cfg +0 -0
  37. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/ner/model +0 -0
  38. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/ner/moves +0 -0
  39. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/parser/cfg +0 -0
  40. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/parser/model +0 -0
  41. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/parser/moves +0 -0
  42. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/senter/cfg +0 -0
  43. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/senter/model +0 -0
  44. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/tagger/cfg +0 -0
  45. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/tagger/model +0 -0
  46. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/tok2vec/cfg +0 -0
  47. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/tok2vec/model +0 -0
  48. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/tokenizer +0 -0
  49. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/vocab/key2row +0 -0
  50. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/vocab/lookups.bin +0 -0
  51. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/vocab/strings.json +0 -0
  52. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/vocab/vectors +0 -0
  53. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/vocab/vectors.cfg +0 -0
  54. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/models/en_core_web_sm/meta.json +0 -0
  55. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/pii.py +0 -0
  56. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/guardrails/secrets.py +0 -0
  57. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/interceptors/__init__.py +0 -0
  58. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/interceptors/mcp.py +0 -0
  59. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/logging.py +0 -0
  60. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/policy/__init__.py +0 -0
  61. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/policy/loader.py +0 -0
  62. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/policy/models.py +0 -0
  63. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/policy/sync.py +0 -0
  64. {cortexhub-0.5.2 → cortexhub-0.5.9}/src/cortexhub/telemetry/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cortexhub
3
- Version: 0.5.2
3
+ Version: 0.5.9
4
4
  Summary: CortexHub Python SDK — Runtime governance for AI systems. One decorator, any tool, any framework.
5
5
  Project-URL: Homepage, https://cortexhub.ai
6
6
  Project-URL: Documentation, https://docs.cortexhub.ai
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "cortexhub"
3
- version = "0.5.2"
3
+ version = "0.5.9"
4
4
  description = "CortexHub Python SDK — Runtime governance for AI systems. One decorator, any tool, any framework."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10,<3.13"
@@ -94,6 +94,14 @@ class PolicyBundle:
94
94
  guardrail_version: str = "0"
95
95
  privacy_mode: str = "on"
96
96
 
97
+ # Enforcement mode on the governed agent — ``observe`` or
98
+ # ``enforce``. Read by the SDK evaluator to decide whether to
99
+ # apply the Observe dry-run overlay (permit decisions that
100
+ # would have blocked in Enforce mode). Shipped fresh on every
101
+ # ``/policies/bundle`` sync. Defaults to ``observe`` for back-
102
+ # compat with pre-0.5.5 control planes.
103
+ enforcement_mode: str = "observe"
104
+
97
105
 
98
106
  @dataclass
99
107
  class SDKConfig:
@@ -160,8 +168,34 @@ class BackendClient:
160
168
  (is_valid, SDKConfig or None)
161
169
 
162
170
  SDKConfig includes governed ``agent_id`` (ObjectId string), display metadata, and policies.
171
+
172
+ Side effects: stores a machine-readable failure hint on
173
+ ``self.last_validation_error_kind`` so the outer ``CortexHub``
174
+ init can emit an actionable message instead of a generic
175
+ "rotate your key." Possible values:
176
+
177
+ * ``"network"`` — DNS/TLS/connection/timeout failure. The
178
+ key was never checked. Tell the user to check network,
179
+ VPN, or flush DNS cache.
180
+ * ``"rejected"`` — Backend returned a well-formed
181
+ ``{valid: false}`` or a 401/403. The key is genuinely
182
+ wrong / revoked.
183
+ * ``"http_error"`` — Backend returned a non-200 with no
184
+ parseable body (5xx, upstream hiccup). Transient.
185
+ * ``"malformed_response"`` — 200 but body not JSON / missing
186
+ fields. Version drift between SDK and backend.
187
+ * ``"unconfigured"`` — No agent key at all.
188
+ * ``None`` — success, or never attempted.
163
189
  """
190
+ self.last_validation_error_kind: str | None = None
191
+ self.last_validation_error_detail: str | None = None
192
+
164
193
  if not self.agent_key or not self._client:
194
+ self.last_validation_error_kind = "unconfigured"
195
+ self.last_validation_error_detail = (
196
+ "No agent key supplied — set CORTEXHUB_AGENT_KEY or "
197
+ "pass ``agent_key=`` to ``cortexhub.init()``."
198
+ )
165
199
  return False, None
166
200
 
167
201
  try:
@@ -188,11 +222,21 @@ class BackendClient:
188
222
  preview=(response.text or "")[:300],
189
223
  error=str(parse_err),
190
224
  )
225
+ self.last_validation_error_kind = "malformed_response"
226
+ self.last_validation_error_detail = (
227
+ "Backend returned 200 but body was not JSON — "
228
+ "likely an SDK/backend version mismatch."
229
+ )
191
230
  return False, None
192
231
 
193
232
  # Check if valid
194
233
  if not data.get("valid", False):
195
234
  logger.warning("Agent key validation failed", message=data.get("message"))
235
+ self.last_validation_error_kind = "rejected"
236
+ self.last_validation_error_detail = (
237
+ data.get("message")
238
+ or "Backend returned valid=false without detail."
239
+ )
196
240
  return False, None
197
241
 
198
242
  # Parse policy bundle from backend
@@ -358,6 +402,11 @@ class BackendClient:
358
402
  default_behavior=policies_data.get("default_behavior", "allow_and_log"),
359
403
  guardrail_version=policies_data.get("guardrail_version", "0"),
360
404
  privacy_mode=_privacy,
405
+ enforcement_mode=(
406
+ policies_data.get("enforcement_mode")
407
+ or data.get("enforcement_mode")
408
+ or "observe"
409
+ ),
361
410
  )
362
411
  logger.debug("Validate response privacy_mode", privacy_mode=_privacy)
363
412
 
@@ -405,16 +454,35 @@ class BackendClient:
405
454
  (response.text or "")[:500] or f"HTTP {response.status_code}"
406
455
  )
407
456
  logger.warning("Agent key validation failed", error=error_detail)
457
+ # 401/403 are authoritative rejections; 5xx / other codes
458
+ # are transient HTTP errors that shouldn't trigger a
459
+ # "rotate your key" panic in the outer init.
460
+ if response.status_code in (401, 403):
461
+ self.last_validation_error_kind = "rejected"
462
+ else:
463
+ self.last_validation_error_kind = "http_error"
464
+ self.last_validation_error_detail = (
465
+ f"HTTP {response.status_code}: {error_detail}"
466
+ )
408
467
  return False, None
409
468
 
410
- except httpx.ConnectError:
469
+ except (httpx.ConnectError, httpx.ConnectTimeout, httpx.ReadTimeout) as e:
411
470
  logger.warning(
412
471
  "Backend unreachable - running in offline observation mode",
413
472
  backend_url=self.backend_url,
473
+ error=str(e),
474
+ )
475
+ self.last_validation_error_kind = "network"
476
+ self.last_validation_error_detail = (
477
+ f"Could not reach {self.backend_url}: {type(e).__name__} — {e}. "
478
+ "Check DNS / VPN / firewall; the agent key itself was "
479
+ "never sent to the backend."
414
480
  )
415
481
  return False, None
416
482
  except Exception as e:
417
483
  logger.error("Agent key validation error", error=str(e))
484
+ self.last_validation_error_kind = "http_error"
485
+ self.last_validation_error_detail = f"{type(e).__name__}: {e}"
418
486
  return False, None
419
487
 
420
488
  def close(self):