Skip to content

The agent that grows with you

fix(auth): keep relative external CLI command paths resolving from the launch cwd

Brooklyn Nicholson6db85489b22a
diff --git a/hermes_cli/auth.py b/hermes_cli/auth.py
index 488d69bd721..12547abc4fe 100644
--- a/hermes_cli/auth.py
+++ b/hermes_cli/auth.py
@@ -2151,13 +2151,15 @@ def _external_process_spec(
or str(getattr(profile, "process_command", "") or ""))
raw_args = os.getenv(args_env_var, "").strip() if args_env_var else ""
args = shlex.split(raw_args) if raw_args else list(getattr(profile, "process_args", ()) or [])
- resolved = None
- if command:
- from hermes_platform.resolver import locate_command
- from hermes_platform.resolver.known_dirs import user_local_bin
-
- found = locate_command(command, known_dirs=user_local_bin()).command
- resolved = found[0] if found else None
+ from hermes_platform.resolver import locate_command
+ from hermes_platform.resolver.known_dirs import user_local_bin
+ lookup = command
+ if os.sep in command or (os.altsep and os.altsep in command):
+ # An operator-configured relative path (./bin/copilot) means the launch cwd, as it did
+ # under shutil.which; anchor it so the resolver's absolute-only explicit check accepts it.
+ lookup = os.path.abspath(os.path.expandvars(os.path.expanduser(command)))
+ found = locate_command(lookup, known_dirs=user_local_bin()).command if command else ()
+ resolved = found[0] if found else None
if command and not resolved:
# A GUI/service launch (LaunchAgent, Desktop backend) has a bare PATH: probe Claude Code's
# install prefixes as the Anthropic adapter does.
diff --git a/tests/hermes_cli/test_external_process_auth_status.py b/tests/hermes_cli/test_external_process_auth_status.py
index ec00aa393b7..0281bfa4a9c 100644
--- a/tests/hermes_cli/test_external_process_auth_status.py
+++ b/tests/hermes_cli/test_external_process_auth_status.py
@@ -80,6 +80,60 @@ def test_external_process_status_finds_user_local_cli_outside_backend_path(
assert resolve_external_process_provider_credentials("copilot-acp")["command"] == str(cli)
+def test_external_process_status_resolves_relative_configured_path_from_cwd(
+ tmp_path, monkeypatch, _clean_copilot_env
+):
+ """An operator's relative command path keeps resolving against the launch cwd."""
+ bin_dir = tmp_path / "bin"
+ bin_dir.mkdir()
+ cli = bin_dir / ("copilot.exe" if os.name == "nt" else "copilot")
+ cli.write_text("", encoding="utf-8")
+ cli.chmod(0o755)
+ monkeypatch.chdir(tmp_path)
+ monkeypatch.setenv("PATH", str(tmp_path / "backend-bin"))
+ monkeypatch.setenv("HERMES_COPILOT_ACP_COMMAND", os.path.join(".", "bin", cli.name))
+
+ status = get_external_process_provider_status("copilot-acp")
+
+ assert status["configured"] is True
+ assert status["resolved_command"] == str(cli)
+ assert resolve_external_process_provider_credentials("copilot-acp")["command"] == str(cli)
+
+
[email protected]("preferred", ["claude-prefix", "user-local", "path", "explicit"])
+def test_external_process_claude_resolution_preserves_precedence(
+ tmp_path, monkeypatch, _clean_copilot_env, preferred
+):
+ """Generic discovery must retain Claude's extra prefixes and command precedence."""
+ candidates = {}
+ for name, directory in (
+ ("claude-prefix", tmp_path / ".claude" / "local"),
+ ("user-local", tmp_path / ".local" / "bin"),
+ ("path", tmp_path / "backend-bin"),
+ ("explicit", tmp_path / "configured-bin"),
+ ):
+ directory.mkdir(parents=True)
+ executable = directory / "claude"
+ executable.write_text("", encoding="utf-8")
+ executable.chmod(0o755)
+ candidates[name] = executable
+ if name == preferred:
+ break
+ monkeypatch.setenv("HOME", str(tmp_path))
+ monkeypatch.setenv("PATH", str(tmp_path / "backend-bin"))
+ monkeypatch.setenv(
+ "HERMES_COPILOT_ACP_COMMAND",
+ str(candidates[preferred]) if preferred == "explicit" else "claude",
+ )
+
+ status = get_external_process_provider_status("copilot-acp")
+
+ assert status["configured"] is True
+ assert status["resolved_command"] == str(candidates[preferred])
+ assert resolve_external_process_provider_credentials("copilot-acp")["command"] == str(candidates[preferred])
+
+
def test_external_process_status_rejects_wrong_auth_type():
# A provider that exists but is not external_process must be refused —
# the generic dispatcher relies on this guard.