File size: 1,618 Bytes
5873600 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | """Opt-in default for extra local Pi bash; never a model/episode deadline."""
from __future__ import annotations
import hashlib
import math
import shutil
from pathlib import Path
def bash_timeout_configuration(source_package: Path, seconds: float | None) -> dict:
if seconds is not None and (not math.isfinite(seconds) or seconds <= 0 or seconds * 1000 > 2147483647):
raise ValueError("Local Pi bash timeout must be a positive finite builtin-supported duration")
return {"mode": "optional-local-bash-default-v1", "enabled": seconds is not None,
"default_seconds": seconds, "explicit_tool_timeout_preserved": True,
"stanford_native_tools_changed": False, "model_or_episode_timeout": False,
"extension_sha256": hashlib.sha256((source_package / "pi-bash-timeout.js").read_bytes()).hexdigest()}
def stage_bash_timeout(source_package: Path, agent: Path) -> None:
target = agent / "collab_harbor/pi-bash-timeout.js"
target.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(source_package / "pi-bash-timeout.js", target)
target.chmod(0o644)
def docker_bash_timeout_lines(seconds: float | None = None) -> str:
# No ENV default in generated tasks. Profiles explicitly opt in.
lines = "COPY collab_harbor/pi-bash-timeout.js /tmp/harbor-pi-agent/extensions/z-local-bash-timeout.js\n"
if seconds is not None:
if not math.isfinite(seconds) or seconds <= 0 or seconds * 1000 > 2147483647:
raise ValueError("Invalid local Pi bash timeout")
lines += f"ENV CI_PI_BASH_TIMEOUT_SEC={seconds:g}\n"
return lines
|