Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 95 additions & 79 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,123 +1,142 @@
# @helloagentai/hermes

A bridge that lets HelloAgent users chat with their personal Hermes agent.
A bridge that lets HelloAgent users chat with their personal local agent
(Hermes, or any agent that speaks the agent-socket protocol).

## What this is

```
HelloAgent client (web / iOS)
│
▼ WebSocket, ha_* token
HelloAgent relay (Go)
HelloAgent server
│
▼ WebSocket, ha_* token (relay-side: this bridge looks like
┌────────────────────┐ an agent named e.g. @alice/hermes)
▼ WebSocket, ha_* token (this bridge looks like an agent
┌────────────────────┐ named e.g. @alice/hermes)
│ helloagent-hermes │
│ (this package) │
└────────────────────┘
│
▼ wschat protocol (JSON over WS, ws://127.0.0.1:8770)
Hermes gateway with wschat plugin
▼ agent-socket protocol (JSON over WS, ws://127.0.0.1:8770)
Local agent process (e.g. Hermes)
│
▼
Agent loop (LLM, tools, memory)
```

The bridge holds two things at once:

1. **A relay client** — authenticated via the HelloAgent SDK using a
long-lived `ha_*` agent token. This is how the user's HelloAgent app
sees the Hermes agent in their contact list.
2. **A wschat WebSocket server** — listens on `ws://127.0.0.1:8770` for the
Hermes `wschat` plugin to connect.
1. **A HelloAgent server client** — authenticated via the HelloAgent SDK
using a long-lived `ha_*` agent token. This is how the user's HelloAgent
app sees your agent in their contact list.
2. **An agent socket** — listens on `ws://127.0.0.1:8770` for one local
agent process to connect.

Inbound messages from the user flow relay → bridge → wschat → Hermes.
Hermes' streamed reply chunks flow back the other way and are forwarded
to the user as a streaming response on the relay's protocol.
Inbound messages flow HelloAgent server → bridge → agent. The agent's
streamed reply chunks flow back the other way as a streaming response to
the HelloAgent user.

## Auth

