Hermes Extension logo # Hermes Extension **A ChatGPT-style side panel for your local [Hermes Agent](https://github.com/NousResearch/hermes-agent) gateway.** No build step Β· No frameworks Β· No content scripts [![Manifest](https://img.shields.io/badge/Manifest_V3-google_chrome-blue?style=flat-square&logo=googlechrome&logoColor=white)](https://developer.chrome.com/docs/extensions/develop/migrate) [![Min Chrome](https://img.shields.io/badge/Chrome-114%2B-4285F4?style=flat-square&logo=googlechrome&logoColor=white)](https://www.google.com/chrome/) [![License](https://img.shields.io/badge/License-MIT-green?style=flat-square)](README.md#license)
--- ## What is this? A tiny Chrome/Edge extension that puts a ChatGPT-clean chat panel in your browser's side panel and talks to a **local Hermes Agent gateway** over plain HTTP + SSE. The whole extension is **vanilla HTML/CSS/JS with no build step** β€” the client is `sidepanel.js` plus a small, node-testable `renderer.js`. It was intentionally kept lean so it's easy to read, audit, and maintain (even for weaker coding models πŸ˜‰). ## See it in action Hermes Extension in action ## Architecture ![How Hermes Extension fits together](docs/architecture.svg) The panel is a pure HTTP client of the local **Hermes Gateway** (`127.0.0.1:8642`). For media it talks to the local **media bridge** (`8643`), and for browser use it drives the **browser-use hub** (`8645`). ### Drive your real browser (MCP) The extension exposes **in-browser browser use** to the agent: through `browser-mcp.py` β€” an MCP server Hermes connects to β€” the agent can **see and operate your actual open tabs** (your real profile, cookies, and logins): snapshots with element refs, click/type/fill/navigate/scroll, screenshots, console & network logs, even file uploads. You can watch it drive the page live in the side panel, or let it attach tabs on its own and auto-release them when done. Full details below in [Browser use β€” live-browser bridge](#browser-use--live-browser-bridge-b1b4). ## Features | Feature | Status | |---------|--------| | Side panel chat UI (ChatGPT-clean) | βœ… | | Paste gateway URL + API key | βœ… | | Create session on first message | βœ… | | **`+` creates the session server-side immediately** | βœ… | | Stream replies via SSE | βœ… | | Markdown rendering (marked + DOMPurify) | βœ… | | LaTeX math (KaTeX: `$…$`, `$$…$$`, `\(…\)`, `\[…\]`) | βœ… | | Local media (`IMAGE:` / `MEDIA:` / `@image:` / `@media:` lines; img/audio/video) | βœ… | | Image paste + click-to-preview + downscale (`@image:data:…`) | βœ… | | `@url:` link attachments | βœ… | | Media bridge (local files, zero browser config) | βœ… | | Version badge in footer | βœ… | | Live updates from other clients (~3 s polling) | βœ… | | Session list + switch | βœ… | | Load message history | βœ… | | New chat | βœ… | | Model picker | βœ… | | Live-browser MCP bridge (drive your real tabs) | βœ… B1–B4 | | Themes / more tools | ❌ later | Only **4 gateway endpoints** are used: 1. `POST /api/sessions` β€” create 2. `POST /api/sessions/{id}/chat/stream` β€” SSE stream 3. `GET /api/sessions/{id}/messages` β€” history 4. `GET /api/sessions` β€” list Plus `GET /v1/health` for the connection test. ## Prerequisites 1. **Hermes Agent** installed and gateway running: ```bat hermes gateway status ``` API server must be on (default `http://127.0.0.1:8642`). 2. **API key** from either: - `~/.hermes/.env` β†’ `API_SERVER_KEY=…` - or `config.yaml` top-level `api_server.key` (there is a second `platforms.api_server` block that is usually `enabled: false` β€” ignore it) ## Install (Chrome / Edge) 1. Make sure the Hermes gateway is up: ```bat hermes gateway status hermes gateway start ``` 2. Open `chrome://extensions` (or `edge://extensions`) 3. Enable **Developer mode** 4. **Load unpacked** β†’ select this folder 5. Pin **Hermes Extension**, click the icon (or `Alt+H`) 6. **Local media**: Edge cannot load `file://` subresources from extension pages β€” even with "Allow access to file URLs" on (Chrome tolerates it, Edge does not). The reliable path is the **media bridge** in step 7; the toggle is no longer required for images. 7. **Media bridge (recommended, zero browser config):** double-click `media-bridge.bat` (keep the console window open; Python 3 required) β€” the panel probes `http://127.0.0.1:8643` at boot and serves local media through it directly. See "Media bridge" below. 8. Get your API key β€” on Windows, double-click `Copy_API_Key.cmd` β†’ paste into Settings β†’ **Test connection** β†’ **Save** ## Layout (no build) ``` manifest.json MV3 β€” sidePanel + storage + debugger + tabs + alarms background.js sidePanel behavior + WS client + chrome.debugger relay + tabs control sidepanel.html shell (+ browser chip/panel, quick menu) sidepanel.css light ChatGPT-like theme + markdown styles sidepanel.js client: SSE parser, rendering pipeline, polling, paste (+ browser UI) renderer.js pure markdown/media/math extraction (node-testable) test_renderer.js unit tests β€” run: node test_renderer.js test_browser_mcp.py browser-mcp unit tests β€” run: py -3.14 -B test_browser_mcp.py browser-mcp.py browser-use hub: MCP stdio server + WS listener on 8645 (B1–B4 tools) media-bridge.py optional local media server (127.0.0.1:8643, stdlib-only) media-bridge.bat launcher for media-bridge.py PROTOCOL.md live-browser bridge wire protocol (B1–B4) vendor/ pinned: marked 12.0.2, DOMPurify 3.1.6, KaTeX 0.16.11 (+ fonts) icons/ 16/32/48/128 docs/ screen-recording.gif, architecture.svg (README images) Copy_API_Key.cmd copies API_SERVER_KEY to clipboard README.md ``` ## How the gateway works (short) Hermes ships a plain **HTTP REST + SSE** server. The extension is only an HTTP client. **Auth:** `Authorization: Bearer ` **Streaming contract** (`POST …/chat/stream` β†’ `text/event-stream`): | Event | Meaning | |-------|---------| | `run.started` | turn began (`run_id`) | | `assistant.delta` | text chunk (`data.delta`) | | `assistant.completed` | final text (`data.content`) | | `run.completed` | done (+ runtime metadata) | | `tool.*` / `hermes.tool.progress` | tool activity (ignored in v1) | | `error` | failure | | `: keepalive` | ignore | Request body used by v1: ```json { "message": "…" } ``` (The bulky extension also sends `model`, `provider`, `require_model_lock`, `selected_skills`. v1 lets the gateway use its default model.) ## Rendering & live updates **Rendering** (applied to every message, user or assistant): - Markdown via vendored [marked](https://github.com/markedjs/marked), sanitized with [DOMPurify](https://github.com/cure53/DOMPurify) before anything enters the DOM. GFM tables, task lists, fences, blockquotes, links, images, etc. - LaTeX math: `$…$` / `\(…\)` inline, `$$…$$` / `\[…\]` display β€” typeset with vendored [KaTeX](https://katex.org). Escaped `\$` and money-like `$5` stay literal; math inside fenced/indented code blocks is never touched. - **Local images**: content lines like `IMAGE:C:\Users\...\image.png`, `MEDIA:…` and the desktop app's `@image:…` / `@media:…` attachment lines become media in the chat β€” images (`png/jpg/gif/webp/bmp/avif/svg`) as inline ``, audio (`mp3/ogg/wav/m4a/aac/flac/opus`) and video (`mp4/webm/mov/mkv`) as inline players. Windows/POSIX absolute paths are loaded **bridge-first** (`http://127.0.0.1:8643` when the bridge is up), falling back to `file://`, then to a clickable path link with an actionable hint. `data:` (pasted) and `http(s)` URLs bypass the bridge entirely. - **Pasted images**: paste (or drag-drop) an image into the composer β†’ thumbnail chips β†’ click to preview (`Esc`/backdrop closes). On send each image is downscaled (longest side ≀1024 px, JPEG q0.80 / PNG for transparency) and **saved to a temp file via the media bridge**, which is sent as an `@image:C:\...` path line β€” the agent's vision reads the file itself, so there's no data-URL size limit to hit. If the bridge isn't running, the fallback is a capped (~100 KB) `@image:data:image/...` URL instead. Either way the message renders back as an inline image via the bridge. The bridge must be running for the primary path (see "Media bridge"). - **`@url:` link attachments** (desktop "Attached Context", e.g. `@url:`https://example.com/``, backticks optional) become clickable links, inline or standalone. - Streaming deltas re-render only the last message, throttled to ~60 ms, and autoscroll while the reply grows. **New chat** β€” the `+` button creates the session server-side immediately (it shows up in the session dropdown), instead of silently waiting for the first message. If creation fails, the panel says so and falls back to creating on first send. **Version badge** β€” the footer shows `v Β· ` so you can confirm the loaded build (unpacked extensions only pick up code changes after a reload). ## Media bridge `media-bridge.py` (stdlib-only) is the **primary** way local media reaches the panel β€” Edge can't load `file://` subresources from extension pages (verified on Edge 151, even with the file-URL toggle on). It serves files at `http://127.0.0.1:8643/media?path=`: - Run it: double-click `media-bridge.bat` (or `python media-bridge.py`) β€” keep the window open. Auto-start via the Windows **Startup** folder is recommended (`shell:startup` β†’ shortcut to `media-bridge.bat`); the panel probes the bridge at boot and uses it directly when it's up. - Serves only files under `%APPDATA%\Hermes`, your home directory, and `/tmp`; everything else gets a `403`. - Fallback chain per item: **bridge** β†’ `file://` β†’ hint block ("start media-bridge.bat…"). Nothing breaks if the bridge isn't running β€” `file://` then kicks in (works in Chrome; in Edge you'll see the hint block instead). **Verification note:** `media-bridge.py` sets `sys.dont_write_bytecode = True` and `media-bridge.bat` runs `python -B`, so no `__pycache__/` ever appears β€” Chrome/Edge refuse to load an unpacked extension whose root contains a `_`-prefixed name (e.g. `__pycache__`). Always syntax-check it WITHOUT `py_compile`: ```bat python -B -c "import ast; ast.parse(open('media-bridge.py', encoding='utf-8').read()); print('OK')" ``` If you ever do run `python -m py_compile`, you MUST `rm -rf __pycache__` afterward and confirm it's gone (`ls -a | findstr /B _` must be empty). ## Live updates **Live updates** β€” the gateway has no push endpoint for sessions other clients wrote to, so the panel polls while it is visible and idle: - Every **3 s**, a cheap session-list request compares the active session's `message_count`; only when it changes is the full history fetched and reconciled by content fingerprint. - Polling pauses while the panel is hidden, while settings are open, or while a stream is in progress, and never drops local messages (a 6 s post-stream grace plus a 30 s stale-limit guard a just-streamed message from blinking out). - Chat in the desktop app and the message appears in the panel within ~3 s, no reload needed. - **Run control** (gateway `/v1/runs` API): the Send/Stop button doesn't just drop the SSE stream β€” it POSTs `/v1/runs/{run_id}/stop` (the `run_id` rides on every stream event), so the turn is genuinely cancelled server-side instead of finishing and re-appearing via the poll. Panel slash commands: `/queue ` (held in a queue strip above the composer, auto-sent when the run finishes; sends immediately when idle), `/steer ` (injected into the running turn after its next tool call; falls back to queue on a 409, matching the CLI), and `/stop`. These appear under "Panel commands" in the `/` skills menu and win over sending on Enter. ## Browser use β€” live-browser bridge (B1–B4) The extension can drive your **real** open tabs (actual profile, cookies, logins) via a local companion server β€” the browser-use layer exposed to Hermes as an **MCP server**. B1 = transport + pairing + attach UI; B2–B4 add the observe/act tools (snapshot with refs, click/type/fill, navigate, screenshots, console/network buffers, tab management). How it fits together: | Piece | Role | |---|---| | `browser-mcp.py` | MCP server (stdio, for Hermes) + WebSocket hub on `ws://127.0.0.1:8645` | | `background.js` | extension SW: WS client, pairing token, `chrome.debugger` attach/relay | | sidepanel | status chip + **agent-session card** (driving / idle / auto-release countdown), Disconnect kill switch, Advanced (manual tab attach, reset pairing) | **Setup:** ```bat py -3.14 -m pip install --user fastmcp websockets ``` - With the Hermes registration below, **Hermes spawns `browser-mcp.py` itself** β€” no console window needed. `browser-mcp.bat` (clears `PYTHONPATH`, which this machine's env points at the Hermes venv whose 3.11-built `pydantic_core` breaks Python 3.14 imports, and runs `py -3.14 -u browser-mcp.py`) is only for standalone testing without Hermes β€” never run both at once (one hub on port 8645). Loopback only either way. - **Pairing is TOFU, one slot per browser**: the first extension `hello` from each browser (Chrome / Edge / Chromium) pins that browser's token to `.live-browser-token` (JSON map; legacy single-token files migrate to a `*` slot). A slot only re-pins on a hello carrying `rotate: true` (sidepanel "Reset pairing" β€” recovers a 4401 lockout). To wipe all pins: `browser-mcp.bat --reset-pairing`, then restart. Env `LIVE_BROWSER_TOKEN` pins `*` for every browser and disables TOFU. - Hermes-side registration (`~/.hermes/config.yaml` β†’ `mcp_servers`): ```yaml mcp_servers: live_browser: command: "py" args: ["-3.14", "-u", "C:\\projects\\browser-extensions\\hermes-extension\\browser-mcp.py"] # Replace with your actual checkout path if you cloned elsewhere. env: PYTHONPATH: "" timeout: 120 connect_timeout: 60 ``` Tools register as `mcp_live_browser_browser_*` (Hermes namespaces MCP tools `mcp__`): attach_status, attach, navigate, snapshot, find, click, drag, type, fill, press, hover, scroll, select, check, uncheck, back, forward, evaluate, wait, screenshot, tabs, upload_file, console, network. `browser_click` also takes viewport coords (`'350,120'` β€” canvas, charts); `browser_drag` drives sliders and drag-and-drop UIs (ref, selector, or coords per endpoint); `browser_press` takes combos (`ctrl+a`, `shift+tab`); `browser_scroll(target, direction)` wheel-scrolls INSIDE an element's scrollable container (dropdowns, modals). After config changes run `/reload-mcp` in Hermes (or restart Hermes). - Wire protocol: see [PROTOCOL.md](PROTOCOL.md). - Debugger conflicts: a tab open in DevTools can't be attached (`TAB_BUSY`) β€” close DevTools on that tab or pick another. - **Agent attaches tabs itself:** `browser_attach()` (focused tab), `browser_tabs(action="list")` then `browser_attach(tabId=…)`, or `browser_attach_status` (auto-attaches). Sidepanel picker is optional. - **The "started debugging this browser" banner is demand-only:** the debugger attaches solely when a tool call (or a sidepanel Attach click) asks for it β€” never on pairing, tab switches, or page loads β€” and it auto-releases ~3 min after the last tool call (the banner disappears; the next tool call re-attaches the focused tab). Hitting Cancel on the banner therefore sticks until the next tool call instead of being undone instantly. Protocol detail: [PROTOCOL.md](PROTOCOL.md) "Attach lifecycle". **Scope:** CDP observe/act surface (snapshot, click/drag/type/fill, scroll, navigate, tabs attach, screenshot, upload_file, console/network) over the extension debugger bridge. **Verification note:** `browser-mcp.py` sets `sys.dont_write_bytecode = True`, and `python -m py_compile` writes `__pycache__/` into the extension root (which Chrome/Edge refuse to load) β€” run compile checks with `PYTHONPYCACHEPREFIX` pointing outside the repo, or delete `__pycache__` afterwards (same rule as `media-bridge.py`). ## Troubleshooting | Symptom | Fix | |---------|-----| | "Invalid gateway API key" (401) | Copy `API_SERVER_KEY` from `%LOCALAPPDATA%\hermes\.env` (Windows) or `~/.hermes/.env` β€” not a random key. `Copy_API_Key.cmd` now checks both locations. | | Connection refused | `hermes gateway start` (or restart the scheduled task) | | Health OK but sessions 401 | Key mismatch between `.env` and running gateway process β€” `hermes gateway restart` after changing `.env` | | Health OK but sessions 403 | CORS Origin rejected. Extension `Origin: chrome-extension://` not in `API_SERVER_CORS_ORIGINS`. Run `powershell -ExecutionPolicy Bypass -File scripts/sync_cors.ps1` (pinned ID `efhcbfjhccbdcglgdhgbnikcnffcmhpb` from `manifest.json:key`) then `hermes gateway restart`. Verify with `curl -H "Origin: chrome-extension://" -H "Authorization: Bearer KEY" http://127.0.0.1:8642/api/sessions?limit=1` | | Create session failed (403) | Two causes: (1) Folder rename without `manifest.json:key` β†’ unpacked ID changed β†’ `chrome.storage.local` wiped β†’ API key missing. Now pinned to `efhcbfjhccbdcglgdhgbnikcnffcmhpb`. Re-run `Copy_API_Key.cmd`, paste in Settings β†’ Test connection β†’ Save. (2) CORS 403 as above β€” `scripts/sync_cors.ps1` then `hermes gateway restart`. | | Create session failed (401) | Invalid key β€” re-copy from correct env file | | Empty replies | Check Hermes logs; model backend may be down | | Local images render as path links β€” `local file β€” start media-bridge.bat…` (e.g. `%APPDATA%\Hermes\composer-images\...png`) | Bridge not running. `media-bridge.py` is required for local files (`%APPDATA%\Hermes`, `~`, `/tmp`, `C:\projects` only). Run `media-bridge.bat` and keep window open, then reload panel. Verify: `curl http://127.0.0.1:8643/media?path=C:\Users\...\image.png` should return 200. `file://` fallback is blocked in MV3 (Edge always, Chrome without toggle). | | Local image 403 `path outside allowed roots` | File outside allowlist roots β€” move under `%APPDATA%\Hermes` or home dir | | Chip stuck red / tools return `TIMEOUT` even though the hub should be up | A shadow listener can hold the port while `browser-mcp.py` is down (e.g. the Hermes gateway binds `0.0.0.0:8644`; the extension then "connects" to the wrong peer). The extension now treats a connection as usable only after the hub's `hello-ack` β€” a missing ack means close + backoff, so the bridge recovers when the real hub returns. Verify with `netstat -ano \| findstr :8645` and restart `browser-mcp.bat` | | Extension stuck in a 4401 pairing loop (lockout) | Sidepanel β†’ Browser β†’ **Reset pairing** β€” wipes the stored token and re-pins this browser's slot with a fresh one (`rotate:true` hello) | Probe from a terminal (replace `KEY`): ```bat curl -s -H "Authorization: Bearer KEY" http://127.0.0.1:8642/v1/health curl -s -H "Authorization: Bearer KEY" http://127.0.0.1:8642/api/sessions?limit=1 ``` ## License MIT β€” see [LICENSE](LICENSE).