From 212e248ef1bc92a88122bf14d03bf98d94b38f42 Mon Sep 17 00:00:00 2001 From: Alasdair Mostyn Date: Mon, 30 Mar 2026 16:02:28 +0100 Subject: [PATCH] Explain: custom agent paths --- explain/agents.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/explain/agents.py b/explain/agents.py index 9956cc7..37e4028 100644 --- a/explain/agents.py +++ b/explain/agents.py @@ -42,13 +42,23 @@ def find_binary(cls) -> Path | None: """ Find and return the path to the agent binary. + Checks the EXPLAIN_{AGENT}_PATH environment variable first (e.g. + EXPLAIN_CLAUDE_PATH, EXPLAIN_AMP_PATH), before falling back to a PATH lookup. + Returns: Path to the agent binary, or None if not found + + Raises: + FileNotFoundError: If the EXPLAIN_{AGENT}_PATH environment variable is set but the path + could not be found """ - if loc := shutil.which(cls.program_name): - return Path(loc) - else: - return None + env_var = f"EXPLAIN_{cls.name.upper()}_PATH" + program = os.environ.get(env_var) or cls.program_name + if loc := shutil.which(program): + return Path(loc).absolute() + if os.environ.get(env_var): + raise FileNotFoundError(f"{env_var} is set to {program!r} but it could not be found.") + return None @abstractmethod async def ask(self, question: str, port: int, tools: list[str]) -> str: