Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions anchor/runtime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

Public API for the Anchor Interceptor SDK (Layer 1, V5.0.3).

One import activates full runtime governance across ALL AI providers:
Explicit activation is required to run runtime governance:

import anchor.runtime # auto-activates (BLOCK mode)
import anchor.runtime
anchor.runtime.activate(mode='block') # auto-activates (BLOCK mode)
# or:
anchor.runtime.activate(mode='warn') # warn but don't block
anchor.runtime.activate(mode='audit') # log only, no interruptions
Expand Down Expand Up @@ -84,6 +85,9 @@ def activate(
logger.debug("[Anchor] Runtime already active, skipping re-activation.")
return get_session_stats()

# Load custom providers from policy.anchor
_load_custom_providers_from_policy()

mode_enum = InterceptorMode(mode.lower())
_current_mode = mode_enum
_session_stats = SessionStats()
Expand Down Expand Up @@ -258,13 +262,6 @@ def wrapper(*args, **kwargs):
return decorator


# ---------------------------------------------------------------------------
# Auto-activate on import (BLOCK mode, no verbose)
# ---------------------------------------------------------------------------
_load_custom_providers_from_policy()
activate()


# Re-export for convenience
__all__ = [
"activate",
Expand Down
8 changes: 6 additions & 2 deletions tests/runtime/test_runtime_interceptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@
from anchor.runtime.interceptors.framework import activate_framework_patches, get_active_patches
print("5. framework.py imports: OK")

# 6: full runtime (auto-activated on import)
# 6: full runtime (explicitly activated)
import anchor.runtime as rt
s = rt.get_session_stats()
print(f"6. runtime/__init__.py: OK (status={s['status']}, mode={s.get('mode', '?')})")
assert s["status"] == "inactive", f"Expected inactive on import, got {s['status']}"
rt.activate()
s2 = rt.get_session_stats()
assert s2["status"] == "active", f"Expected active after activate(), got {s2['status']}"
print(f"6. runtime/__init__.py: OK (status={s2['status']}, mode={s2.get('mode', '?')})")

print("\nALL SMOKE TESTS PASSED")
Loading