The pairing flow mirrors [`@helloagentai/openclaw`](https://www.npmjs.com/package/@helloagentai/openclaw). Three paths, identical UX:

1. **Browser PKCE OAuth** (default for `pair`) — opens a browser to
`<webUrl>/oauth/connect`, captures the redirect on a loopback server,
exchanges the code for an access token, calls `linkChannel()` to mint
a scoped `ha_*` agent token, persists creds.
2. **Device code** (`--device`) — for headless/CI machines. Print a
user code, the user approves it from any other browser.
3. **Manual token import** (`--token --relay-ws`) — paste an existing
`ha_*` token; we validate it with one WS handshake against the relay,
then persist.

> The relay's `channelProviders` map currently knows only `"openclaw"`, so
> internally we link as the `openclaw` provider for now. Functionally
> identical for the bridge — when the relay registers `"hermes"` as a
> provider this becomes a two-line change in
> [`auth/login-oauth.ts`](src/auth/login-oauth.ts) and
> [`auth/login-device.ts`](src/auth/login-device.ts).

Credentials are persisted at `~/.helloagent-hermes/credentials/<accountId>/creds.json`
with `chmod 0600`, atomic temp-file + rename, and a `.bak` of the prior
file. Override the state dir with `HA_HERMES_BRIDGE_DIR`.
> On Hermes' side the agent-socket protocol is currently exposed via a
> plugin called `wschat` (it implements this exact wire format). Future
> Hermes versions may rename it to match this rebrand.

## Quickstart

```bash
npm install -g @helloagentai/hermes
helloagent-hermes pair
```

# 1) Pair with HelloAgent
helloagent-hermes pair --agent-name jarvis
The CLI prompts you to paste an agent token:

# Or for a headless box:
helloagent-hermes pair --device --agent-name jarvis
```
Link this bridge to a HelloAgent account:

# Or to import an existing token:
helloagent-hermes pair --token ha_xxx \
--relay-ws wss://api.helloagent.cc/v1/ws
1. Open https://app.helloagent.cc/app/agents/new
2. Create an agent and copy its token (starts with "ha_")
3. Paste the token below

# 2) Start the bridge
helloagent-hermes run --port 8770
Token: ha_xxxxxxxxxxxxx

# 3) Tell Hermes to use it
# (assumes the Hermes wschat plugin is installed under ~/.hermes/plugins/wschat
# and platforms.wschat.enabled: true is set in ~/.hermes/config.yaml)
WSCHAT_URL=ws://127.0.0.1:8770 hermes gateway run
imported token for @alice/jarvis
✓ Connected to HelloAgent as @alice/jarvis.
You can now chat with your agent through the HelloAgent app or browser.
```

Now any HelloAgent user can DM `@<your-handle>/jarvis` and chat with Hermes.
Then in Hermes (with the `wschat` plugin installed at
`~/.hermes/plugins/wschat`), set `platforms.wschat.enabled: true` and the
plugin's URL to `ws://127.0.0.1:8770/agent` in `~/.hermes/config.yaml`,
and restart `hermes gateway`. Now any HelloAgent user can DM
`@<your-handle>/<your-agent-name>` and chat with your Hermes.

For non-interactive use (CI, scripting):

```bash
helloagent-hermes pair --token ha_xxxxxxxxxxxxx
```

## Auth

Pairing is one step: paste an `ha_*` agent token. The bridge validates it
with one WebSocket handshake against the HelloAgent server, persists it
to disk, and uses it from then on.

You create the agent (and get the token) on the web at
[`https://app.helloagent.cc/app/agents/new`](https://app.helloagent.cc/app/agents/new).
The web UI handles agent registration; this CLI just consumes the
resulting token.

Credentials persist at
`~/.helloagent-hermes/credentials/<accountId>/creds.json` with `chmod
0600`, atomic temp-file + rename, and a `.bak` of the prior file. Override
the state dir with `HA_HERMES_BRIDGE_DIR`.

## CLI

```
helloagent-hermes pair [--device | --token <T> --relay-ws <URL>]
[--agent-name <N>] [--api-url <URL>] [--web-url <URL>]
[--account <ID>]
helloagent-hermes run [--port <N>] [--host <H>] [--wschat-token <T>]
[--account <ID>]
helloagent-hermes pair [--token <T>] [--account <ID>] [--re-pair]
helloagent-hermes status
helloagent-hermes stop
helloagent-hermes logout [--account <ID>]
```

Environment variables:
`pair` pairs if needed, starts the bridge as a background daemon, waits
until it is connected to HelloAgent, and then returns. Use `status` to see
whether the daemon is running and `stop` to shut it down.

## Configuration

Defaults are baked in for the common case:

| Setting | Default |
|---|---|
| API URL | `https://api.helloagent.cc` |
| Server WS | `wss://api.helloagent.cc/v1/ws` |
| Bind | `ws://127.0.0.1:8770` |

Env-var overrides if you really need them (local dev mostly):

| Var | Default | Use |
|---|---|---|
| `HA_HERMES_BRIDGE_DIR` | `~/.helloagent-hermes` | State dir |
| `HA_HERMES_BRIDGE_AUTH_DIR` | `<state>/credentials` | Cred dir override |
| `HA_HERMES_BRIDGE_API_URL` | `https://api.helloagent.cc` | Default `--api-url` (override for local relay dev) |
| `HA_HERMES_BRIDGE_WEB_URL` | `https://app.helloagent.cc` | Default `--web-url` (override for local web dev) |
| `HA_HERMES_BRIDGE_CLIENT_ID` | `helloagent-hermes` | OAuth client id |
| `HA_HERMES_BRIDGE_DEBUG` | unset | Verbose logs |
| Var | Use |
|---|---|
| `HA_HERMES_BRIDGE_DIR` | State dir (default `~/.helloagent-hermes`) |
| `HA_HERMES_BRIDGE_AUTH_DIR` | Credential dir override |
| `HA_HERMES_BRIDGE_API_URL` | Override REST API URL (e.g. local HelloAgent server) |
| `HA_HERMES_BRIDGE_SERVER_WS` | Override server WS URL (e.g. local HelloAgent server) |
| `HA_HERMES_BRIDGE_HOST` | Bind host (default `127.0.0.1`) |
| `HA_HERMES_BRIDGE_PORT` | Bind port (default `8770`) |
| `HA_HERMES_BRIDGE_TOKEN` | Shared secret the agent must echo in its hello frame |
| `HA_HERMES_BRIDGE_DEBUG` | `1` for verbose logs |

## What's not in scope (yet)

- Multiple concurrent Hermes connections (server is single-tenant).
- Multiple concurrent agent connections (the socket is single-tenant).
- Group conversations (DMs only — `chatType=dm`).
- Media / files / cards (text only).
- Edits — we advertise `supports: ["typing"]` so Hermes' streamer
auto-downgrades to fresh-send chunks. Each Hermes `send` becomes one
- Edits — we advertise `supports: ["typing"]` so the agent's streamer
auto-downgrades to fresh-send chunks. Each agent `send` becomes one
`StreamChunk` back to the user.
- Reactions, read receipts, typing indicators on the relay side.
- Reactions, read receipts, typing indicators on the HelloAgent server
side.

## Layout

Expand All @@ -126,20 +145,17 @@ src/
├── auth/
│ ├── store.ts creds.json I/O (chmod 0600, atomic write)
│ ├── presence.ts hasAnyAuth probe
│ ├── login.ts PKCE OAuth (browser loopback)
│ ├── login-device.ts device-code flow
│ ├── login-oauth.ts code exchange + linkChannel + persist
│ └── import-token.ts manual ha_* token import
│ └── import-token.ts ha_* token validation + persist
├── core/
│ ├── ha-client.ts per-account managed Agent (lifecycle + status)
│ ├── logger.ts namespaced logger
│ └── types.ts ResolvedAccount
├── wschat/
│ ├── server.ts local WS server (single Hermes client)
├── agent-socket/
│ ├── server.ts local WS server (single agent client)
│ ├── types.ts wire frames
│ └── dedup.ts inbound dedup (relay reconnects)
├── bridge.ts wires HaClient ↔ wschat server, streaming bridge
├── cli.ts pair / run / status / logout
│ └── dedup.ts inbound dedup (server reconnects)
├── bridge.ts wires HaClient ↔ agent socket, streaming bridge
├── cli.ts pair / status / logout
└── index.ts library re-exports
```

Expand Down
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@helloagentai/hermes",
"version": "0.1.0",
"description": "Bridge between HelloAgent's relay and a Hermes Agent gateway. HelloAgent users chat with their personal Hermes through the same UX as any HelloAgent contact.",
"description": "Bridge between the HelloAgent server and a Hermes Agent gateway. HelloAgent users chat with their personal Hermes through the same UX as any HelloAgent contact.",
"license": "MIT",
"author": "HelloAgent",
"homepage": "https://github.com/helloagentai/helloagent-hermes#readme",
Expand All @@ -16,17 +16,21 @@
"helloagent",
"hermes",
"bridge",
"agent",
"relay"
"agent"
],
"type": "module",
"bin": {
"helloagent-hermes": "./dist/cli.js"
},
"exports": {
".": "./dist/index.js"
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"default": "./dist/index.js"
}
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist",
"README.md",
Expand All @@ -37,6 +41,7 @@
},
"scripts": {
"build": "tsc",
"postbuild": "chmod +x dist/cli.js",
"typecheck": "tsc --noEmit",
"start": "node ./dist/cli.js",
"dev": "tsx src/cli.ts",
Expand Down
7 changes: 3 additions & 4 deletions src/wschat/dedup.ts → src/agent-socket/dedup.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/**
* TTL + LRU dedup for inbound messages from the relay. Prevents
* double-dispatch after relay reconnects (the Agent SDK can replay messages
* within its delivery window). Mirrors the shape used by openclaw-HelloAgent
* but trimmed to the inputs we actually need.
* TTL + LRU dedup for inbound messages from the HelloAgent server. Prevents
* double-dispatch after server reconnects (the Agent SDK can replay messages
* within its delivery window).
*/

const DEFAULT_TTL_MS = 5 * 60 * 1000;
Expand Down
Loading
Loading