cortexhub 0.5.6__tar.gz → 0.5.8__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 (63) hide show
  1. {cortexhub-0.5.6 → cortexhub-0.5.8}/PKG-INFO +1 -1
  2. {cortexhub-0.5.6 → cortexhub-0.5.8}/pyproject.toml +1 -1
  3. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/backend/client.py +56 -1
  4. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/client.py +63 -5
  5. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/version.py +1 -1
  6. {cortexhub-0.5.6 → cortexhub-0.5.8}/.gitignore +0 -0
  7. {cortexhub-0.5.6 → cortexhub-0.5.8}/LICENSE +0 -0
  8. {cortexhub-0.5.6 → cortexhub-0.5.8}/README.md +0 -0
  9. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/__init__.py +0 -0
  10. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/audit/__init__.py +0 -0
  11. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/audit/events.py +0 -0
  12. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/backend/__init__.py +0 -0
  13. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/config.py +0 -0
  14. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/constants.py +0 -0
  15. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/context/__init__.py +0 -0
  16. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/context/enricher.py +0 -0
  17. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/errors.py +0 -0
  18. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/__init__.py +0 -0
  19. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/injection.py +0 -0
  20. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/__init__.py +0 -0
  21. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/LICENSE +0 -0
  22. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/LICENSES_SOURCES +0 -0
  23. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/README.md +0 -0
  24. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/accuracy.json +0 -0
  25. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/attribute_ruler/patterns +0 -0
  26. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/config.cfg +0 -0
  27. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/lemmatizer/lookups/lookups.bin +0 -0
  28. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/meta.json +0 -0
  29. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/ner/cfg +0 -0
  30. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/ner/model +0 -0
  31. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/ner/moves +0 -0
  32. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/parser/cfg +0 -0
  33. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/parser/model +0 -0
  34. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/parser/moves +0 -0
  35. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/senter/cfg +0 -0
  36. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/senter/model +0 -0
  37. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/tagger/cfg +0 -0
  38. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/tagger/model +0 -0
  39. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/tok2vec/cfg +0 -0
  40. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/tok2vec/model +0 -0
  41. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/tokenizer +0 -0
  42. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/vocab/key2row +0 -0
  43. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/vocab/lookups.bin +0 -0
  44. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/vocab/strings.json +0 -0
  45. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/vocab/vectors +0 -0
  46. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/en_core_web_sm-3.8.0/vocab/vectors.cfg +0 -0
  47. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/models/en_core_web_sm/meta.json +0 -0
  48. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/pii.py +0 -0
  49. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/guardrails/secrets.py +0 -0
  50. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/interceptors/__init__.py +0 -0
  51. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/interceptors/mcp.py +0 -0
  52. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/logging.py +0 -0
  53. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/policy/__init__.py +0 -0
  54. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/policy/absence.py +0 -0
  55. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/policy/effects.py +0 -0
  56. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/policy/evaluator.py +0 -0
  57. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/policy/loader.py +0 -0
  58. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/policy/models.py +0 -0
  59. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/policy/sync.py +0 -0
  60. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/signing.py +0 -0
  61. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/telemetry/__init__.py +0 -0
  62. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/telemetry/otel.py +0 -0
  63. {cortexhub-0.5.6 → cortexhub-0.5.8}/src/cortexhub/tool.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cortexhub
3
- Version: 0.5.6
3
+ Version: 0.5.8
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.6"
3
+ version = "0.5.8"
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"
@@ -168,8 +168,34 @@ class BackendClient:
168
168
  (is_valid, SDKConfig or None)
169
169
 
