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
1 change: 1 addition & 0 deletions .github/workflows/runtime-compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ jobs:
python -m unittest discover -s tests -p test_direct_adapter_integration.py -v
python -m unittest discover -s tests -p test_native_voice.py -v
python -m unittest discover -s tests -p test_native_api.py -v
python -m unittest discover -s tests -p test_provider_sign_in.py -v
python -m unittest discover -s tests -p test_adapter.py -v
python -m unittest discover -s tests -p test_registration.py -v
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ systemd and Hermes Desktop keep supervising it; chats running on that process st
| Group chat activity | See which tools each agent in a group chat is using, live. Needs a Hermes host with the `on_room_member_activity` hook. | [Room activity](docs/NATIVE_ROOM_ACTIVITY.md) |
| Context usage | How much of the model's context the last request used. | [Context usage](docs/CONTEXT_USAGE.md) |
| Provider usage | How much of each AI plan or balance you've used: Claude, Codex, GitHub Copilot, OpenCode, OpenRouter, DeepSeek, Nous Portal and more. Found automatically from the tools installed on the computer and the providers set up in Hermes. Read-only. | [Provider usage](docs/PROVIDER_USAGE.md) |
| Provider sign-in | Sign in to accounts that otherwise need a terminal on the computer (GitHub Copilot, Claude Code, Claude subscriptions) from the phone. The provider's own sign-in tool runs on the computer; the phone gets only its link and code. | [Provider sign-in](docs/PROVIDER_SIGN_IN.md) |
| Generated media and files | Agent-made images, videos and files show up in chat. Hermes' own media rules decide what can be shared, and host paths are never exposed. | [Agent attachments](docs/AGENT_ATTACHMENTS.md) |
| Model names | `model-names.json` gives friendly model names. The app can refresh it without a plugin update. | |

Expand Down
114 changes: 114 additions & 0 deletions docs/PROVIDER_SIGN_IN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Provider sign-in

Some AI accounts only sign in from a terminal on the Hermes computer. With this feature, bighelp's Provider Keys
screen signs in to them from the phone: the plugin runs the provider's own sign-in tool on the computer, and the
phone shows its link and code. Accounts Hermes already signs in to itself (Nous Portal, ChatGPT/Codex, MiniMax,
xAI Grok) keep using Hermes' own sign-in.

## What it signs in to

| Account in Hermes | Tool that signs in | How it goes on the phone |
| --- | --- | --- |
| GitHub Copilot (ACP) (`copilot-acp`) | GitHub Copilot CLI: `copilot login --device-code` | Code and link; GitHub confirms on its own |
| GitHub Copilot (`copilot`) | Hermes' own GitHub login, the same one `hermes model` runs. The token goes to the profile's env as `COPILOT_GITHUB_TOKEN` | Code and link; GitHub confirms on its own |
| Claude Code (`claude-code`) | Claude Code: `claude auth login --claudeai` | Link; paste the code Claude shows back into bighelp |
| Claude Subscription DirectSDK (`claude-subscription-directsdk-experimental`) | Claude Code, with the plugin's `CLAUDE_SUBSCRIPTION_DIRECTSDK_COMMAND` and `CLAUDE_SUBSCRIPTION_DIRECTSDK_CONFIG_DIR` | Link; paste the code back |
| Anthropic Account (`anthropic`) | Claude Code: `claude setup-token`. Its long-lived token goes to the profile's env as `CLAUDE_CODE_OAUTH_TOKEN`, the route Hermes documents for Claude subscriptions | Link; paste the code back |
| Qwen OAuth (`qwen-oauth`) | None. Qwen stopped offering this sign-in in April 2026 | Listed as retired, with Qwen Cloud's API key as the replacement |

A sign-in is listed only when this Hermes has that provider. That includes GitHub Copilot, which Hermes files under
API keys because it keeps a token, but which signs in with GitHub like an account.

