Skip to content

feat: integrate Hermes Agent as 5th coding CLI#136

Merged
datasciencemonkey merged 8 commits into
mainfrom
feat/hermes-agent-integration
Apr 27, 2026
Merged

feat: integrate Hermes Agent as 5th coding CLI#136
datasciencemonkey merged 8 commits into
mainfrom
feat/hermes-agent-integration

Conversation

@datasciencemonkey
Copy link
Copy Markdown
Owner

@datasciencemonkey datasciencemonkey commented Apr 18, 2026

Summary

Integrate Hermes Agent as the 5th coding CLI in CoDA, plus auth fixes for Hermes and Gemini.

Commits

  • feat: integrate Hermes Agent as 5th coding CLI — setup script, config generation, PAT rotation support, onboarding docs
  • fix: replace 135MB git clone with uv tool install — original setup timed out on Databricks Apps; now uses uv tool install from git URL
  • fix: post-setup token sync — prevents stale PAT when setup finishes after first rotation (race condition where _update_hermes() silently skipped missing config)
  • fix: Gemini CLI auth — removed quoted "bearer" in .env (Node.js dotenv included quotes in value); stripped stale GEMINI_API_KEY from terminal session env
  • chore: update default Gemini modeldatabricks-gemini-3-1-prodatabricks-gemini-2-5-pro

Test plan

Hermes Agent

  • /api/setup-status shows hermes step completing (not stuck/pending)
  • which hermes returns ~/.local/bin/hermes in a terminal session
  • cat ~/.hermes/config.yaml shows provider: custom + correct AI Gateway endpoint
  • hermes chat connects and can send/receive messages
  • After ~10 min (PAT rotation), cat ~/.hermes/config.yaml shows updated api_key: value
  • Launching hermes chat after rotation works without 403

Gemini CLI

  • gemini CLI starts without prompting for GEMINI_API_KEY / Vertex / GCA
  • cat ~/.gemini/.env shows GEMINI_API_KEY_AUTH_MECHANISM=bearer (no quotes)
  • env | grep GEMINI_API_KEY in terminal session returns empty (stripped from env)
  • Gemini uses databricks-gemini-2-5-pro model by default

Token rotation (all CLIs)

  • After first PAT rotation, check all config files have the new token:
    • ~/.claude/settings.jsonANTHROPIC_AUTH_TOKEN
    • ~/.codex/.envOPENAI_API_KEY
    • ~/.gemini/.envGEMINI_API_KEY
    • ~/.hermes/config.yamlapi_key: (both primary and fallback)
    • ~/.local/share/opencode/auth.jsonapi_key
  • All CLIs work after rotation without restart

Post-setup token sync

  • Deploy fresh app, create session immediately (before 10-min rotation)
  • All CLI configs should have valid token (not the stale boot token)

Adds Hermes Agent (github.com/NousResearch/hermes-agent) alongside Claude
Code, Codex, OpenCode, and Gemini CLI. Hermes is a Python-based multi-
provider AI CLI with tool-calling, persistent memory, and a rich skill
system — installed via its official installer into ~/.local/bin/hermes.

Integration points:
- setup_hermes.py: installs Hermes, writes ~/.hermes/config.yaml pointing
  at Databricks AI Gateway (/mlflow/v1) or /serving-endpoints fallback.
  Configures custom provider, fallback_providers chain (opus-4-7 ->
  opus-4-6 on 429/529/503), external skills dir shared with Claude Code,
  and MCP servers (deepwiki + exa + optional team-memory).
- app.py: adds hermes to setup_state steps, parallel_steps, and the
  _configure_all_cli_auth re-run loop.
- cli_auth.py: _update_hermes() rewrites api_key lines in
  ~/.hermes/config.yaml on PAT rotation (every 10m).
- app.yaml.template: HERMES_MODEL env var (default opus-4-7).
- CLAUDE.md / README.md / docs/deployment.md: documentation.

Usage after deploy:
  hermes chat            # interactive chat
  hermes --tui chat      # rich TUI
  hermes model           # select default model
  hermes mcp list        # list configured MCP servers
@datasciencemonkey datasciencemonkey self-assigned this Apr 18, 2026
The original setup_hermes.py cloned the full NousResearch/hermes-agent
repo (135MB) with a 180s timeout, which silently failed on Databricks
Apps. Switched to `uv tool install` from git URL — handles venv and
binary setup automatically. Also dropped the `matrix` extra (requires
native libolm).
When PAT rotation happens while a setup script is still installing
(e.g., Hermes takes minutes to install from git), the rotation's
update_cli_tokens() silently skips missing config files. The setup
script then writes config with the initial (now-revoked) token.

Fix: after all parallel setup completes, re-apply the current token
to all CLI configs. This ensures every config has the latest token
regardless of installation timing vs rotation timing.

Closes the race window that caused HTTP 403 on first Hermes launch.
Two bugs preventing Gemini CLI from authenticating:

1. setup_gemini.py wrote GEMINI_API_KEY_AUTH_MECHANISM="bearer" (with
   literal quotes). Node.js dotenv parses this as '"bearer"' — Gemini
   CLI expects 'bearer' without quotes, fails auth check, falls back
   to interactive prompt asking for credentials.

2. Terminal sessions inherited GEMINI_API_KEY from the parent process
   env, which goes stale after PAT rotation. Now stripped from shell
   env (like DATABRICKS_TOKEN) so Gemini CLI reads from ~/.gemini/.env
   which is kept current by cli_auth.py.
Updated in setup_gemini.py, setup_opencode.py, setup_hermes.py,
app.yaml, app.yaml.template, README.md, and deployment docs.
Gemini CLI has a workspace trust system that silently skips loading
.env files in untrusted directories (gemini-cli#20005). Terminal
sessions on Databricks Apps start in ~/projects/ which was never
trusted, so GEMINI_API_KEY from ~/.gemini/.env was never loaded.

Fix: write ~/.gemini/trustedFolders.json during setup to pre-trust
both ~/projects/ and ~/ so .env loading works from any directory.
Gemini CLI expects string enum values (TRUST_FOLDER, TRUST_PARENT,
DO_NOT_TRUST), not booleans. Using true caused:
  Invalid trust level "true" for path "..."
Hermes is installed via uv tool install into an isolated venv. The
mcp Python package (HTTP transport) wasn't included, so MCP servers
(DeepWiki, Exa) failed with "mcp.client.streamable_http not available."

Fix: add --with 'mcp>=1.2.0' to the uv tool install command.
@datasciencemonkey
Copy link
Copy Markdown
Owner Author

Testing Summary

All changes validated on Databricks Apps deployment:

Hermes Agent - Working end-to-end:

  • uv tool install completes successfully (replaced failing 135MB git clone)
  • MCP servers (DeepWiki, Exa) connect after adding mcp>=1.2.0 dependency
  • Config written correctly with AI Gateway endpoint
  • Token rotation updates api_key in config.yaml
  • Post-setup token sync prevents stale PAT on first launch

Gemini CLI - Fixed three-layer auth bug:

  • Removed quoted "bearer" in .env (dotenv parsed it with literal quotes)
  • Pre-trusted ~/projects/ in trustedFolders.json (Gemini silently skips .env in untrusted workspaces)
  • Used correct TRUST_FOLDER enum (not boolean true)
  • Stripped stale GEMINI_API_KEY from terminal session env
  • Default model updated to databricks-gemini-2-5-pro

Token rotation - All 5 CLIs confirmed receiving rotated tokens via cli_auth.py

Ready to merge.

@datasciencemonkey datasciencemonkey merged commit cdb5f40 into main Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant