The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(agent): prompt_builder/plugin_llm/process_bootstrap pass-2 — inline _normalize_ref, fold snapshot read, proxy-env scan
Teknium123d962dc754
diff --git a/agent/plugin_llm.py b/agent/plugin_llm.pyindex a67d221414b..d084d465e22 100644--- a/agent/plugin_llm.py+++ b/agent/plugin_llm.py@@ -109,16 +109,12 @@ _OVERRIDE_FLAGS = ("allow_provider_override", "allow_model_override", "allow_age"allow_profile_override", "allow_task_override")-def _normalize_ref(raw: str) -> str:- return (raw or "").strip().lower()--def _coerce_allowlist(raw: Any) -> tuple[Optional[frozenset], bool]:"""YAML list → ``(frozenset_or_None, allow_any)``. A ``"*"`` entry sets``allow_any``; missing / non-list → ``(None, False)`` = no allowlist."""if not isinstance(raw, list):return None, False- normalized = [_normalize_ref(item) for item in raw if isinstance(item, str)]+ normalized = [item.strip().lower() for item in raw if isinstance(item, str)]return frozenset(item for item in normalized if item and item != "*"), "*" in normalized@@ -159,7 +155,7 @@ def _gate_ref_override(policy: _TrustPolicy, kind: str, requested: str) -> str:if not getattr(policy, f"allow_{kind}_override"):raise _denied(policy.plugin_id, f"override the {kind}", f"allow_{kind}_override")allowed = getattr(policy, f"allowed_{kind}s")- if not getattr(policy, f"allow_any_{kind}") and allowed is not None and _normalize_ref(requested) not in allowed:+ if not getattr(policy, f"allow_any_{kind}") and allowed is not None and requested.strip().lower() not in allowed:raise PluginLlmTrustError(f"Plugin {policy.plugin_id!r} {kind} override {requested!r} is not in "f"plugins.entries.{policy.plugin_id}.llm.allowed_{kind}s.")return requested.strip()diff --git a/agent/process_bootstrap.py b/agent/process_bootstrap.pyindex 64ceaeaee8c..3f0fae516f9 100644--- a/agent/process_bootstrap.py+++ b/agent/process_bootstrap.py@@ -269,11 +269,8 @@ class _SafeWriter:def _get_proxy_from_env() -> Optional[str]:"""First configured proxy URL from HTTPS_PROXY / HTTP_PROXY / ALL_PROXY (any case), or None."""- for key in ("HTTPS_PROXY", "HTTP_PROXY", "ALL_PROXY", "https_proxy", "http_proxy", "all_proxy"):- value = os.environ.get(key, "").strip()- if value:- return normalize_proxy_url(value)- return None+ keys = ("HTTPS_PROXY", "HTTP_PROXY", "ALL_PROXY", "https_proxy", "http_proxy", "all_proxy")+ return next((normalize_proxy_url(v) for k in keys if (v := os.environ.get(k, "").strip())), None)def _get_proxy_for_base_url(base_url: Optional[str]) -> Optional[str]:diff --git a/agent/prompt_builder.py b/agent/prompt_builder.pyindex 1d6892213ca..0889204a473 100644--- a/agent/prompt_builder.py+++ b/agent/prompt_builder.py@@ -59,11 +59,9 @@ def _find_hermes_md(cwd: Path) -> Optional[Path]:current = cwd.resolve()# No git root: cwd only — walking parents could pick up a file planted in /tmp, /home, etc.for directory in [current, *current.parents] if stop_at else [current]:- for name in (".hermes.md", "HERMES.md"):- if (directory / name).is_file():- return directory / name- if directory == stop_at:- break+ found = next((directory / n for n in (".hermes.md", "HERMES.md") if (directory / n).is_file()), None)+ if found or directory == stop_at:+ return foundreturn None@@ -247,7 +245,6 @@ TOOL_USE_ENFORCEMENT_GUIDANCE = ("user. Responses that only describe intentions without acting are not acceptable.")-# Model name substrings that trigger tool-use enforcement guidance.TOOL_USE_ENFORCEMENT_MODELS = ("gpt", "codex", "gemini", "gemma", "grok", "glm", "qwen", "deepseek")# Models that receive OPENAI_MODEL_EXECUTION_GUIDANCE when agent.execution_guidance is "auto" (agentic-eval@@ -739,9 +736,8 @@ def _run_backend_probe(env_type: str, terminal_tool) -> str:"""Execute the probe command inside a freshly built backend; "" when it yields nothing."""config = terminal_tool._get_env_config()# Mirrors tools/terminal_tool.py's live-command assembly (`_create_environment` is the factory).- image_key = _BACKEND_IMAGE_KEYS.get(env_type)env = terminal_tool._create_environment(- env_type=env_type, image=config.get(image_key, "") if image_key else "", cwd=config.get("cwd", ""),+ env_type=env_type, image=config.get(_BACKEND_IMAGE_KEYS[env_type], "") if env_type in _BACKEND_IMAGE_KEYS else "", cwd=config.get("cwd", ""),timeout=config.get("timeout", 180),ssh_config=terminal_tool._ssh_config_from_config(config) if env_type == "ssh" else None,container_config=({k: config.get(k, d) for k, d in _CONTAINER_CONFIG_DEFAULTS}@@ -812,10 +808,8 @@ def _local_host_hints() -> list[str]:def _remote_backend_hint(backend: str) -> str:"""Backend-only block for remote/sandbox backends (host info deliberately suppressed)."""- lead = (- f"Terminal backend: {backend}. Your `terminal`, `read_file`, `write_file`, `patch`, and "- f"`search_files` tools all operate inside "- )+ lead = (f"Terminal backend: {backend}. Your `terminal`, `read_file`, `write_file`, `patch`, and "+ f"`search_files` tools all operate inside ")probe = _probe_remote_backend(backend)if probe:return lead + (@@ -959,12 +953,9 @@ def _build_skills_manifest(skills_dir: Path) -> dict[str, list[int]]:def _load_skills_snapshot(skills_dir: Path) -> Optional[dict]:"""The disk snapshot if it exists, is current-version, and its manifest still matches."""- snapshot_path = _skills_prompt_snapshot_path()- if not snapshot_path.exists():- return Nonetry:- snapshot = json.loads(snapshot_path.read_text(encoding="utf-8"))- except Exception:+ snapshot = json.loads(_skills_prompt_snapshot_path().read_text(encoding="utf-8"))+ except Exception: # missing, unreadable or corrupt -> rebuildreturn Noneif (isinstance(snapshot, dict) and snapshot.get("version") == _SKILLS_SNAPSHOT_VERSIONand snapshot.get("manifest") == _build_skills_manifest(skills_dir)):@@ -979,10 +970,8 @@ def _build_snapshot_entry(skill_file: Path, skills_dir: Path, frontmatter: dict,org_id: str | None = Noneif len(parts) >= 3 and parts[0] == ORG_MIRROR_DIR_NAME:org_id, parts = parts[1], parts[2:]- if len(parts) >= 2:- skill_name, category = parts[-2], ("/".join(parts[:-2]) if len(parts) > 2 else parts[0])- else:- skill_name, category = skill_file.parent.name, "general"+ skill_name = skill_file.parent.name # == parts[-2] whenever a parent component exists+ category = "general" if len(parts) < 2 else "/".join(parts[:-2]) if len(parts) > 2 else parts[0]platforms = frontmatter.get("platforms") or []platforms = [platforms] if isinstance(platforms, str) else platformsentry = {@@ -1263,9 +1252,6 @@ def _build_skills_system_prompt_inner(return result-# Context files (SOUL.md, AGENTS.md, .cursorrules)--def _truncate_content(content: str, filename: str, max_chars: Optional[int] = None, context_length: Optional[int] = None,read_path: Optional[str] = None,