If the tool isn't installed, the app says so and shows the install command. Nothing is installed for you.

## Respecting provider terms

- The provider's own client does every sign-in. bighelp never contacts a sign-in service, never builds its own
OAuth request, and never reads or copies another tool's saved login.
- Hermes keeps its own Claude sign-in (`hermes auth add anthropic`) in the terminal on purpose, so bighelp never
runs it. Claude accounts sign in through Claude Code, Anthropic's own client.
- A sign-in a provider ends is marked retired instead of started.

## Safety and privacy

- Commands are fixed per provider in `loopdy_plugin/provider_sign_in.py`. The phone only names a provider; it can't
pass arguments, and nothing runs through a shell.
- The tool runs in a private terminal on the computer. Its attempts to open a browser there do nothing.
- Only three things reach the phone: an `https` link on the provider's own domains, the one-time code to enter
there, and whether it worked. Terminal output stays in memory for that one sign-in and is never logged.
- A token a tool prints for you to keep is saved straight to the profile's env with Hermes' credential helper,
then dropped. It never reaches the phone or the logs.
- A pasted code must be one line of visible text, up to 2,048 characters.
- A sign-in stops after 15 minutes. At most four run at once, and starting one again replaces the unfinished one.
- Linux and macOS only (it needs a POSIX terminal).

## Adding a provider

Add a `Recipe` to `RECIPES` in `loopdy_plugin/provider_sign_in.py`:

- `provider_id`: the account's id in Hermes' `/api/providers/oauth` list. The app matches on it.
- `command`: the provider's own CLI and fixed arguments, usually `_cli("tool", override=(...settings))`.
- `flow`: `DEVICE` when the provider's page confirms by itself, `PASTE` when it shows a code to paste back.
- `link_hosts`: the provider's own domains. Links anywhere else are never shown.
- `code`: for device flows, the pattern of the code the tool prints.
- `rejected`: what the tool prints when a pasted code doesn't work, if it doesn't exit.
- `signed_in`: an optional local check (no network) that the account is signed in.
- `retired`: a message, when the provider has ended the sign-in.

Only add a provider when its own client does the sign-in, and add tests with a fake of its CLI that prints what
the real one prints. The app needs no update for a new provider.

## For the app

`native-provider-sign-in-v1` in `/native/context` features.

`POST /api/plugins/loopdy/native/provider-sign-in/<operation>` with the usual native headers (`If-Match` context
ETag and `X-Loopdy-Request-ID`). Every body has `agentId`, the profile.

| Operation | Body | Answer |
| --- | --- | --- |
| `list` | `{"agentId"}` | `{"agentId", "providers": [provider]}` |
| `start` | `{"agentId", "providerId"}` | a session, after waiting up to 12 seconds for the link |
| `status` | `{"agentId", "sessionId"}` | a session |
| `submit` | `{"agentId", "sessionId", "code"}` | a session (`finishing`) |
| `cancel` | `{"agentId", "sessionId"}` | a session (`cancelled`) |

A provider:

```json
{
"providerId": "claude-code",
"name": "Claude Code",
"client": "Claude Code",
"flow": "paste",
"state": "ready",
"signedIn": false,
"docsURL": "https://docs.claude.com/en/docs/claude-code/setup"
}
```

`state` is `ready`, `notInstalled` (with `message` and `installCommand`) or `retired` (with `message` and, when
there is one, `replacementKey`, the Hermes env name of the key to use instead). `signedIn` is present only when the
tool can say.

A session:

```json
{
"sessionId": "5f0c3c52-3a8e-4b8f-9d37-0d3c0e6f1a2b",
"providerId": "copilot-acp",
"flow": "device",
"status": "waiting",
"link": "https://github.com/login/device",
"code": "WDJB-MJHT",
"expiresInSeconds": 890
}
```