170
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.
171
189
  """
190
+ self.last_validation_error_kind: str | None = None
191
+ self.last_validation_error_detail: str | None = None
192
+
172
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
+ )
173
199
  return False, None
174
200
 
175
201
  try:
@@ -196,11 +222,21 @@ class BackendClient:
196
222
  preview=(response.text or "")[:300],
197
223
  error=str(parse_err),
198
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
+ )
199
230
  return False, None
200
231
 
201
232
  # Check if valid
202
233
  if not data.get("valid", False):
203
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
+ )
204
240
  return False, None
205
241
 
206
242
  # Parse policy bundle from backend
@@ -418,16 +454,35 @@ class BackendClient:
418
454
  (response.text or "")[:500] or f"HTTP {response.status_code}"
419
455
  )
420
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
+ )
421
467
  return False, None
422
468
 
423
- except httpx.ConnectError:
469
+ except (httpx.ConnectError, httpx.ConnectTimeout, httpx.ReadTimeout) as e:
424
470
  logger.warning(
425
471
  "Backend unreachable - running in offline observation mode",
426
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."
427
480
  )
428
481
  return False, None
429
482
  except Exception as e:
430
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}"
431
486
  return False, None
432
487
 
433
488
  def close(self):
@@ -387,11 +387,67 @@ class CortexHub:
387
387
  )
388
388
  self.agent_id = os.getenv("CORTEXHUB_OFFLINE_AGENT_ID", "offline")
389
389
  else:
390
- raise ConfigurationError(
391
- "Agent key validation failed. "
392
- "Check that your agent key is correct and not revoked. "
393
- "Create or rotate the key in https://app.cortexhub.ai"
394
- )
390
+ # Emit a targeted error based on WHY validation failed.
391
+ # The generic "rotate your key" message sent users on
392
+ # wild goose chases every time DNS / VPN / a transient
393
+ # 5xx hiccuped — the key was never actually rejected
394
+ # in those cases. ``BackendClient.validate_agent_key``
395
+ # stores the failure kind on the client so we can be
396
+ # specific here.
397
+ kind = getattr(self.backend, "last_validation_error_kind", None)
398
+ detail = getattr(self.backend, "last_validation_error_detail", None)
399
+ if kind == "network":
400
+ message = (
401
+ "Could not reach the CortexHub backend — the agent "
402
+ "key was never validated.\n"
403
+ f" Reason: {detail}\n"
404
+ " Fixes in order of likelihood:\n"
405
+ " 1. Check that you're online and DNS is working "
406
+ "(``dig api.cortexhub.ai``). On macOS, flush a stale "
407
+ "cache with ``sudo dscacheutil -flushcache && sudo "
408
+ "killall -HUP mDNSResponder``.\n"
409
+ " 2. If on a corporate VPN, confirm it isn't "
410
+ "blocking api.cortexhub.ai.\n"
411
+ " 3. If this is a restricted environment, run "
412
+ "with ``CORTEXHUB_ALLOW_OFFLINE_ENFORCEMENT=true`` "
413
+ "and a cached policy bundle on disk."
414
+ )
415
+ elif kind == "rejected":
416
+ message = (
417
+ "The CortexHub backend rejected the agent key. It "
418
+ "is missing, wrong, or has been revoked.\n"
419
+ f" Backend said: {detail}\n"
420
+ " Create or rotate the key in "
421
+ "https://app.cortexhub.ai and update the "
422
+ "``CORTEXHUB_AGENT_KEY`` environment variable "
423
+ "(or the ``agent_key=`` argument to ``cortexhub.init()``)."
424
+ )
425
+ elif kind == "unconfigured":
426
+ message = (
427
+ "No agent key supplied. Set "
428
+ "``CORTEXHUB_AGENT_KEY`` in your environment, "
429
+ "or pass ``agent_key=...`` to ``cortexhub.init()``.\n"
430
+ " Get a key from https://app.cortexhub.ai."
431
+ )
432
+ elif kind == "malformed_response":
433
+ message = (
434
+ "The CortexHub backend returned an unexpected "
435
+ "response to the validate call — likely an SDK / "
436
+ "backend version mismatch.\n"
437
+ f" Detail: {detail}\n"
438
+ " Try ``pip install -U cortexhub``. If the problem "
439
+ "persists, share this message with the CortexHub team."
440
+ )
441
+ else: # "http_error" or unknown
442
+ message = (
443
+ "Agent key validation failed with an unexpected "
444
+ "error — the key itself may still be valid.\n"
445
+ f" Detail: {detail}\n"
446
+ " This is usually transient. Retry in a few seconds. "
447
+ "If it persists, check the CortexHub status page or "
448
+ "contact support."
449
+ )
450
+ raise ConfigurationError(message)
395
451
  else:
396
452
  self._apply_sdk_config(sdk_config)
397
453
  if not sdk_config.has_policies:
@@ -1389,6 +1445,7 @@ class CortexHub:
1389
1445
  parameters_schema=parameters_schema,
1390
1446
  principal=principal,
1391
1447
  resource_type=resource_type,
1448
+ classification=classification,
1392
1449
  )
1393
1450
  except CortexHubError:
1394
1451
  raise # all governance decisions — always propagate
@@ -1412,6 +1469,7 @@ class CortexHub:
1412
1469
  parameters_schema: dict[str, Any] | None = None,
1413
1470
  principal: "Principal | dict[str, str] | None" = None,
1414
1471
  resource_type: str = "Tool",
1472
+ classification: str | None = None,
1415
1473
  ) -> Any:
1416
1474
  """Internal governance pipeline — called from execute_governed_tool."""
1417
1475
  # Ensure policies and enforcement mode are fresh before evaluating.
@@ -12,7 +12,7 @@ incorrectly in those environments.
12
12
 
13
13
  from importlib.metadata import PackageNotFoundError, version
14
14
 
15
- __fallback_version__ = "0.5.6"
15
+ __fallback_version__ = "0.5.8"
16
16
 
17
17
 
18
18
  def _resolve_version() -> str:
File without changes
File without changes
File without changes