"""_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 "."