Skip to content

Commit b37fc07

Browse files
Zie619claude
andcommitted
chore: fix ruff lint/format, add .env to gitignore, prune dangling objects
- Fix 5 ruff lint errors (unsorted imports, unused imports, line too long) - Auto-format 2 files with ruff format - Add .env/.env.local exclusions to .gitignore - Pruned dangling git objects from history rewrite Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 17270e9 commit b37fc07

File tree

6 files changed

+22
-21
lines changed

6 files changed

+22
-21
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,10 @@ demo-video/node_modules/
3535
.DS_Store
3636
Thumbs.db
3737

38+
# Environment files
39+
.env
40+
.env.local
41+
.env.*.local
42+
3843
# Confidential documents
3944
*.docx

trusera-agent-sdk/trusera_sdk/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""Trusera SDK for monitoring AI agents."""
22

3-
from .cedar import CedarEvaluator, PolicyDecision, PolicyAction, EvaluationResult
3+
from .cedar import CedarEvaluator, EvaluationResult, PolicyAction, PolicyDecision
44
from .client import TruseraClient
55
from .decorators import get_default_client, monitor, set_default_client
66
from .events import Event, EventType
7-
from .standalone import StandaloneInterceptor, RequestBlockedError
7+
from .standalone import RequestBlockedError, StandaloneInterceptor
88

99
__version__ = "0.1.0"
1010

trusera-agent-sdk/trusera_sdk/cedar.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class EvaluationResult:
6363
# Matches: forbid ( principal, action == Action::"http", resource ) when { ... };
6464
RULE_PATTERN = re.compile(
6565
r'(forbid|permit)\s*\(\s*principal\s*,\s*action\s*==\s*Action::"(\w+)"\s*,\s*resource\s*\)'
66-
r'\s*when\s*\{([^}]+)\}\s*;',
66+
r"\s*when\s*\{([^}]+)\}\s*;",
6767
re.MULTILINE | re.DOTALL | re.IGNORECASE,
6868
)
6969

@@ -87,7 +87,7 @@ def parse_policy(policy_text: str) -> list[PolicyRule]:
8787
"""
8888
rules: list[PolicyRule] = []
8989
# Strip comments (// style)
90-
cleaned = re.sub(r'//[^\n]*', '', policy_text)
90+
cleaned = re.sub(r"//[^\n]*", "", policy_text)
9191

9292
for match in RULE_PATTERN.finditer(cleaned):
9393
action_str = match.group(1).lower()
@@ -197,8 +197,7 @@ def evaluate_request(
197197
return EvaluationResult(
198198
decision=PolicyDecision.DENY,
199199
reason=(
200-
f"Forbidden by policy: request.{rule.field} "
201-
f"{rule.operator} \"{rule.value}\""
200+
f'Forbidden by policy: request.{rule.field} {rule.operator} "{rule.value}"'
202201
),
203202
matched_rule=rule,
204203
)
@@ -214,7 +213,7 @@ def evaluate_request(
214213
decision=PolicyDecision.ALLOW,
215214
reason=(
216215
f"Explicitly permitted by policy: request.{rule.field} "
217-
f"{rule.operator} \"{rule.value}\""
216+
f'{rule.operator} "{rule.value}"'
218217
),
219218
matched_rule=rule,
220219
)
@@ -263,7 +262,7 @@ def from_file(cls, policy_path: str) -> CedarEvaluator:
263262
Raises:
264263
FileNotFoundError: If policy file doesn't exist
265264
"""
266-
with open(policy_path, encoding='utf-8') as f:
265+
with open(policy_path, encoding="utf-8") as f:
267266
policy_text = f.read()
268267

269268
rules = parse_policy(policy_text)

trusera-agent-sdk/trusera_sdk/integrations/autogen.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
"""AutoGen integration for Trusera."""
22

33
import logging
4-
from typing import Any, Callable, Optional
4+
from typing import Any, Callable
55

66
from ..client import TruseraClient
77
from ..events import Event, EventType
88

99
logger = logging.getLogger(__name__)
1010

1111
try:
12-
import autogen
12+
import autogen # noqa: F401
1313

1414
AUTOGEN_AVAILABLE = True
1515
except ImportError:
@@ -171,7 +171,8 @@ def setup_agent(self, agent: Any) -> None:
171171
"""
172172
if hasattr(agent, "register_hook"):
173173
agent.register_hook("process_message_before_send", self.message_hook)
174-
logger.info(f"Registered Trusera hook for agent: {getattr(agent, 'name', 'unknown')}")
174+
agent_name = getattr(agent, "name", "unknown")
175+
logger.info(f"Registered Trusera hook for agent: {agent_name}")
175176
else:
176177
logger.warning(f"Agent {getattr(agent, 'name', 'unknown')} does not support hooks")
177178

trusera-agent-sdk/trusera_sdk/integrations/crewai.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""CrewAI integration for Trusera."""
22

33
import logging
4-
from typing import Any, Optional
4+
from typing import Any
55

66
from ..client import TruseraClient
77
from ..events import Event, EventType

trusera-agent-sdk/trusera_sdk/standalone.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ def __init__(
8686
"""
8787
if enforcement not in ("block", "warn", "log"):
8888
raise ValueError(
89-
f"Invalid enforcement mode: {enforcement}. "
90-
f"Must be 'block', 'warn', or 'log'"
89+
f"Invalid enforcement mode: {enforcement}. Must be 'block', 'warn', or 'log'"
9190
)
9291

9392
self.enforcement = enforcement
@@ -175,8 +174,8 @@ def _log_event(
175174
self.log_file.parent.mkdir(parents=True, exist_ok=True)
176175

177176
# Append to JSONL file (one JSON object per line)
178-
with open(self.log_file, 'a', encoding='utf-8') as f:
179-
f.write(json.dumps(event) + '\n')
177+
with open(self.log_file, "a", encoding="utf-8") as f:
178+
f.write(json.dumps(event) + "\n")
180179

181180
self._event_count += 1
182181
if self.debug:
@@ -412,9 +411,7 @@ async def async_send_wrapper(
412411
request: httpx.Request,
413412
**kwargs: Any,
414413
) -> httpx.Response:
415-
original = self._original_async_send.__get__(
416-
client_self, httpx.AsyncClient
417-
)
414+
original = self._original_async_send.__get__(client_self, httpx.AsyncClient)
418415
return await self._intercept_async_request(original, request, **kwargs)
419416

420417
# Monkey-patch httpx
@@ -442,8 +439,7 @@ def uninstall(self) -> None:
442439

443440
self._installed = False
444441
logger.info(
445-
f"Trusera StandaloneInterceptor uninstalled "
446-
f"({self._event_count} events logged)"
442+
f"Trusera StandaloneInterceptor uninstalled ({self._event_count} events logged)"
447443
)
448444

449445
def get_stats(self) -> dict[str, Any]:

0 commit comments

Comments
 (0)