Skip to content

Actions

agent_gate.actions

Normalize a PreToolUse hook payload into an :class:Action.

The agent's own account of a call is removed here. A Bash call carries a description the agent wrote about the command; the gate judges the command, never the description.

Action(tool, params, cwd, session_id, tool_use_id) dataclass

One tool call, as the gate judges it.

Parameters:

Name Type Description Default
tool str

the tool name, e.g. Bash or mcp__gmail__send_message.

required
params dict[str, Any]

the tool input with narrative fields removed.

required
cwd Path

the agent's working directory.

required
session_id str

the Claude Code session.

required
tool_use_id str

the id of this call.

required

command property

The shell command of a Bash call, else an empty string.

consequential property

True unless the call only reads.

is_mcp property

True for an MCP tool.

mcp_read_only property

True for an MCP tool whose name starts with a read verb.

from_hook(payload) classmethod

Build an action from a PreToolUse hook payload.

Parameters:

Name Type Description Default
payload dict[str, Any]

the JSON object Claude Code writes to the hook's stdin.

required
Source code in src/agent_gate/actions.py
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
@classmethod
def from_hook(cls, payload: dict[str, Any]) -> Action:
    """Build an action from a PreToolUse hook payload.

    :param payload: the JSON object Claude Code writes to the hook's stdin.
    """
    raw = payload.get("tool_input") or {}
    params = {k: v for k, v in raw.items() if k not in NARRATIVE_FIELDS}
    return cls(
        tool=str(payload.get("tool_name", "")),
        params=params,
        cwd=Path(payload.get("cwd") or ".").resolve(),
        session_id=str(payload.get("session_id") or "unknown"),
        tool_use_id=str(payload.get("tool_use_id") or ""),
    )

params_text(limit=2000)

The tool input as stable JSON, capped, used to spot retries of a blocked action.

Parameters:

Name Type Description Default
limit int | None

the maximum length kept, or None for all of it.

2000
Source code in src/agent_gate/actions.py
121
122
123
124
125
126
def params_text(self, limit: int | None = 2000) -> str:
    """The tool input as stable JSON, capped, used to spot retries of a blocked action.

    :param limit: the maximum length kept, or ``None`` for all of it.
    """
    return json.dumps(self.params, sort_keys=True, default=str)[:limit]