Files
pydantic--pydantic-ai/.github/scripts/pydantic_ai_gh_aw_shim/bash.py
T
wehub-resource-sync 9201ef759e
CI / lint (push) Waiting to run
CI / mypy (push) Waiting to run
CI / docs (push) Waiting to run
CI / test on 3.10 (standard) (push) Waiting to run
CI / test on 3.11 (standard) (push) Waiting to run
CI / test on 3.12 (standard) (push) Waiting to run
CI / test on 3.10 (all-extras) (push) Waiting to run
CI / test on 3.11 (all-extras) (push) Waiting to run
CI / test on 3.12 (all-extras) (push) Waiting to run
CI / test on 3.13 (all-extras) (push) Waiting to run
CI / test on 3.14 (pydantic-evals) (push) Waiting to run
Harness Compat / harness compat (push) Waiting to run
CI / test on 3.13 (standard) (push) Waiting to run
CI / test on 3.14 (standard) (push) Waiting to run
CI / test on 3.14 (all-extras) (push) Waiting to run
CI / test on 3.10 (pydantic-ai-slim) (push) Waiting to run
CI / test on 3.11 (pydantic-ai-slim) (push) Waiting to run
CI / test on 3.12 (pydantic-ai-slim) (push) Waiting to run
CI / test on 3.13 (pydantic-ai-slim) (push) Waiting to run
CI / test on 3.14 (pydantic-ai-slim) (push) Waiting to run
CI / test on 3.10 (pydantic-evals) (push) Waiting to run
CI / test on 3.11 (pydantic-evals) (push) Waiting to run
CI / test on 3.12 (pydantic-evals) (push) Waiting to run
CI / test on 3.13 (pydantic-evals) (push) Waiting to run
CI / test on 3.10 (lowest-versions) (push) Waiting to run
CI / test on 3.11 (lowest-versions) (push) Waiting to run
CI / test on 3.12 (lowest-versions) (push) Waiting to run
CI / test on 3.13 (lowest-versions) (push) Waiting to run
CI / test on 3.14 (lowest-versions) (push) Waiting to run
CI / test examples on 3.11 (push) Waiting to run
CI / test examples on 3.12 (push) Waiting to run
CI / test examples on 3.13 (push) Waiting to run
CI / test examples on 3.14 (push) Waiting to run
CI / coverage (push) Blocked by required conditions
CI / check (push) Blocked by required conditions
CI / deploy-docs (push) Blocked by required conditions
CI / deploy-docs-preview (push) Blocked by required conditions
CI / build release artifacts (push) Blocked by required conditions
CI / publish to PyPI (push) Blocked by required conditions
CI / Send tweet (push) Blocked by required conditions
chore: import upstream snapshot with attribution
2026-07-13 13:27:52 +08:00

37 lines
1.7 KiB
Python

"""Claude's `Bash` tool -- run a shell command in the workspace.
Backed by pydantic-ai-harness's `ShellToolset`, which handles subprocess
execution, the per-command timeout, and tail-keeping output truncation. The
Claude `Bash` signature (`command`, optional `timeout` in seconds) and the
sandbox PATH augmentation are preserved by the adapter.
"""
from pydantic_ai.exceptions import ModelRetry
from ._backends import BASH_DEFAULT_TIMEOUT, BASH_MAX_TIMEOUT, shell
async def bash(command: str, timeout: int | None = None) -> str:
"""Run a shell command in the repository workspace.
Returns the command's labeled stdout/stderr (truncated). `timeout` is in
seconds (default 120, capped at 600).
"""
secs = BASH_DEFAULT_TIMEOUT if not timeout or timeout <= 0 else min(int(timeout), BASH_MAX_TIMEOUT)
try:
out = await shell().run_command(command, timeout_seconds=float(secs))
except (ModelRetry, OSError) as exc:
# ModelRetry: the harness blocked the command; the shim's tools have always
# surfaced such conditions as a returned error string rather than a
# model-facing retry. OSError: subprocess startup failed (e.g. the
# workspace cwd does not exist) -- the harness doesn't convert it, so catch
# it here rather than let it abort the whole run.
return f'error: {exc}'
# On timeout the harness *returns* a `[Command timed out after Ns]` sentinel
# rather than raising. The old tool surfaced timeouts as an `error:` string
# (and `Grep` already wraps the same sentinel), so do the same here instead
# of handing the model an unprefixed result it might read as success.
if out.startswith('[Command timed out'):
return f'error: {out}'
return out