Files
docker-agent-sandbox/docker_agent_sandbox/tools/_utils.py
Matte23 80c2f9b159 feat: Initial library extraction from PIN LLM benchmark
DockerSandbox + LangChain file/shell tools extracted into a standalone package.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-02 11:47:44 +02:00

26 lines
773 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""_utils.py shared helpers for file-ops tools."""
from __future__ import annotations
import posixpath
_MAX_OUTPUT_LINES = 200
_MAX_OUTPUT_CHARS = 20_000
_TRUNCATION_NOTICE = "\n... [output truncated] ..."
def truncate_output(output: str) -> str:
"""Truncate *output* to avoid hitting token limits."""
lines = output.splitlines(keepends=True)
if len(lines) > _MAX_OUTPUT_LINES:
output = "".join(lines[:_MAX_OUTPUT_LINES]) + _TRUNCATION_NOTICE
if len(output) > _MAX_OUTPUT_CHARS:
output = output[:_MAX_OUTPUT_CHARS] + _TRUNCATION_NOTICE
return output
def _parent(path: str) -> str:
"""Return the parent directory of *path* (best-effort, no I/O)."""
parent = posixpath.dirname(path.rstrip("/"))
return parent or "."