Skip to content

Commit c122e64

Browse files
authored
Merge pull request #109 from undoio/explain-custom-agent-path
Explain: custom agent paths
2 parents e30e0bd + 212e248 commit c122e64

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

explain/agents.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,23 @@ def find_binary(cls) -> Path | None:
4343
"""
4444
Find and return the path to the agent binary.
4545
46+
Checks the EXPLAIN_{AGENT}_PATH environment variable first (e.g.
47+
EXPLAIN_CLAUDE_PATH, EXPLAIN_AMP_PATH), before falling back to a PATH lookup.
48+
4649
Returns:
4750
Path to the agent binary, or None if not found
51+
52+
Raises:
53+
FileNotFoundError: If the EXPLAIN_{AGENT}_PATH environment variable is set but the path
54+
could not be found
4855
"""
49-
if loc := shutil.which(cls.program_name):
50-
return Path(loc)
51-
else:
52-
return None
56+
env_var = f"EXPLAIN_{cls.name.upper()}_PATH"
57+
program = os.environ.get(env_var) or cls.program_name
58+
if loc := shutil.which(program):
59+
return Path(loc).absolute()
60+
if os.environ.get(env_var):
61+
raise FileNotFoundError(f"{env_var} is set to {program!r} but it could not be found.")
62+
return None
5363

5464
@abstractmethod
5565
async def ask(self, question: str, port: int, tools: list[str]) -> str:

0 commit comments

Comments
 (0)