`status` is `starting`, `waiting` (device: open the link, enter the code), `needsCode` (paste: open the link, then
send the page's code), `finishing`, `signedIn`, `failed`, `expired` or `cancelled`. `link` and `code` are dropped
once it ends. `message` says what went wrong in plain words.

Errors use the usual native error body. Codes: `sign_in_unavailable` (404, no sign-in for that provider),
`sign_in_not_found` (404), `sign_in_tool_missing` (409), `sign_in_not_waiting` (409), `sign_in_retired` (410),
`sign_in_code_invalid` (422), `sign_in_busy` (429), `sign_in_start_failed` (503) and `sign_in_host_unavailable` (503).
59 changes: 59 additions & 0 deletions loopdy_plugin/native_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,62 @@ async def provider_usage(request: Request) -> Response:
if native_context(request) != owner:
raise NativeAPIError(412, "context_changed", "The native context changed; refresh before retrying.")
return _response({"agentId": body.agentId, **value}, owner, request_id)


_SESSION_ID = r"^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"


class _SignInStart(_Body):
providerId: str = Field(pattern=r"^[a-z0-9][a-z0-9._-]{0,63}$")


class _SignInSession(_Body):
sessionId: str = Field(pattern=_SESSION_ID)


class _SignInCode(_SignInSession):
code: str = Field(min_length=1, max_length=2048)


_SIGN_IN_BODIES: dict[str, type[_Body]] = {
"list": _Body, "start": _SignInStart, "status": _SignInSession, "submit": _SignInCode, "cancel": _SignInSession,
}
_SIGN_IN_STATUS = {
"sign_in_unavailable": 404, "sign_in_not_found": 404, "sign_in_tool_missing": 409, "sign_in_not_waiting": 409,
"sign_in_retired": 410, "sign_in_code_invalid": 422, "sign_in_busy": 429, "sign_in_start_failed": 503,
}


def _sign_in(operation: str, body: _Body) -> dict:
from hermes_cli.profiles import profile_exists
from . import provider_sign_in as sign_in
if not profile_exists(body.agentId):
raise NativeAPIError(404, "profile_not_found", "The selected profile no longer exists.")
try:
if operation == "list":
return {"providers": sign_in.providers(body.agentId)}
if operation == "start":
return sign_in.start(body.agentId, body.providerId)
if operation == "status":
return sign_in.status(body.agentId, body.sessionId)
if operation == "submit":
return sign_in.submit(body.agentId, body.sessionId, body.code)
return sign_in.cancel(body.agentId, body.sessionId)
except sign_in.SignInError as error:
raise NativeAPIError(_SIGN_IN_STATUS.get(error.code, 409), error.code, error.message) from None


@router.post("/provider-sign-in/{operation}")
async def provider_sign_in(operation: str, request: Request) -> Response:
"""Sign in to a provider account with that provider's own sign-in tool (bighelp app: Provider Keys)."""
from .provider_sign_in import CAPABILITY
model = _SIGN_IN_BODIES.get(operation)
if model is None:
raise NativeAPIError(404, "unknown_operation", "The sign-in operation is unknown.")
owner = native_context(request)
request_id = _precondition(request, owner)
if CAPABILITY not in owner.features:
raise NativeAPIError(503, "sign_in_host_unavailable", "This host can't run sign-ins for the app.")
body = await _body(request, model)
value = await run_in_threadpool(_sign_in, operation, body)
return _response({"agentId": body.agentId, **value}, owner, request_id)
5 changes: 5 additions & 0 deletions loopdy_plugin/native_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,9 @@ def skip(feature: str, reason: str) -> None:
features.append(usage_capability)
else:
skip(usage_capability, "public profile helpers are unimportable.")
from .provider_sign_in import CAPABILITY as sign_in_capability, available as sign_in_available
if sign_in_available():
features.append(sign_in_capability)
else:
skip(sign_in_capability, "sign-ins need a POSIX terminal and public profile helpers.")
return profile, tuple(features)
Loading
Loading