Skip to content

Commit 6979669

Browse files
committed
fix: pass tool safety lint checks
1 parent 7723266 commit 6979669

9 files changed

Lines changed: 13 additions & 42 deletions

File tree

trpc_agent_sdk/tools/safety/_bash_scanner.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from __future__ import annotations
1414

1515
import re
16-
from typing import Iterator
1716

1817
from trpc_agent_sdk.tools.safety._facts import (
1918
ConcurrencyFact,

trpc_agent_sdk/tools/safety/_cross_field_scanner.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@
77

88
from __future__ import annotations
99

10-
import os
1110
from typing import Iterable
1211

13-
from trpc_agent_sdk.tools.safety._facts import Loc
1412
from trpc_agent_sdk.tools.safety._models import (
15-
Evidence,
1613
RiskCategory,
1714
RiskLevel,
1815
SafetyDecision,

trpc_agent_sdk/tools/safety/_policy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
2525

2626
from trpc_agent_sdk.tools.safety._exceptions import SafetyPolicyError
27-
from trpc_agent_sdk.tools.safety._models import ScriptLanguage, ToolKind
27+
from trpc_agent_sdk.tools.safety._models import ScriptLanguage
2828

2929
POLICY_VERSION = "1"
3030

trpc_agent_sdk/tools/safety/_python_scanner.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
from __future__ import annotations
1212

1313
import ast
14-
import os
15-
from typing import Any, Iterator
1614

17-
from trpc_agent_sdk.tools.safety._exceptions import SafetyScannerError
1815
from trpc_agent_sdk.tools.safety._facts import (
1916
ConcurrencyFact,
2017
DependencyInstallFact,
@@ -37,7 +34,6 @@
3734
)
3835
from trpc_agent_sdk.tools.safety._models import ScriptLanguage
3936
from trpc_agent_sdk.tools.safety._rules import _LanguageScannerRule, SafetyRule
40-
from trpc_agent_sdk.tools.safety._policy import is_sensitive_env_key
4137
from trpc_agent_sdk.tools.safety._redaction import contains_secret_literal
4238

4339
# Networks libs and the attribute used to extract a host arg.
@@ -404,10 +400,6 @@ def _pathlib_write(self, node: ast.Call, canonical: str) -> FileWriteFact:
404400
if isinstance(node.func, ast.Attribute) \
405401
and isinstance(node.func.value, ast.Call):
406402
target = _const_str(_first_arg(node.func.value)) or ""
407-
size = None
408-
if node.args:
409-
data_arg = node.args[0] if node.args else None
410-
size = self._static_size(data_arg)
411403
if not target:
412404
explicit = False
413405
target = "<dynamic>"
@@ -836,11 +828,10 @@ def _handle_sink_call(self, node: ast.Call, canonical: str) -> None:
836828
if sink_kind is None and isinstance(node.func, ast.Attribute):
837829
method = node.func.attr
838830
if method in {"info", "debug", "warning", "warn", "error", "critical", "exception", "log"}:
839-
if isinstance(node.func.value, ast.Name) \
840-
and node.func.value.id.lower() in {"log", "logger",
841-
"logging"}:
842-
sink_kind = "output"
843-
sink_name = f"log.{method}"
831+
if isinstance(node.func.value, ast.Name):
832+
if node.func.value.id.lower() in {"log", "logger", "logging"}:
833+
sink_kind = "output"
834+
sink_name = f"log.{method}"
844835
if sink_kind is None:
845836
return
846837
if not self._tainted_flows_into_call(node):

trpc_agent_sdk/tools/safety/_rules.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,13 @@
1212
from __future__ import annotations
1313

1414
import ipaddress
15-
from typing import Iterable, Protocol, Sequence, runtime_checkable
15+
from typing import Iterable, Protocol, runtime_checkable
1616

1717
from trpc_agent_sdk.tools.safety._facts import (
1818
ConcurrencyFact,
19-
DependencyInstallFact,
20-
DynamicExecFact,
21-
FileDeleteFact,
22-
FileReadFact,
23-
FileWriteFact,
24-
ForkBombFact,
25-
LargeWriteFact,
26-
LongSleepFact,
27-
NetworkFact,
28-
ParseErrorFact,
29-
PrivilegeFact,
30-
ProcessFact,
3119
ScriptFacts,
32-
SecretFlowFact,
33-
ShellOperatorFact,
34-
UnboundedLoopFact,
3520
)
3621
from trpc_agent_sdk.tools.safety._models import (
37-
Evidence,
3822
RiskCategory,
3923
RiskLevel,
4024
SafetyDecision,

trpc_agent_sdk/tools/safety/_telemetry.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,6 @@ def build_audit_event(
171171
):
172172
"""Build a :class:`SafetyAuditEvent` from a report."""
173173

174-
from trpc_agent_sdk.tools.safety._models import SafetyAuditEvent
175-
176174
return SafetyAuditEvent(
177175
event_id=report.report_id,
178176
timestamp=timestamp,

trpc_agent_sdk/tools/safety/examples/samples/06_whitelist_network.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
def fetch_user(handle: str) -> dict:
1212
response = requests.get(
13-
f"https://api.github.com/users/{handle}", timeout=5,
13+
f"https://api.github.com/users/{handle}",
14+
timeout=5,
1415
)
1516
response.raise_for_status()
1617
return response.json()

trpc_agent_sdk/tools/safety/examples/samples/08_shell_injection.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
def run_untrusted(user_input: str) -> int:
1212
return subprocess.run(
13-
f"ls {user_input}", shell=True, check=False,
13+
f"ls {user_input}",
14+
shell=True,
15+
check=False,
1416
).returncode
1517

1618

trpc_agent_sdk/tools/safety/wrapper.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919

2020
from __future__ import annotations
2121

22-
import asyncio
2322
import inspect
2423
from typing import Any, Callable, Generic, Mapping, TypeVar
2524

2625
from trpc_agent_sdk.tools.safety._audit import AuditSink, InMemoryAuditSink, NullAuditSink
27-
from trpc_agent_sdk.tools.safety._filter import BlockedExecutionError, ToolScriptSafetyFilter
26+
from trpc_agent_sdk.tools.safety._filter import ToolScriptSafetyFilter
2827
from trpc_agent_sdk.tools.safety._guard import ToolSafetyGuard
2928
from trpc_agent_sdk.tools.safety._models import (
3029
SafetyReport,
@@ -99,7 +98,7 @@ def __call__(self, *args: Any, **kwargs: Any) -> T:
9998
_ = report # caller can inspect via last_report
10099

101100
async def call_async(self, *args: Any, **kwargs: Any) -> T:
102-
report = await self._enforce_async(args, kwargs)
101+
await self._enforce_async(args, kwargs)
103102
result = self.delegate(*args, **kwargs)
104103
if inspect.isawaitable(result):
105104
return await result

0 commit comments

Comments
 (0)