"""Filesystem capability via pydantic-ai-backend. Allows all file operations (read, write, edit, ls, glob, grep) with sensitive-file protections from PERMISSIVE_RULESET. The execute tool is excluded entirely so the model cannot run arbitrary shell commands. Usage ----- The console toolset tools access the filesystem through ``ctx.deps.backend``, so the agent must be configured with ``deps_type=AgentDeps`` and callers must pass ``deps=AgentDeps(backend=LocalBackend("/"), issue_number=123)`` (or any other root) to ``agent.run()``. Without this, any fs tool call will raise ``AttributeError``. """ from dataclasses import dataclass from pydantic_ai_backends import ConsoleCapability, LocalBackend from pydantic_ai_backends.permissions.presets import PERMISSIVE_RULESET from capabilities.base import CapabilityWithTools @dataclass class AgentDeps: """Shared runtime deps for the agent and capabilities. Pass this as ``deps=AgentDeps(backend=LocalBackend("/"), issue_number=123)`` when calling ``agent.run()``. The ``backend`` attribute satisfies the ``ConsoleDeps`` protocol expected by the console toolset's tools, and ``issue_number`` provides the current GitHub issue context to tools that need it. """ backend: LocalBackend issue_number: int = 0 class _FSCapability(CapabilityWithTools, ConsoleCapability): """ConsoleCapability subclass with agent-appropriate instructions. Overrides the default prompt to frame the filesystem functions as sandbox-internal functions rather than top-level tools, consistent with how all other capabilities are described to the agent. """ def _instructions_header(self) -> str: return """\ ## Filesystem Functions Call these as `await function_name(...)` inside `run_code`. Use these functions to read and write files. Do NOT use stdlib file I/O (`open()`, `os`, `pathlib`) — only these functions are available in the sandbox.\ """ FSCapability = _FSCapability( include_execute=False, permissions=PERMISSIVE_RULESET, ) __all__ = ["FSCapability", "AgentDeps"]