DockerSandbox + LangChain file/shell tools extracted into a standalone package. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
26 lines
773 B
Python
26 lines
773 B
Python
"""_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 "."
|