client.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """GitHub Copilot CLI (``copilot --acp --stdio``) client: the generic ACP client plus Copilot's quirks."""
  2. from __future__ import annotations
  3. from typing import Any
  4. from agent.acp_client import ACPClient
  5. # Stderr fingerprint of the deprecated `gh copilot` extension. Require BOTH the product name
  6. # AND a deprecation marker: the NEW `@github/copilot` CLI legitimately mentions "copilot-cli".
  7. _DEPRECATION_REQUIRED = ("gh-copilot",)
  8. _DEPRECATION_MARKERS = ("has been deprecated", "no commands will be executed")
  9. _DEPRECATED_CLI_ERROR = (
  10. "Hermes ACP mode requires the NEW GitHub Copilot CLI (github.com/github/copilot-cli), but the binary it just "
  11. "spawned is the deprecated `gh copilot` extension.\n\n"
  12. "Install the new CLI:\n npm install -g @github/copilot\n # then verify with: copilot --help\n\n"
  13. "If `copilot` already resolves to the new CLI but you still see this,\npoint Hermes at it explicitly:\n"
  14. " export HERMES_COPILOT_ACP_COMMAND=/path/to/new/copilot\n\n"
  15. "Alternative: use the `copilot` provider (no ACP, hits the Copilot API\ndirectly with a Copilot subscription "
  16. "token) via `hermes setup`.\n\nOriginal error:\n"
  17. )
  18. def is_gh_copilot_deprecation_message(stderr_text: str) -> bool:
  19. """True iff stderr looks like the deprecated gh-copilot extension's banner."""
  20. lower = stderr_text.lower()
  21. return any(req in lower for req in _DEPRECATION_REQUIRED) and any(m in lower for m in _DEPRECATION_MARKERS)
  22. class CopilotACPClient(ACPClient):
  23. """ACP client for the GitHub Copilot CLI."""
  24. # Same launch spec as the copilot-acp profile's process_* fields (the fallback when a
  25. # caller passes no command/args).
  26. default_command = "copilot"
  27. default_args = ("--acp", "--stdio")
  28. command_env_vars = ("HERMES_COPILOT_ACP_COMMAND", "COPILOT_CLI_PATH")
  29. args_env_var = "HERMES_COPILOT_ACP_ARGS"
  30. marker_base_url = "acp://copilot"
  31. placeholder_model = "copilot-acp"
  32. label = "Copilot ACP"
  33. missing_command_hint = "Install GitHub Copilot CLI or set HERMES_COPILOT_ACP_COMMAND/COPILOT_CLI_PATH."
  34. # The CLI keeps its own login (Hermes never reads it); `copilot login` is its terminal sign-in command.
  35. auth_required_hint = "Run `copilot login` to sign in to the GitHub Copilot CLI."
  36. unsupported_transport_hint = (
  37. "Either install a CLI that ships with --acp support (e.g. `@github/copilot` late 2025+), or set "
  38. "HERMES_COPILOT_ACP_COMMAND / HERMES_COPILOT_ACP_ARGS to a working pair.")
  39. def model_entry_disabled(self, entry: dict[str, Any]) -> bool:
  40. """Copilot marks org-policy-disabled models with ``_meta.copilotEnablement: disabled``."""
  41. return str((entry.get("_meta") or {}).get("copilotEnablement") or "").strip().lower() == "disabled"
  42. def early_exit_error(self, stderr_text: str) -> str | None:
  43. return _DEPRECATED_CLI_ERROR + stderr_text if is_gh_copilot_deprecation_message(stderr_text) else None