-
Notifications
You must be signed in to change notification settings - Fork 154
feat: Add OpenCode and Hermes launchers (with Windows support) #450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hyeonggyu
wants to merge
4
commits into
NVIDIA-NeMo:main
Choose a base branch
from
hyeonggyu:feature/hermes-opencode-launchers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
83ca7f0
feat(launchers): add OpenCode and Hermes launchers
hyeonggyu 2848438
feat(launchers): support Windows environments
hyeonggyu 793866c
Merge origin/main into feature/hermes-opencode-launchers
hyeonggyu 15cf262
style: fix trailing newline in test file
hyeonggyu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,202 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Run Hermes through an in-process native Switchyard server. | ||
|
|
||
| Hermes resolves its endpoint through the same environment overrides other | ||
| providers honour: ``OPENROUTER_BASE_URL`` overrides the upstream base URL and | ||
| ``OPENROUTER_API_KEY`` provides the bearer token. The launcher points both at | ||
| the local Switchyard proxy, selects the route through ``--model`` and | ||
| ``--provider custom``, and launches ``hermes`` against it. No change is made to | ||
| the user's Hermes config (~/.hermes/config.yaml). | ||
| """ | ||
|
|
||
| import logging | ||
| import os | ||
| import shutil | ||
| import subprocess | ||
| from pathlib import Path | ||
|
|
||
| from switchyard.cli.launchers.launcher_runtime import ( | ||
| banner_pause, | ||
| configure_debug_file_logging, | ||
| is_executable_file, | ||
| is_windows_batch_shim, | ||
| print_ready_banner, | ||
| print_startup_failure, | ||
| silence_launch_loggers, | ||
| stdin_is_tty, | ||
| wait_for_proxy_ready, | ||
| ) | ||
| from switchyard.cli.launchers.live_stats_footer import LiveStatsFooter | ||
| from switchyard.cli.launchers.native_server import NativeServer | ||
| from switchyard.cli.launchers.proxy_health_monitor import ProxyHealthMonitor | ||
| from switchyard.cli.launchers.session_summary import print_session_summary | ||
| from switchyard.cli.launchers.shell_tui import ShellTUI | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| _READY_TIMEOUT_S = 10.0 | ||
| _EXIT_BINARY_NOT_FOUND = 127 | ||
| _EXIT_SIGINT = 130 | ||
| _API_KEY_PLACEHOLDER = "switchyard" | ||
|
|
||
|
|
||
| def _find_hermes_binary() -> str | None: | ||
| """Locate the ``hermes`` executable.""" | ||
| path_hit = shutil.which("hermes") | ||
| if path_hit: | ||
| return path_hit | ||
| for candidate in ( | ||
| Path.home() / ".local" / "bin" / "hermes", | ||
| Path.home() / ".hermes" / "hermes-agent" / "venv" / "bin" / "hermes", | ||
| ): | ||
| if is_executable_file(candidate): | ||
| return str(candidate) | ||
| return None | ||
|
|
||
|
|
||
| def _wait_ready(port: int, timeout_s: float = _READY_TIMEOUT_S) -> bool: | ||
| """Probe ``GET /health`` until HTTP 200 or timeout.""" | ||
| return wait_for_proxy_ready(port, timeout_s=timeout_s) | ||
|
|
||
|
|
||
| def _hermes_env(port: int) -> dict[str, str]: | ||
| """Build the env-var overrides that route Hermes through our proxy. | ||
|
|
||
| * ``OPENROUTER_BASE_URL`` — our proxy URL. Hermes consults this override | ||
| when resolving the endpoint for ``--provider custom``. | ||
| * ``OPENROUTER_API_KEY`` — opaque token for the local proxy. | ||
| """ | ||
| env = os.environ.copy() | ||
| env["OPENROUTER_BASE_URL"] = f"http://127.0.0.1:{port}/v1" | ||
| env["OPENROUTER_API_KEY"] = _API_KEY_PLACEHOLDER | ||
| # Never let Hermes phone home to update channels during a proxied run. | ||
| env.setdefault("HERMES_DISABLE_AUTOUPDATE", "1") | ||
| return env | ||
|
|
||
|
|
||
| def _hermes_command(hermes_bin: str, hermes_args: list[str], model: str) -> list[str]: | ||
| """Build the Hermes command for the local proxy. | ||
|
|
||
| ``--provider custom -m <model>`` are global Hermes flags, so they always | ||
| lead. Forwarded arguments are Hermes' own command — an explicit subcommand | ||
| (``chat -q ...``, one-shot ``-z ...``, ``resume``, ...) plus any flags — | ||
| passed through verbatim. With nothing forwarded, default to the interactive | ||
| ``chat`` surface. | ||
| """ | ||
| routing = ["--provider", "custom", "-m", model] | ||
| if not hermes_args: | ||
| return [hermes_bin, "chat", *routing] | ||
| return [hermes_bin, *routing, *hermes_args] | ||
|
|
||
|
|
||
| def _supervise_hermes( | ||
| hermes_bin: str, | ||
| hermes_args: list[str], | ||
| model: str, | ||
| port: int, | ||
| ) -> int: | ||
| """Run Hermes and return its exit code.""" | ||
| try: | ||
| result = subprocess.run( | ||
| _hermes_command(hermes_bin, hermes_args, model), | ||
| env=_hermes_env(port), | ||
| check=False, | ||
| shell=is_windows_batch_shim(hermes_bin), | ||
| ) | ||
| return result.returncode | ||
| except KeyboardInterrupt: | ||
| return _EXIT_SIGINT | ||
|
|
||
|
|
||
| def _start_native_server(config: Path) -> NativeServer: | ||
| """Start the native server; kept separate for supervision tests.""" | ||
| return NativeServer(config) | ||
|
|
||
|
|
||
| def _run_hermes_with_switchyard( | ||
| config: Path, | ||
| display_model: str, | ||
| hermes_args: list[str], | ||
| ) -> int: | ||
| """Host a native deployment and run Hermes against it.""" | ||
| hermes_bin = _find_hermes_binary() | ||
| if hermes_bin is None: | ||
| logger.error( | ||
| "hermes binary not found. Install it with " | ||
| "`curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash`, " | ||
| "or place it on your PATH." | ||
| ) | ||
| return _EXIT_BINARY_NOT_FOUND | ||
|
|
||
| silence_launch_loggers(local_logger=logger) | ||
| log_path = configure_debug_file_logging(display_model=display_model) | ||
| server = _start_native_server(config) | ||
| resolved_port = server.port | ||
| stats = server.stats | ||
| strategy_summary = f"config → {config.name}" | ||
|
|
||
| try: | ||
| if not _wait_ready(resolved_port): | ||
| print_startup_failure( | ||
| port=resolved_port, | ||
| timeout_s=_READY_TIMEOUT_S, | ||
| log_path=log_path, | ||
| ) | ||
| return 1 | ||
|
|
||
| logger.info("proxy ready on port %d", resolved_port) | ||
| print_ready_banner( | ||
| port=resolved_port, | ||
| display_model=display_model, | ||
| log_path=log_path, | ||
| strategy_summary=strategy_summary, | ||
| routes=[display_model], | ||
| default_route=display_model, | ||
| ) | ||
| if stdin_is_tty(): | ||
| banner_pause() | ||
|
|
||
| if stdin_is_tty(): | ||
| footer = LiveStatsFooter( | ||
| stats, | ||
| display_model, | ||
| ProxyHealthMonitor(resolved_port), | ||
| strategy_label="config", | ||
| ) | ||
| return ShellTUI( | ||
| command=_hermes_command(hermes_bin, hermes_args, display_model), | ||
| footer_fn=footer.as_footer_fn(), | ||
| footer_height=lambda: footer.height, | ||
| env=_hermes_env(resolved_port), | ||
| ).run() | ||
|
|
||
| return _supervise_hermes( | ||
| hermes_bin, | ||
| hermes_args, | ||
| display_model, | ||
| resolved_port, | ||
| ) | ||
| finally: | ||
| print_session_summary(stats) | ||
| server.close() | ||
|
|
||
|
|
||
| def launch_hermes_config( | ||
| config: Path, | ||
| model: str, | ||
| hermes_args: list[str], | ||
| ) -> int: | ||
| """Run Hermes against a native server TOML deployment.""" | ||
| _quiet_launch_loggers() | ||
| return _run_hermes_with_switchyard( | ||
| config, | ||
| display_model=model, | ||
| hermes_args=hermes_args, | ||
| ) | ||
|
|
||
|
|
||
| def _quiet_launch_loggers() -> None: | ||
| """Keep dependency chatter out of Hermes' terminal UI.""" | ||
| silence_launch_loggers(local_logger=logger) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Update the launcher-path overview.
The sentence at Line 34 still lists only Claude Code, Codex CLI, and OpenClaw. Add OpenCode and Hermes so the Quick Start description matches the new commands at Lines 60-61.
🤖 Prompt for AI Agents