The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(agent/display,error_surface,i18n): final guard-ladder collapse
Tekniumae2953ef0175
diff --git a/agent/display.py b/agent/display.pyindex f289da9df63..598553bfae4 100644--- a/agent/display.py+++ b/agent/display.py@@ -552,15 +552,14 @@ def build_tool_label(tool_name: str, args: dict, max_len: int | None = None) ->def _resolved_path(path: str) -> Path:"""Resolve a possibly-relative filesystem path against the current cwd."""- candidate = Path(os.path.expanduser(path))- return candidate if candidate.is_absolute() else Path.cwd() / candidate+ return Path.cwd() / Path(os.path.expanduser(path)) # a `/` with an absolute rhs keeps the rhsdef _snapshot_text(path: Path) -> str | None:"""Return UTF-8 file content, or None for missing/unreadable files."""try:return path.read_text(encoding="utf-8")- except (FileNotFoundError, IsADirectoryError, UnicodeDecodeError, OSError):+ except (UnicodeDecodeError, OSError): # FileNotFoundError/IsADirectoryError are OSErrorsreturn None@@ -853,8 +852,7 @@ class KawaiiSpinner:def start(self):if self.running:return- self.running = True- self.start_time = time.time()+ self.running, self.start_time = True, time.time()self.thread = threading.Thread(target=self._animate, daemon=True)self.thread.start()diff --git a/agent/error_surface.py b/agent/error_surface.pyindex 666dce3145e..1c6532f708b 100644--- a/agent/error_surface.py+++ b/agent/error_surface.py@@ -90,9 +90,8 @@ def _disk_full(candidate: Any) -> bool:def _result_layer(reason: str, error_text: str, provider: str) -> str:- layer = _REASON_TO_LAYER.get(reason)- if layer is not None:- return layer+ if reason in _REASON_TO_LAYER:+ return _REASON_TO_LAYER[reason]if reason in _TRANSPORT_REASONS and _is_custom_endpoint(provider):return LAYER_ENDPOINTreturn LAYER_STREAMING if _looks_like_stream_drop(error_text) else LAYER_PROVIDER@@ -117,11 +116,9 @@ def build_error_surface_from_result(result: Any, provider: str = "", model: strreturn _surface(LAYER_DISK, "disk_full", False, provider, model)if result.get("billing_block") or reason in ("billing", "billing_unverified"):return _surface(LAYER_BILLING, reason or "billing", False, provider, model)- if not reason:- # Failed result without a classified reason (legacy paths).- if _looks_like_stream_drop(error_text):- return _surface(LAYER_STREAMING, "stream_drop", True, provider, model)- return _surface(LAYER_PROVIDER, "unknown", True, provider, model)+ if not reason: # failed result without a classified reason (legacy paths)+ drop = _looks_like_stream_drop(error_text)+ return _surface(LAYER_STREAMING if drop else LAYER_PROVIDER, "stream_drop" if drop else "unknown", True, provider, model)# Prefer the classifier's own verdict (``failure_retryable``); the# reason-set fallback covers older results.retryable = result.get("failure_retryable")diff --git a/agent/i18n.py b/agent/i18n.pyindex 4fe61acf0d1..02f0c97036a 100644--- a/agent/i18n.py+++ b/agent/i18n.py@@ -98,15 +98,14 @@ def _load_catalog(lang: str) -> dict[str, str]:flat: dict[str, str] = {}if not path.is_file():logger.debug("i18n catalog missing for %s at %s", lang, path)- else:- try:- import yaml- with path.open("r", encoding="utf-8") as f:- raw = yaml.safe_load(f) or {}- except Exception as exc:- logger.warning("Failed to load i18n catalog %s: %s", path, exc)- else:- _flatten_into(raw, "", flat)+ return _cache_catalog(lang, flat)+ try:+ import yaml+ with path.open("r", encoding="utf-8") as f:+ _flatten_into(yaml.safe_load(f) or {}, "", flat)+ except Exception as exc:+ logger.warning("Failed to load i18n catalog %s: %s", path, exc)+ flat = {}return _cache_catalog(lang, flat)