Compare commits

..

7 Commits

Author SHA1 Message Date
Alexander Whitestone
5e13fd2a5f docs: Hermes Agent Feature Census — complete inventory
Some checks failed
Forge CI / smoke-and-build (pull_request) Failing after 24s
Full feature census of hermes-agent codebase covering:
- Feature Matrix (memory, tools, sessions, plugins, config, gateway)
- Architecture Overview (dependency chain, data flow)
- Recent Development Activity (last 30 days, 1750+ commits)
- Overlap Analysis (what to use vs what to build)
- Contribution Roadmap (upstream vs Timmy Foundation)

Refs: #290
2026-04-11 05:03:51 -04:00
04c017bcb3 fix: CI stability — reduce deps, increase timeout
Some checks failed
Forge CI / smoke-and-build (push) Failing after 28s
2026-04-11 00:32:20 +00:00
4c2ac7b644 Merge pull request 'fix(memory): add remove action to on_memory_write bridge' (#277) from keymaxx/mimoomni/243 into main
Some checks failed
Forge CI / smoke-and-build (push) Failing after 45s
Auto-merged by Timmy
2026-04-10 20:59:47 +00:00
8202649ca0 fix(memory): add remove action to on_memory_write bridge
All checks were successful
Forge CI / smoke-and-build (pull_request) Successful in 43s
- Extend on_memory_write trigger in run_agent.py to fire for 'remove' action
- Holographic provider now handles 'replace' (re-adds content) and 'remove' (lowers trust on matching facts)
- Fixes orphaned facts when entries are deleted from built-in memory

Fixes #243
2026-04-10 15:31:45 -04:00
f5f028d981 auto-merge PR #276
Some checks failed
Forge CI / smoke-and-build (push) Failing after 42s
2026-04-10 19:03:02 +00:00
Alexander Whitestone
a703fb823c docs: add Matrix integration setup guide and interactive script
Some checks failed
Forge CI / smoke-and-build (pull_request) Failing after 36s
Phase 2 of Matrix integration — wires Hermes to any Matrix homeserver.

- docs/matrix-setup.md: step-by-step guide covering matrix.org (testing)
  and self-hosted (sovereignty) options, auth methods, E2EE setup, room
  config, and troubleshooting
- scripts/setup_matrix.py: interactive wizard that prompts for homeserver,
  supports token/password auth, generates MATRIX_DEVICE_ID, writes
  ~/.hermes/.env and config.yaml, and optionally creates a test room +
  sends a test message

No config.py changes needed — all Matrix env vars (MATRIX_HOMESERVER,
MATRIX_ACCESS_TOKEN, MATRIX_USER_ID, MATRIX_PASSWORD, MATRIX_ENCRYPTION,
MATRIX_DEVICE_ID, MATRIX_ALLOWED_USERS, MATRIX_HOME_ROOM, etc.) are
already registered in OPTIONAL_ENV_VARS and _EXTRA_ENV_KEYS.

Closes #271
2026-04-10 07:46:42 -04:00
a89dae9942 [auto-merge] browser integration PoC
Some checks failed
Forge CI / smoke-and-build (push) Failing after 38s
Notebook CI / notebook-smoke (push) Failing after 7s
Auto-merged by PR review bot: browser integration PoC
2026-04-10 11:44:56 +00:00
6 changed files with 1203 additions and 9 deletions

View File

@@ -13,7 +13,7 @@ concurrency:
jobs:
smoke-and-build:
runs-on: ubuntu-latest
timeout-minutes: 5
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v4
@@ -31,7 +31,7 @@ jobs:
run: |
uv venv .venv --python 3.11
source .venv/bin/activate
uv pip install -e ".[all,dev]"
uv pip install -e ".[dev]"
- name: Smoke tests
run: |
@@ -55,7 +55,7 @@ jobs:
- name: Green-path E2E
run: |
source .venv/bin/activate
python -m pytest tests/test_green_path_e2e.py -q --tb=short
python -m pytest tests/test_green_path_e2e.py -q --tb=short -p no:xdist
env:
OPENROUTER_API_KEY: ""
OPENAI_API_KEY: ""

477
docs/hermes-agent-census.md Normal file
View File

@@ -0,0 +1,477 @@
# Hermes Agent — Feature Census
**Epic:** [#290 — Know Thy Agent: Hermes Feature Census](https://forge.alexanderwhitestone.com/Timmy_Foundation/hermes-agent/issues/290)
**Date:** 2026-04-11
**Source:** Timmy_Foundation/hermes-agent (fork of NousResearch/hermes-agent)
**Upstream:** NousResearch/hermes-agent (last sync: 2026-04-07, 499 commits merged in PR #201)
**Codebase:** ~200K lines Python (335 source files), 470 test files
---
## 1. Feature Matrix
### 1.1 Memory System
| Feature | Status | File:Line | Notes |
|---------|--------|-----------|-------|
| **`add` action** | ✅ Exists | `tools/memory_tool.py:457` | Append entry to MEMORY.md or USER.md |
| **`replace` action** | ✅ Exists | `tools/memory_tool.py:466` | Find by substring, replace content |
| **`remove` action** | ✅ Exists | `tools/memory_tool.py:475` | Find by substring, delete entry |
| **Dual stores (memory + user)** | ✅ Exists | `tools/memory_tool.py:43-45` | MEMORY.md (2200 char limit) + USER.md (1375 char limit) |
| **Entry deduplication** | ✅ Exists | `tools/memory_tool.py:128-129` | Exact-match dedup on load |
| **Injection/exfiltration scanning** | ✅ Exists | `tools/memory_tool.py:85` | Blocks prompt injection, role hijacking, secret exfil |
| **Frozen snapshot pattern** | ✅ Exists | `tools/memory_tool.py:119-135` | Preserves LLM prefix cache across session |
| **Atomic writes** | ✅ Exists | `tools/memory_tool.py:417-436` | tempfile.mkstemp + os.replace |
| **File locking (fcntl)** | ✅ Exists | `tools/memory_tool.py:137-153` | Exclusive lock for concurrent safety |
| **External provider plugin** | ✅ Exists | `agent/memory_manager.py` | Supports 1 external provider (Honcho, Mem0, Hindsight, etc.) |
| **Provider lifecycle hooks** | ✅ Exists | `agent/memory_provider.py:55-66` | on_memory_write, prefetch, sync_turn, on_session_end, on_pre_compress, on_delegation |
| **Session search (past conversations)** | ✅ Exists | `tools/session_search_tool.py:492` | FTS5 search across SQLite message store |
| **Holographic memory** | 🔌 Plugin slot | Config `memory.provider` | Accepted as external provider name, not built-in |
| **Engram integration** | ❌ Not present | — | Not in codebase; Engram is a Timmy Foundation project |
| **Trust system** | ❌ Not present | — | No trust scoring on memory entries |
### 1.2 Tool System
| Feature | Status | File:Line | Notes |
|---------|--------|-----------|-------|
| **Central registry** | ✅ Exists | `tools/registry.py:290` | Module-level singleton, all tools self-register |
| **47 static tools** | ✅ Exists | See full list below | Organized in 21+ toolsets |
| **Dynamic MCP tools** | ✅ Exists | `tools/mcp_tool.py` | Runtime registration from MCP servers (17 in live instance) |
| **Tool approval system** | ✅ Exists | `tools/approval.py` | Manual/smart/off modes, dangerous command detection |
| **Toolset composition** | ✅ Exists | `toolsets.py:404` | Composite toolsets (e.g., `debugging = terminal + web + file`) |
| **Per-platform toolsets** | ✅ Exists | `toolsets.py` | `hermes-cli`, `hermes-telegram`, `hermes-discord`, etc. |
| **Skill management** | ✅ Exists | `tools/skill_manager_tool.py:747` | Create, patch, delete skill documents |
| **Mixture of Agents** | ✅ Exists | `tools/mixture_of_agents_tool.py:553` | Route through 4+ frontier LLMs |
| **Subagent delegation** | ✅ Exists | `tools/delegate_tool.py:963` | Isolated contexts, up to 3 parallel |
| **Code execution sandbox** | ✅ Exists | `tools/code_execution_tool.py:1360` | Python scripts with tool access |
| **Image generation** | ✅ Exists | `tools/image_generation_tool.py:694` | FLUX 2 Pro |
| **Vision analysis** | ✅ Exists | `tools/vision_tools.py:606` | Multi-provider vision |
| **Text-to-speech** | ✅ Exists | `tools/tts_tool.py:974` | Edge TTS, ElevenLabs, OpenAI, NeuTTS |
| **Speech-to-text** | ✅ Exists | Config `stt.*` | Local Whisper, Groq, OpenAI, Mistral Voxtral |
| **Home Assistant** | ✅ Exists | `tools/homeassistant_tool.py:456-483` | 4 HA tools (list, state, services, call) |
| **RL training** | ✅ Exists | `tools/rl_training_tool.py:1376-1394` | 10 Tinker-Atropos tools |
| **Browser automation** | ✅ Exists | `tools/browser_tool.py:2137-2211` | 10 tools (navigate, click, type, scroll, screenshot, etc.) |
| **Gitea client** | ✅ Exists | `tools/gitea_client.py` | Gitea API integration |
| **Cron job management** | ✅ Exists | `tools/cronjob_tools.py:508` | Scheduled task CRUD |
| **Send message** | ✅ Exists | `tools/send_message_tool.py:1036` | Cross-platform messaging |
#### Complete Tool List (47 static)
| # | Tool | Toolset | File:Line |
|---|------|---------|-----------|
| 1 | `read_file` | file | `tools/file_tools.py:832` |
| 2 | `write_file` | file | `tools/file_tools.py:833` |
| 3 | `patch` | file | `tools/file_tools.py:834` |
| 4 | `search_files` | file | `tools/file_tools.py:835` |
| 5 | `terminal` | terminal | `tools/terminal_tool.py:1783` |
| 6 | `process` | terminal | `tools/process_registry.py:1039` |
| 7 | `web_search` | web | `tools/web_tools.py:2082` |
| 8 | `web_extract` | web | `tools/web_tools.py:2092` |
| 9 | `vision_analyze` | vision | `tools/vision_tools.py:606` |
| 10 | `image_generate` | image_gen | `tools/image_generation_tool.py:694` |
| 11 | `text_to_speech` | tts | `tools/tts_tool.py:974` |
| 12 | `skills_list` | skills | `tools/skills_tool.py:1357` |
| 13 | `skill_view` | skills | `tools/skills_tool.py:1367` |
| 14 | `skill_manage` | skills | `tools/skill_manager_tool.py:747` |
| 15 | `browser_navigate` | browser | `tools/browser_tool.py:2137` |
| 16 | `browser_snapshot` | browser | `tools/browser_tool.py:2145` |
| 17 | `browser_click` | browser | `tools/browser_tool.py:2154` |
| 18 | `browser_type` | browser | `tools/browser_tool.py:2162` |
| 19 | `browser_scroll` | browser | `tools/browser_tool.py:2170` |
| 20 | `browser_back` | browser | `tools/browser_tool.py:2178` |
| 21 | `browser_press` | browser | `tools/browser_tool.py:2186` |
| 22 | `browser_get_images` | browser | `tools/browser_tool.py:2195` |
| 23 | `browser_vision` | browser | `tools/browser_tool.py:2203` |
| 24 | `browser_console` | browser | `tools/browser_tool.py:2211` |
| 25 | `todo` | todo | `tools/todo_tool.py:260` |
| 26 | `memory` | memory | `tools/memory_tool.py:544` |
| 27 | `session_search` | session_search | `tools/session_search_tool.py:492` |
| 28 | `clarify` | clarify | `tools/clarify_tool.py:131` |
| 29 | `execute_code` | code_execution | `tools/code_execution_tool.py:1360` |
| 30 | `delegate_task` | delegation | `tools/delegate_tool.py:963` |
| 31 | `cronjob` | cronjob | `tools/cronjob_tools.py:508` |
| 32 | `send_message` | messaging | `tools/send_message_tool.py:1036` |
| 33 | `mixture_of_agents` | moa | `tools/mixture_of_agents_tool.py:553` |
| 34 | `ha_list_entities` | homeassistant | `tools/homeassistant_tool.py:456` |
| 35 | `ha_get_state` | homeassistant | `tools/homeassistant_tool.py:465` |
| 36 | `ha_list_services` | homeassistant | `tools/homeassistant_tool.py:474` |
| 37 | `ha_call_service` | homeassistant | `tools/homeassistant_tool.py:483` |
| 38-47 | `rl_*` (10 tools) | rl | `tools/rl_training_tool.py:1376-1394` |
### 1.3 Session System
| Feature | Status | File:Line | Notes |
|---------|--------|-----------|-------|
| **Session creation** | ✅ Exists | `gateway/session.py:676` | get_or_create_session with auto-reset |
| **Session keying** | ✅ Exists | `gateway/session.py:429` | platform:chat_type:chat_id[:thread_id][:user_id] |
| **Reset policies** | ✅ Exists | `gateway/session.py:610` | none / idle / daily / both |
| **Session switching (/resume)** | ✅ Exists | `gateway/session.py:825` | Point key at a previous session ID |
| **Session branching (/branch)** | ✅ Exists | CLI commands.py | Fork conversation history |
| **SQLite persistence** | ✅ Exists | `hermes_state.py:41-94` | sessions + messages + FTS5 search |
| **JSONL dual-write** | ✅ Exists | `gateway/session.py:891` | Backward compatibility with legacy format |
| **WAL mode concurrency** | ✅ Exists | `hermes_state.py:157` | Concurrent read/write with retry |
| **Context compression** | ✅ Exists | Config `compression.*` | Auto-compress when context exceeds ratio |
| **Memory flush on reset** | ✅ Exists | `gateway/run.py:632` | Reviews old transcript before auto-reset |
| **Token/cost tracking** | ✅ Exists | `hermes_state.py:41` | input, output, cache_read, cache_write, reasoning tokens |
| **PII redaction** | ✅ Exists | Config `privacy.redact_pii` | Hash user IDs, strip phone numbers |
### 1.4 Plugin System
| Feature | Status | File:Line | Notes |
|---------|--------|-----------|-------|
| **Plugin discovery** | ✅ Exists | `hermes_cli/plugins.py:5-11` | User (~/.hermes/plugins/), project, pip entry-points |
| **Plugin manifest (plugin.yaml)** | ✅ Exists | `hermes_cli/plugins.py` | name, version, requires_env, provides_tools, provides_hooks |
| **Lifecycle hooks** | ✅ Exists | `hermes_cli/plugins.py:55-66` | 9 hooks (pre/post tool_call, llm_call, api_request; on_session_start/end/finalize/reset) |
| **PluginContext API** | ✅ Exists | `hermes_cli/plugins.py:124-233` | register_tool, inject_message, register_cli_command, register_hook |
| **Plugin management CLI** | ✅ Exists | `hermes_cli/plugins_cmd.py:1-690` | install, update, remove, enable, disable |
| **Project plugins (opt-in)** | ✅ Exists | `hermes_cli/plugins.py` | Requires HERMES_ENABLE_PROJECT_PLUGINS env var |
| **Pip plugins** | ✅ Exists | `hermes_cli/plugins.py` | Entry-point group: hermes_agent.plugins |
### 1.5 Config System
| Feature | Status | File:Line | Notes |
|---------|--------|-----------|-------|
| **YAML config** | ✅ Exists | `hermes_cli/config.py:259-619` | ~120 config keys across 25 sections |
| **Schema versioning** | ✅ Exists | `hermes_cli/config.py` | `_config_version: 14` with migration support |
| **Provider config** | ✅ Exists | Config `providers.*`, `fallback_providers` | Per-provider overrides, fallback chains |
| **Credential pooling** | ✅ Exists | Config `credential_pool_strategies` | Key rotation strategies |
| **Auxiliary model config** | ✅ Exists | Config `auxiliary.*` | 8 separate side-task models (vision, compression, etc.) |
| **Smart model routing** | ✅ Exists | Config `smart_model_routing.*` | Route simple prompts to cheap model |
| **Env var management** | ✅ Exists | `hermes_cli/config.py:643-1318` | ~80 env vars across provider/tool/messaging/setting categories |
| **Interactive setup wizard** | ✅ Exists | `hermes_cli/setup.py` | Guided first-run configuration |
| **Config migration** | ✅ Exists | `hermes_cli/config.py` | Auto-migrates old config versions |
### 1.6 Gateway
| Feature | Status | File:Line | Notes |
|---------|--------|-----------|-------|
| **18 platform adapters** | ✅ Exists | `gateway/platforms/` | Telegram, Discord, Slack, WhatsApp, Signal, Mattermost, Matrix, HomeAssistant, Email, SMS, DingTalk, API Server, Webhook, Feishu, Wecom, Weixin, BlueBubbles |
| **Message queuing** | ✅ Exists | `gateway/run.py:507` | Queue during agent processing, media placeholder support |
| **Agent caching** | ✅ Exists | `gateway/run.py:515` | Preserve AIAgent instances per session for prompt caching |
| **Background reconnection** | ✅ Exists | `gateway/run.py:527` | Exponential backoff for failed platforms |
| **Authorization** | ✅ Exists | `gateway/run.py:1826` | Per-user allowlists, DM pairing codes |
| **Slash command interception** | ✅ Exists | `gateway/run.py` | Commands handled before agent (not billed) |
| **ACP server** | ✅ Exists | `acp_adapter/server.py:726` | VS Code / Zed / JetBrains integration |
| **Cron scheduler** | ✅ Exists | `cron/scheduler.py:850` | Full job scheduler with cron expressions |
| **Batch runner** | ✅ Exists | `batch_runner.py:1285` | Parallel batch processing |
| **API server** | ✅ Exists | `gateway/platforms/api_server.py` | OpenAI-compatible HTTP API |
### 1.7 Providers (20 supported)
| Provider | ID | Key Env Var |
|----------|----|-------------|
| Nous Portal | `nous` | `NOUS_BASE_URL` |
| OpenRouter | `openrouter` | `OPENROUTER_API_KEY` |
| Anthropic | `anthropic` | (standard) |
| Google AI Studio | `gemini` | `GOOGLE_API_KEY`, `GEMINI_API_KEY` |
| OpenAI Codex | `openai-codex` | (standard) |
| GitHub Copilot | `copilot` / `copilot-acp` | (OAuth) |
| DeepSeek | `deepseek` | `DEEPSEEK_API_KEY` |
| Kimi / Moonshot | `kimi-coding` | `KIMI_API_KEY` |
| Z.AI / GLM | `zai` | `GLM_API_KEY`, `ZAI_API_KEY` |
| MiniMax | `minimax` | `MINIMAX_API_KEY` |
| MiniMax (China) | `minimax-cn` | `MINIMAX_CN_API_KEY` |
| Alibaba / DashScope | `alibaba` | `DASHSCOPE_API_KEY` |
| Hugging Face | `huggingface` | `HF_TOKEN` |
| OpenCode Zen | `opencode-zen` | `OPENCODE_ZEN_API_KEY` |
| OpenCode Go | `opencode-go` | `OPENCODE_GO_API_KEY` |
| Qwen OAuth | `qwen-oauth` | (Portal) |
| AI Gateway | `ai-gateway` | (Nous) |
| Kilo Code | `kilocode` | (standard) |
| Ollama (local) | — | First-class via auxiliary wiring |
| Custom endpoint | `custom` | user-provided URL |
### 1.8 UI / UX
| Feature | Status | File:Line | Notes |
|---------|--------|-----------|-------|
| **Skin/theme engine** | ✅ Exists | `hermes_cli/skin_engine.py` | 7 built-in skins, user YAML skins |
| **Kawaii spinner** | ✅ Exists | `agent/display.py` | Animated faces, configurable verbs/wings |
| **Rich banner** | ✅ Exists | `banner.py` | Logo, hero art, system info |
| **Prompt_toolkit input** | ✅ Exists | `cli.py` | Autocomplete, history, syntax |
| **Streaming output** | ✅ Exists | Config `display.streaming` | Optional streaming |
| **Reasoning display** | ✅ Exists | Config `display.show_reasoning` | Show/hide chain-of-thought |
| **Cost display** | ✅ Exists | Config `display.show_cost` | Show $ in status bar |
| **Voice mode** | ✅ Exists | Config `voice.*` | Ctrl+B record, auto-TTS, silence detection |
| **Human delay simulation** | ✅ Exists | Config `human_delay.*` | Simulated typing delay |
### 1.9 Security
| Feature | Status | File:Line | Notes |
|---------|--------|-----------|-------|
| **Tirith security scanning** | ✅ Exists | `tools/tirith_security.py` | Pre-exec code scanning |
| **Secret redaction** | ✅ Exists | Config `security.redact_secrets` | Auto-strip secrets from output |
| **Memory injection scanning** | ✅ Exists | `tools/memory_tool.py:85` | Blocks prompt injection in memory |
| **URL safety** | ✅ Exists | `tools/url_safety.py` | URL reputation checking |
| **Command approval** | ✅ Exists | `tools/approval.py` | Manual/smart/off modes |
| **OSV vulnerability check** | ✅ Exists | `tools/osv_check.py` | Open Source Vulnerabilities DB |
| **Conscience validator** | ✅ Exists | `tools/conscience_validator.py` | SOUL.md alignment checking |
| **Shield detector** | ✅ Exists | `tools/shield/detector.py` | Jailbreak/crisis detection |
---
## 2. Architecture Overview
```
┌─────────────────────────────────────────────────────────┐
│ Entry Points │
├──────────┬──────────┬──────────┬──────────┬─────────────┤
│ CLI │ Gateway │ ACP │ Cron │ Batch Runner│
│ cli.py │gateway/ │acp_apt/ │ cron/ │batch_runner │
│ 8620 ln │ run.py │server.py │sched.py │ 1285 ln │
│ │ 7905 ln │ 726 ln │ 850 ln │ │
└────┬─────┴────┬─────┴──────────┴──────┬───┴─────────────┘
│ │ │
▼ ▼ ▼
┌─────────────────────────────────────────────────────────┐
│ AIAgent (run_agent.py, 9423 ln) │
│ ┌──────────────────────────────────────────────────┐ │
│ │ Core Conversation Loop │ │
│ │ while iterations < max: │ │
│ │ response = client.chat(tools, messages) │ │
│ │ if tool_calls: handle_function_call() │ │
│ │ else: return response │ │
│ └──────────────────────┬───────────────────────────┘ │
│ │ │
│ ┌──────────────────────▼───────────────────────────┐ │
│ │ model_tools.py (577 ln) │ │
│ │ _discover_tools() → handle_function_call() │ │
│ └──────────────────────┬───────────────────────────┘ │
└─────────────────────────┼───────────────────────────────┘
┌────────────────────▼────────────────────┐
│ tools/registry.py (singleton) │
│ ToolRegistry.register() → dispatch() │
└────────────────────┬────────────────────┘
┌─────────┬───────────┼───────────┬────────────────┐
▼ ▼ ▼ ▼ ▼
┌────────┐┌────────┐┌──────────┐┌──────────┐ ┌──────────┐
│ file ││terminal││ web ││ browser │ │ memory │
│ tools ││ tool ││ tools ││ tool │ │ tool │
│ 4 tools││2 tools ││ 2 tools ││ 10 tools │ │ 3 actions│
└────────┘└────────┘└──────────┘└──────────┘ └────┬─────┘
┌──────────▼──────────┐
│ agent/memory_manager │
│ ┌──────────────────┐│
│ │BuiltinProvider ││
│ │(MEMORY.md+USER.md)│
│ ├──────────────────┤│
│ │External Provider ││
│ │(optional, 1 max) ││
│ └──────────────────┘│
└─────────────────────┘
┌─────────────────────────────────────────────────┐
│ Session Layer │
│ SessionStore (gateway/session.py, 1030 ln) │
│ SessionDB (hermes_state.py, 1238 ln) │
│ ┌───────────┐ ┌─────────────────────────────┐ │
│ │sessions.js│ │ state.db (SQLite + FTS5) │ │
│ │ JSONL │ │ sessions │ messages │ fts │ │
│ └───────────┘ └─────────────────────────────┘ │
└─────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────┐
│ Gateway Platform Adapters │
│ telegram │ discord │ slack │ whatsapp │ signal │
│ matrix │ email │ sms │ mattermost│ api │
│ homeassistant │ dingtalk │ feishu │ wecom │ ... │
└─────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────┐
│ Plugin System │
│ User ~/.hermes/plugins/ │ Project .hermes/ │
│ Pip entry-points (hermes_agent.plugins) │
│ 9 lifecycle hooks │ PluginContext API │
└─────────────────────────────────────────────────┘
```
**Key dependency chain:**
```
tools/registry.py (no deps — imported by all tool files)
tools/*.py (each calls registry.register() at import time)
model_tools.py (imports tools/registry + triggers tool discovery)
run_agent.py, cli.py, batch_runner.py, environments/
```
---
## 3. Recent Development Activity (Last 30 Days)
### Activity Summary
| Metric | Value |
|--------|-------|
| Total commits (since 2026-03-12) | ~1,750 |
| Top contributor | Teknium (1,169 commits) |
| Timmy Foundation commits | ~55 (Alexander Whitestone: 21, Timmy Time: 22, Bezalel: 12) |
| Key upstream sync | PR #201 — 499 commits from NousResearch/hermes-agent (2026-04-07) |
### Top Contributors (Last 30 Days)
| Contributor | Commits | Focus Area |
|-------------|---------|------------|
| Teknium | 1,169 | Core features, bug fixes, streaming, browser, Telegram/Discord |
| teknium1 | 238 | Supplementary work |
| 0xbyt4 | 117 | Various |
| Test | 61 | Testing |
| Allegro | 49 | Fleet ops, CI |
| kshitijk4poor | 30 | Features |
| SHL0MS | 25 | Features |
| Google AI Agent | 23 | MemPalace plugin |
| Timmy Time | 22 | CI, fleet config, merge coordination |
| Alexander Whitestone | 21 | Memory fixes, browser PoC, docs, CI, provider config |
| Bezalel | 12 | CI pipeline, devkit, health checks |
### Key Upstream Changes (Merged in Last 30 Days)
| Change | PR | Impact |
|--------|----|--------|
| Browser provider switch (Browserbase → Browser Use) | upstream #5750 | Breaking change in browser tooling |
| notify_on_complete for background processes | upstream #5779 | New feature for async workflows |
| Interactive model picker (Telegram + Discord) | upstream #5742 | UX improvement |
| Streaming fix after tool boundaries | upstream #5739 | Bug fix |
| Delegate: share credential pools with subagents | upstream | Security improvement |
| Permanent command allowlist on startup | upstream #5076 | Bug fix |
| Paginated model picker for Telegram | upstream | UX improvement |
| Slack thread replies without @mentions | upstream | Gateway improvement |
| Supermemory memory provider (added then removed) | upstream | Experimental, rolled back |
| Background process management overhaul | upstream | Major feature |
### Timmy Foundation Contributions (Our Fork)
| Change | PR | Author |
|--------|----|--------|
| Memory remove action bridge fix | #277 | Alexander Whitestone |
| Browser integration PoC + analysis | #262 | Alexander Whitestone |
| Memory budget enforcement tool | #256 | Alexander Whitestone |
| Memory sovereignty verification | #257 | Alexander Whitestone |
| Memory Architecture Guide | #263, #258 | Alexander Whitestone |
| MemPalace plugin creation | #259, #265 | Google AI Agent |
| CI: duplicate model detection | #235 | Alexander Whitestone |
| Kimi model config fix | #225 | Bezalel |
| Ollama provider wiring fix | #223 | Alexander Whitestone |
| Deep Self-Awareness Epic | #215 | Bezalel |
| BOOT.md for repo | #202 | Bezalel |
| Upstream sync (499 commits) | #201 | Alexander Whitestone |
| Forge CI pipeline | #154, #175, #187 | Bezalel |
| Gitea PR & Issue automation skill | #181 | Bezalel |
| Development tools for wizard fleet | #166 | Bezalel |
| KNOWN_VIOLATIONS justification | #267 | Manus AI |
---
## 4. Overlap Analysis
### What We're Building That Already Exists
| Timmy Foundation Planned Work | Hermes-Agent Already Has | Verdict |
|------------------------------|--------------------------|---------|
| **Memory system (add/remove/replace)** | `tools/memory_tool.py` with all 3 actions | **USE IT** — already exists, we just needed the `remove` fix (PR #277) |
| **Session persistence** | SQLite + JSONL dual-write system | **USE IT** — battle-tested, FTS5 search included |
| **Gateway platform adapters** | 18 adapters including Telegram, Discord, Matrix | **USE IT** — don't rebuild, contribute fixes |
| **Config management** | Full YAML config with migration, env vars | **USE IT** — extend rather than replace |
| **Plugin system** | Complete with lifecycle hooks, PluginContext API | **USE IT** — write plugins, not custom frameworks |
| **Tool registry** | Centralized registry with self-registration | **USE IT** — register new tools via existing pattern |
| **Cron scheduling** | `cron/scheduler.py` + `cronjob` tool | **USE IT** — integrate rather than duplicate |
| **Subagent delegation** | `delegate_task` with isolated contexts | **USE IT** — extend for fleet coordination |
### What We Need That Doesn't Exist
| Timmy Foundation Need | Hermes-Agent Status | Action |
|----------------------|---------------------|--------|
| **Engram integration** | Not present | Build as external memory provider plugin |
| **Holographic fact store** | Accepted as provider name, not implemented | Build as external memory provider |
| **Fleet orchestration** | Not present (single-agent focus) | Build on top, contribute patterns upstream |
| **Trust scoring on memory** | Not present | Build as extension to memory tool |
| **Multi-agent coordination** | delegate_tool supports parallel (max 3) | Extend for fleet-wide dispatch |
| **VPS wizard deployment** | Not present | Timmy Foundation domain — build independently |
| **Gitea CI/CD integration** | Minimal (gitea_client.py exists) | Extend existing client |
### Duplication Risk Assessment
| Risk | Level | Details |
|------|-------|---------|
| Memory system duplication | 🟢 LOW | We were almost duplicating memory removal (PR #278 vs #277). Now resolved. |
| Config system duplication | 🟢 LOW | Using hermes config directly via fork |
| Gateway duplication | 🟡 MEDIUM | Our fleet-ops patterns may partially overlap with gateway capabilities |
| Session management duplication | 🟢 LOW | Using hermes sessions directly |
| Plugin system duplication | 🟢 LOW | We write plugins, not a parallel system |
---
## 5. Contribution Roadmap
### What to Build (Timmy Foundation Own)
| Item | Rationale | Priority |
|------|-----------|----------|
| **Engram memory provider** | Sovereign local memory (Go binary, SQLite+FTS). Must be ours. | 🔴 HIGH |
| **Holographic fact store** | Our architecture for knowledge graph memory. Unique to Timmy. | 🔴 HIGH |
| **Fleet orchestration layer** | Multi-wizard coordination (Allegro, Bezalel, Ezra, Claude). Not upstream's problem. | 🔴 HIGH |
| **VPS deployment automation** | Sovereign wizard provisioning. Timmy-specific. | 🟡 MEDIUM |
| **Trust scoring system** | Evaluate memory entry reliability. Research needed. | 🟡 MEDIUM |
| **Gitea CI/CD integration** | Deep integration with our forge. Extend gitea_client.py. | 🟡 MEDIUM |
| **SOUL.md compliance tooling** | Conscience validator exists (`tools/conscience_validator.py`). Extend it. | 🟢 LOW |
### What to Contribute Upstream
| Item | Rationale | Difficulty |
|------|-----------|------------|
| **Memory remove action fix** | Already done (PR #277). ✅ | Done |
| **Browser integration analysis** | Useful for all users (PR #262). ✅ | Done |
| **CI stability improvements** | Reduce deps, increase timeout (our commit). ✅ | Done |
| **Duplicate model detection** | CI check useful for all forks (PR #235). ✅ | Done |
| **Memory sovereignty patterns** | Verification scripts, budget enforcement. Useful broadly. | Medium |
| **Engram provider adapter** | If Engram proves useful, offer as memory provider option. | Medium |
| **Fleet delegation patterns** | If multi-agent coordination patterns generalize. | Hard |
| **Wizard health monitoring** | If monitoring patterns generalize to any agent fleet. | Medium |
### Quick Wins (Next Sprint)
1. **Verify memory remove action** — Confirm PR #277 works end-to-end in our fork
2. **Test browser tool after upstream switch** — Browserbase → Browser Use (upstream #5750) may break our PoC
3. **Update provider config** — Kimi model references updated (PR #225), verify no remaining stale refs
4. **Engram provider prototype** — Start implementing as external memory provider plugin
5. **Fleet health integration** — Use gateway's background reconnection patterns for wizard fleet
---
## Appendix A: File Counts by Directory
| Directory | Files | Lines |
|-----------|-------|-------|
| `tools/` | 70+ .py files | ~50K |
| `gateway/` | 20+ .py files | ~25K |
| `agent/` | 10 .py files | ~10K |
| `hermes_cli/` | 15 .py files | ~20K |
| `acp_adapter/` | 9 .py files | ~8K |
| `cron/` | 3 .py files | ~2K |
| `tests/` | 470 .py files | ~80K |
| **Total** | **335 source + 470 test** | **~200K + ~80K** |
## Appendix B: Key File Index
| File | Lines | Purpose |
|------|-------|---------|
| `run_agent.py` | 9,423 | AIAgent class, core conversation loop |
| `cli.py` | 8,620 | CLI orchestrator, slash command dispatch |
| `gateway/run.py` | 7,905 | Gateway main loop, platform management |
| `tools/terminal_tool.py` | 1,783 | Terminal orchestration |
| `tools/web_tools.py` | 2,082 | Web search + extraction |
| `tools/browser_tool.py` | 2,211 | Browser automation (10 tools) |
| `tools/code_execution_tool.py` | 1,360 | Python sandbox |
| `tools/delegate_tool.py` | 963 | Subagent delegation |
| `tools/mcp_tool.py` | ~1,050 | MCP client |
| `tools/memory_tool.py` | 560 | Memory CRUD |
| `hermes_state.py` | 1,238 | SQLite session store |
| `gateway/session.py` | 1,030 | Session lifecycle |
| `cron/scheduler.py` | 850 | Job scheduler |
| `hermes_cli/config.py` | 1,318 | Config system |
| `hermes_cli/plugins.py` | 611 | Plugin system |
| `hermes_cli/skin_engine.py` | 500+ | Theme engine |

271
docs/matrix-setup.md Normal file
View File

@@ -0,0 +1,271 @@
# Matrix Integration Setup Guide
Connect Hermes Agent to any Matrix homeserver for sovereign, encrypted messaging.
## Prerequisites
- Python 3.10+
- matrix-nio SDK: `pip install "matrix-nio[e2e]"`
- For E2EE: libolm C library (see below)
## Option A: matrix.org Public Homeserver (Testing)
Best for quick evaluation. No server to run.
### 1. Create a Matrix Account
Go to https://app.element.io and create an account on matrix.org.
Choose a username like `@hermes-bot:matrix.org`.
### 2. Get an Access Token
The recommended auth method. Token avoids storing passwords and survives
password changes.
```bash
# Using curl (replace user/password):
curl -X POST 'https://matrix-client.matrix.org/_matrix/client/v3/login' \
-H 'Content-Type: application/json' \
-d '{
"type": "m.login.password",
"user": "your-bot-username",
"password": "your-password"
}'
```
Look for `access_token` and `device_id` in the response.
Alternatively, in Element: Settings -> Help & About -> Advanced -> Access Token.
### 3. Set Environment Variables
Add to `~/.hermes/.env`:
```bash
MATRIX_HOMESERVER=https://matrix-client.matrix.org
MATRIX_ACCESS_TOKEN=syt_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
MATRIX_USER_ID=@hermes-bot:matrix.org
MATRIX_DEVICE_ID=HERMES_BOT
```
### 4. Install Dependencies
```bash
pip install "matrix-nio[e2e]"
```
### 5. Start Hermes Gateway
```bash
hermes gateway
```
## Option B: Self-Hosted Homeserver (Sovereignty)
For full control over your data and encryption keys.
### Popular Homeservers
- **Synapse** (reference impl): https://github.com/element-hq/synapse
- **Conduit** (lightweight, Rust): https://conduit.rs
- **Dendrite** (Go): https://github.com/matrix-org/dendrite
### 1. Deploy Your Homeserver
Follow your chosen server's documentation. Common setup with Docker:
```bash
# Synapse example:
docker run -d --name synapse \
-v /opt/synapse/data:/data \
-e SYNAPSE_SERVER_NAME=your.domain.com \
-e SYNAPSE_REPORT_STATS=no \
matrixdotorg/synapse:latest
```
### 2. Create Bot Account
Register on your homeserver:
```bash
# Synapse: register new user (run inside container)
docker exec -it synapse register_new_matrix_user http://localhost:8008 \
-c /data/homeserver.yaml -u hermes-bot -p 'secure-password' --admin
```
### 3. Configure Hermes
Set in `~/.hermes/.env`:
```bash
MATRIX_HOMESERVER=https://matrix.your.domain.com
MATRIX_ACCESS_TOKEN=<obtain via login API>
MATRIX_USER_ID=@hermes-bot:your.domain.com
MATRIX_DEVICE_ID=HERMES_BOT
```
## Environment Variables Reference
| Variable | Required | Description |
|----------|----------|-------------|
| `MATRIX_HOMESERVER` | Yes | Homeserver URL (e.g. `https://matrix.org`) |
| `MATRIX_ACCESS_TOKEN` | Yes* | Access token (preferred over password) |
| `MATRIX_USER_ID` | With password | Full user ID (`@user:server`) |
| `MATRIX_PASSWORD` | Alt* | Password (alternative to token) |
| `MATRIX_DEVICE_ID` | Recommended | Stable device ID for E2EE persistence |
| `MATRIX_ENCRYPTION` | No | Set `true` to enable E2EE |
| `MATRIX_ALLOWED_USERS` | No | Comma-separated allowed user IDs |
| `MATRIX_HOME_ROOM` | No | Room ID for cron/notifications |
| `MATRIX_REACTIONS` | No | Enable processing reactions (default: true) |
| `MATRIX_REQUIRE_MENTION` | No | Require @mention in rooms (default: true) |
| `MATRIX_FREE_RESPONSE_ROOMS` | No | Room IDs exempt from mention requirement |
| `MATRIX_AUTO_THREAD` | No | Auto-create threads (default: true) |
\* Either `MATRIX_ACCESS_TOKEN` or `MATRIX_USER_ID` + `MATRIX_PASSWORD` is required.
## Config YAML Entries
Add to `~/.hermes/config.yaml` under a `matrix:` key for declarative settings:
```yaml
matrix:
require_mention: true
free_response_rooms:
- "!roomid1:matrix.org"
- "!roomid2:matrix.org"
auto_thread: true
```
These override to env vars only if the env var is not already set.
## End-to-End Encryption (E2EE)
E2EE protects messages so only participants can read them. Hermes uses
matrix-nio's Olm/Megolm implementation.
### 1. Install E2EE Dependencies
```bash
# macOS
brew install libolm
# Ubuntu/Debian
sudo apt install libolm-dev
# Then install matrix-nio with E2EE support:
pip install "matrix-nio[e2e]"
```
### 2. Enable Encryption
Set in `~/.hermes/.env`:
```bash
MATRIX_ENCRYPTION=true
MATRIX_DEVICE_ID=HERMES_BOT
```
### 3. How It Works
- On first connect, Hermes creates a device and uploads encryption keys.
- Keys are stored in `~/.hermes/platforms/matrix/store/`.
- On shutdown, Megolm session keys are exported to `exported_keys.txt`.
- On next startup, keys are imported so the bot can decrypt old messages.
- The `MATRIX_DEVICE_ID` ensures the bot reuses the same device identity
across restarts. Without it, each restart creates a new "device" in
Matrix and old keys become unusable.
### 4. Verifying E2EE
1. Create an encrypted room in Element.
2. Invite your bot user.
3. Send a message — the bot should respond.
4. Check logs: `grep -i "e2ee\|crypto\|encrypt" ~/.hermes/logs/gateway.log`
## Room Configuration
### Inviting the Bot
1. Create a room in Element or any Matrix client.
2. Invite the bot: `/invite @hermes-bot:your.domain.com`
3. The bot auto-accepts invites (controlled by `MATRIX_ALLOWED_USERS`).
### Home Room
Set `MATRIX_HOME_ROOM` to a room ID for cron jobs and notifications:
```bash
MATRIX_HOME_ROOM=!abcde12345:matrix.org
```
### Free-Response Rooms
Rooms where the bot responds to all messages without @mention:
```bash
MATRIX_FREE_RESPONSE_ROOMS=!room1:matrix.org,!room2:matrix.org
```
Or in config.yaml:
```yaml
matrix:
free_response_rooms:
- "!room1:matrix.org"
```
## Troubleshooting
### "Matrix: need MATRIX_ACCESS_TOKEN or MATRIX_USER_ID + MATRIX_PASSWORD"
Neither auth method is configured. Set `MATRIX_ACCESS_TOKEN` in `~/.hermes/.env`
or provide `MATRIX_USER_ID` + `MATRIX_PASSWORD`.
### "Matrix: whoami failed"
The access token is invalid or expired. Generate a new one via the login API.
### "Matrix: E2EE dependencies are missing"
Install libolm and matrix-nio with E2EE support:
```bash
brew install libolm # macOS
pip install "matrix-nio[e2e]"
```
### "Matrix: login failed"
- Check username and password.
- Ensure the account exists on the target homeserver.
- Some homeservers require admin approval for new registrations.
### Bot Not Responding in Rooms
1. Check `MATRIX_REQUIRE_MENTION` — if `true` (default), messages must
@mention the bot.
2. Check `MATRIX_ALLOWED_USERS` — if set, only listed users can interact.
3. Check logs: `tail -f ~/.hermes/logs/gateway.log`
### E2EE Rooms Show "Unable to Decrypt"
1. Ensure `MATRIX_DEVICE_ID` is set to a stable value.
2. Check that `~/.hermes/platforms/matrix/store/` has read/write permissions.
3. Verify libolm is installed: `python -c "from nio.crypto import ENCRYPTION_ENABLED; print(ENCRYPTION_ENABLED)"`
### Slow Message Delivery
Matrix federation can add latency. For faster responses:
- Use the same homeserver for the bot and users.
- Set `MATRIX_HOME_ROOM` to a local room.
- Check network connectivity between Hermes and the homeserver.
## Quick Start (Automated)
Run the interactive setup script:
```bash
python scripts/setup_matrix.py
```
This guides you through homeserver selection, authentication, and verification.

View File

@@ -241,13 +241,29 @@ class HolographicMemoryProvider(MemoryProvider):
self._auto_extract_facts(messages)
def on_memory_write(self, action: str, target: str, content: str) -> None:
"""Mirror built-in memory writes as facts."""
if action == "add" and self._store and content:
try:
"""Mirror built-in memory writes as facts.
- add: mirror new fact to holographic store
- replace: search for old content, update or re-add
- remove: lower trust on matching facts so they fade naturally
"""
if not self._store:
return
try:
if action == "add" and content:
category = "user_pref" if target == "user" else "general"
self._store.add_fact(content, category=category)
except Exception as e:
logger.debug("Holographic memory_write mirror failed: %s", e)
elif action == "replace" and content:
category = "user_pref" if target == "user" else "general"
self._store.add_fact(content, category=category)
elif action == "remove" and content:
# Lower trust on matching facts so they decay naturally
results = self._store.search_facts(content, limit=5)
for fact in results:
if content.strip().lower() in fact.get("content", "").lower():
self._store.update_fact(fact["fact_id"], trust=max(0.0, fact.get("trust", 0.5) - 0.4))
except Exception as e:
logger.debug("Holographic memory_write mirror failed: %s", e)
def shutdown(self) -> None:
self._store = None

View File

@@ -6086,7 +6086,7 @@ class AIAgent:
store=self._memory_store,
)
# Bridge: notify external memory provider of built-in memory writes
if self._memory_manager and function_args.get("action") in ("add", "replace"):
if self._memory_manager and function_args.get("action") in ("add", "replace", "remove"):
try:
self._memory_manager.on_memory_write(
function_args.get("action", ""),

430
scripts/setup_matrix.py Executable file
View File

@@ -0,0 +1,430 @@
#!/usr/bin/env python3
"""Interactive Matrix setup wizard for Hermes Agent.
Guides you through configuring Matrix integration:
- Homeserver URL
- Token auth or password auth
- Device ID generation
- Config/env file writing
- Optional: test room creation and message send
- E2EE verification
Usage:
python scripts/setup_matrix.py
"""
import getpass
import json
import os
import secrets
import sys
import urllib.error
import urllib.request
from pathlib import Path
# ---------------------------------------------------------------------------
# Helpers
# ---------------------------------------------------------------------------
def _hermes_home() -> Path:
"""Resolve ~/.hermes (or HERMES_HOME override)."""
return Path(os.environ.get("HERMES_HOME", Path.home() / ".hermes"))
def _prompt(msg: str, default: str = "") -> str:
"""Prompt with optional default. Returns stripped input or default."""
suffix = f" [{default}]" if default else ""
val = input(f"{msg}{suffix}: ").strip()
return val or default
def _prompt_bool(msg: str, default: bool = True) -> bool:
"""Yes/no prompt."""
d = "Y/n" if default else "y/N"
val = input(f"{msg} [{d}]: ").strip().lower()
if not val:
return default
return val in ("y", "yes")
def _http_post_json(url: str, data: dict, timeout: int = 15) -> dict:
"""POST JSON and return parsed response. Raises on HTTP errors."""
body = json.dumps(data).encode()
req = urllib.request.Request(
url,
data=body,
headers={"Content-Type": "application/json"},
method="POST",
)
try:
with urllib.request.urlopen(req, timeout=timeout) as resp:
return json.loads(resp.read())
except urllib.error.HTTPError as exc:
detail = exc.read().decode(errors="replace")
raise RuntimeError(f"HTTP {exc.code}: {detail}") from exc
except urllib.error.URLError as exc:
raise RuntimeError(f"Connection error: {exc.reason}") from exc
def _http_get_json(url: str, token: str = "", timeout: int = 15) -> dict:
"""GET JSON, optionally with Bearer auth."""
req = urllib.request.Request(url, method="GET")
if token:
req.add_header("Authorization", f"Bearer {token}")
try:
with urllib.request.urlopen(req, timeout=timeout) as resp:
return json.loads(resp.read())
except urllib.error.HTTPError as exc:
detail = exc.read().decode(errors="replace")
raise RuntimeError(f"HTTP {exc.code}: {detail}") from exc
except urllib.error.URLError as exc:
raise RuntimeError(f"Connection error: {exc.reason}") from exc
def _write_env_file(env_path: Path, vars: dict) -> None:
"""Write/update ~/.hermes/.env with given variables."""
existing: dict[str, str] = {}
if env_path.exists():
for line in env_path.read_text().splitlines():
line = line.strip()
if line and not line.startswith("#") and "=" in line:
k, v = line.split("=", 1)
existing[k.strip()] = v.strip().strip("'\"")
existing.update(vars)
lines = ["# Hermes Agent environment variables"]
for k, v in sorted(existing.items()):
# Quote values with spaces or special chars
if any(c in v for c in " \t#\"'$"):
lines.append(f'{k}="{v}"')
else:
lines.append(f"{k}={v}")
env_path.parent.mkdir(parents=True, exist_ok=True)
env_path.write_text("\n".join(lines) + "\n")
try:
os.chmod(str(env_path), 0o600)
except (OSError, NotImplementedError):
pass
print(f" -> Wrote {len(vars)} vars to {env_path}")
def _write_config_yaml(config_path: Path, matrix_section: dict) -> None:
"""Add/update matrix: section in config.yaml (creates file if needed)."""
try:
import yaml
except ImportError:
print(" [!] PyYAML not installed — skipping config.yaml update.")
print(" Add manually under 'matrix:' key.")
return
config: dict = {}
if config_path.exists():
try:
config = yaml.safe_load(config_path.read_text()) or {}
except Exception:
config = {}
config["matrix"] = matrix_section
config_path.parent.mkdir(parents=True, exist_ok=True)
config_path.write_text(yaml.dump(config, default_flow_style=False, sort_keys=False))
try:
os.chmod(str(config_path), 0o600)
except (OSError, NotImplementedError):
pass
print(f" -> Updated matrix section in {config_path}")
def _generate_device_id() -> str:
"""Generate a stable, human-readable device ID."""
return f"HERMES_{secrets.token_hex(4).upper()}"
# ---------------------------------------------------------------------------
# Login flows
# ---------------------------------------------------------------------------
def login_with_token(homeserver: str) -> dict:
"""Validate an existing access token via whoami."""
token = getpass.getpass("Access token (hidden): ").strip()
if not token:
print(" [!] Token cannot be empty.")
sys.exit(1)
whoami_url = f"{homeserver}/_matrix/client/v3/account/whoami"
print(" Validating token...")
resp = _http_get_json(whoami_url, token=token)
user_id = resp.get("user_id", "")
device_id = resp.get("device_id", "")
print(f" Authenticated as: {user_id}")
if device_id:
print(f" Server device ID: {device_id}")
return {
"MATRIX_ACCESS_TOKEN": token,
"MATRIX_USER_ID": user_id,
}
def login_with_password(homeserver: str) -> dict:
"""Login with username + password, get access token."""
user_id = _prompt("Full user ID (e.g. @bot:matrix.org)")
if not user_id:
print(" [!] User ID cannot be empty.")
sys.exit(1)
password = getpass.getpass("Password (hidden): ").strip()
if not password:
print(" [!] Password cannot be empty.")
sys.exit(1)
login_url = f"{homeserver}/_matrix/client/v3/login"
print(" Logging in...")
resp = _http_post_json(login_url, {
"type": "m.login.password",
"identifier": {
"type": "m.id.user",
"user": user_id,
},
"password": password,
"device_name": "Hermes Agent",
})
access_token = resp.get("access_token", "")
device_id = resp.get("device_id", "")
resolved_user = resp.get("user_id", user_id)
if not access_token:
print(" [!] Login succeeded but no access_token in response.")
sys.exit(1)
print(f" Authenticated as: {resolved_user}")
if device_id:
print(f" Device ID: {device_id}")
return {
"MATRIX_ACCESS_TOKEN": access_token,
"MATRIX_USER_ID": resolved_user,
"_server_device_id": device_id,
}
# ---------------------------------------------------------------------------
# Test room + message
# ---------------------------------------------------------------------------
def create_test_room(homeserver: str, token: str) -> str | None:
"""Create a private test room and return the room ID."""
create_url = f"{homeserver}/_matrix/client/v3/createRoom"
try:
resp = _http_post_json(create_url, {
"name": "Hermes Test Room",
"topic": "Auto-created by hermes setup_matrix.py — safe to delete",
"preset": "private_chat",
"visibility": "private",
}, timeout=30)
# Set auth header manually (createRoom needs proper auth)
room_id = resp.get("room_id", "")
if room_id:
print(f" Created test room: {room_id}")
return room_id
except Exception:
pass
# Fallback: use curl-style with auth
req = urllib.request.Request(
create_url,
data=json.dumps({
"name": "Hermes Test Room",
"topic": "Auto-created by hermes setup_matrix.py — safe to delete",
"preset": "private_chat",
"visibility": "private",
}).encode(),
headers={
"Content-Type": "application/json",
"Authorization": f"Bearer {token}",
},
method="POST",
)
try:
with urllib.request.urlopen(req, timeout=30) as resp:
data = json.loads(resp.read())
room_id = data.get("room_id", "")
if room_id:
print(f" Created test room: {room_id}")
return room_id
except Exception as exc:
print(f" [!] Room creation failed: {exc}")
return None
def send_test_message(homeserver: str, token: str, room_id: str) -> bool:
"""Send a test message to a room. Returns True on success."""
txn_id = secrets.token_hex(8)
url = (
f"{homeserver}/_matrix/client/v3/rooms/"
f"{urllib.request.quote(room_id, safe='')}/send/m.room.message/{txn_id}"
)
req = urllib.request.Request(
url,
data=json.dumps({
"msgtype": "m.text",
"body": "Hermes Agent setup verified successfully!",
}).encode(),
headers={
"Content-Type": "application/json",
"Authorization": f"Bearer {token}",
},
method="PUT",
)
try:
with urllib.request.urlopen(req, timeout=15) as resp:
data = json.loads(resp.read())
event_id = data.get("event_id", "")
if event_id:
print(f" Test message sent: {event_id}")
return True
except Exception as exc:
print(f" [!] Test message failed: {exc}")
return False
def check_e2ee_support() -> bool:
"""Check if E2EE dependencies are available."""
try:
import nio
from nio.crypto import ENCRYPTION_ENABLED
return bool(ENCRYPTION_ENABLED)
except (ImportError, AttributeError):
return False
# ---------------------------------------------------------------------------
# Main
# ---------------------------------------------------------------------------
def main():
print("=" * 60)
print(" Hermes Agent — Matrix Setup Wizard")
print("=" * 60)
print()
# -- Homeserver --
print("Step 1: Homeserver")
print(" A) matrix.org (public, for testing)")
print(" B) Custom homeserver (self-hosted)")
choice = _prompt("Choose [A/B]", "A").upper()
if choice == "B":
homeserver = _prompt("Homeserver URL (e.g. https://matrix.example.com)")
if not homeserver:
print(" [!] Homeserver URL is required.")
sys.exit(1)
else:
homeserver = "https://matrix-client.matrix.org"
homeserver = homeserver.rstrip("/")
print(f" Using: {homeserver}")
print()
# -- Authentication --
print("Step 2: Authentication")
print(" A) Access token (recommended)")
print(" B) Username + password")
auth_choice = _prompt("Choose [A/B]", "A").upper()
if auth_choice == "B":
auth_vars = login_with_password(homeserver)
else:
auth_vars = login_with_token(homeserver)
print()
# -- Device ID --
print("Step 3: Device ID (for E2EE persistence)")
server_device = auth_vars.pop("_server_device_id", "")
default_device = server_device or _generate_device_id()
device_id = _prompt("Device ID", default_device)
auth_vars["MATRIX_DEVICE_ID"] = device_id
print()
# -- E2EE --
print("Step 4: End-to-End Encryption")
e2ee_available = check_e2ee_support()
if e2ee_available:
enable_e2ee = _prompt_bool("Enable E2EE?", default=False)
if enable_e2ee:
auth_vars["MATRIX_ENCRYPTION"] = "true"
print(" E2EE enabled. Keys will be stored in:")
print(" ~/.hermes/platforms/matrix/store/")
else:
print(" E2EE dependencies not found. Skipping.")
print(" To enable later: pip install 'matrix-nio[e2e]'")
print()
# -- Optional settings --
print("Step 5: Optional Settings")
allowed = _prompt("Allowed user IDs (comma-separated, or empty for all)")
if allowed:
auth_vars["MATRIX_ALLOWED_USERS"] = allowed
home_room = _prompt("Home room ID for notifications (or empty)")
if home_room:
auth_vars["MATRIX_HOME_ROOM"] = home_room
require_mention = _prompt_bool("Require @mention in rooms?", default=True)
auto_thread = _prompt_bool("Auto-create threads?", default=True)
print()
# -- Write files --
print("Step 6: Writing Configuration")
hermes_home = _hermes_home()
env_path = hermes_home / ".env"
_write_env_file(env_path, auth_vars)
config_path = hermes_home / "config.yaml"
matrix_cfg = {
"require_mention": require_mention,
"auto_thread": auto_thread,
}
_write_config_yaml(config_path, matrix_cfg)
print()
# -- Verify connection --
print("Step 7: Verification")
token = auth_vars.get("MATRIX_ACCESS_TOKEN", "")
do_test = _prompt_bool("Create test room and send message?", default=True)
if do_test and token:
room_id = create_test_room(homeserver, token)
if room_id:
send_test_message(homeserver, token, room_id)
print()
# -- Summary --
print("=" * 60)
print(" Setup Complete!")
print("=" * 60)
print()
print(" Config written to:")
print(f" {env_path}")
print(f" {config_path}")
print()
print(" To start the Matrix gateway:")
print(" hermes gateway --platform matrix")
print()
if not e2ee_available:
print(" To enable E2EE later:")
print(" pip install 'matrix-nio[e2e]'")
print(" Then set MATRIX_ENCRYPTION=true in .env")
print()
print(" Docs: docs/matrix-setup.md")
print()
if __name__ == "__main__":
main()