feat: runtime monkey-patch instead of file patching — zero fork required
The plugin now monkey-patches HonchoMemoryProvider._do_session_init at plugin load time instead of requiring changes to any file in the Hermes repo. This means: - No modifications to plugins/memory/honcho/__init__.py or any other file - No fork needed — pure plugin approach - Survives Hermes upgrades without merge conflicts - Removed docs/honcho-injector.md (replaced by docs/how-it-works.md) - Updated README with new architecture description Config file at /opt/data/identity-config.json remains the single source of truth for mappings.
This commit is contained in:
101
README.md
101
README.md
@@ -3,51 +3,60 @@
|
||||
Maps platform-specific user IDs (Discord snowflake, Telegram UID, terminal
|
||||
session) and kanban boards to stable Honcho peer names. Eliminates
|
||||
`user-default-t_*` peers from kanban workers and unifies a user's identity
|
||||
across platforms (Discord + Telegram → same Honcho peer).
|
||||
across platforms.
|
||||
|
||||
**Zero modifications to the Hermes repo.** No fork required. The plugin
|
||||
uses runtime monkey-patching at plugin load time to wrap Honcho's session
|
||||
initialization — no files are changed on disk.
|
||||
|
||||
## Architecture
|
||||
|
||||
```
|
||||
┌──────────────────────┐
|
||||
│ identity-config.json │
|
||||
│ /opt/data/ │
|
||||
└──────┬───────────────┘
|
||||
│ read on init
|
||||
┌──────────────────┼──────────────────┐
|
||||
│ │ │
|
||||
▼ ▼ ▼
|
||||
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
|
||||
│ pre_gateway │ │ on_session │ │ Honcho │
|
||||
│ dispatch │ │ start hook │ │ injector │
|
||||
│ hook (log) │ │ (log/track) │ │ (session.py)│
|
||||
└──────────────┘ └──────────────┘ └──────┬───────┘
|
||||
│
|
||||
resolves peer_name
|
||||
before Honcho init
|
||||
┌──────────────────────────┐
|
||||
│ identity-config.json │
|
||||
│ /opt/data/ │
|
||||
└──────┬───────────────────┘
|
||||
│ reads on every resolve
|
||||
┌──────────────────┼───────────────────────┐
|
||||
│ │ │
|
||||
▼ ▼ ▼
|
||||
┌──────────────┐ ┌──────────────┐ ┌──────────────────────┐
|
||||
│ pre_gateway │ │ /identity │ │ Honcho monkey-patch │
|
||||
│ dispatch │ │ slash cmd │ │ (runtime, no files) │
|
||||
│ hook (log) │ │ (manage) │ └──────────┬───────────┘
|
||||
└──────────────┘ └──────────────┘ │
|
||||
injects peer_name
|
||||
into kwargs["user_id"]
|
||||
BEFORE Honcho session init
|
||||
```
|
||||
|
||||
Two components work together:
|
||||
## How it works
|
||||
|
||||
1. **This plugin** (user-installed) — provides `/identity` slash command for
|
||||
config management, `pre_gateway_dispatch` logging, and `on_session_start`
|
||||
tracking. Installed via `hermes plugins install`.
|
||||
1. **Plugin loads** → `register()` is called → monkey-patches
|
||||
`HonchoMemoryProvider._do_session_init` with a wrapper.
|
||||
|
||||
2. **Honcho injector** (~6 lines in `plugins/memory/honcho/session.py`) — reads
|
||||
the config file and `HERMES_KANBAN_TASK` env var to inject the correct
|
||||
`runtime_user_peer_name` into Honcho's session initialization. See
|
||||
[`docs/honcho-injector.md`](docs/honcho-injector.md).
|
||||
2. **Kanban worker starts** → Honcho tries to init → no `user_id` from
|
||||
gateway → the wrapper calls `get_peer_name()` → reads the task body
|
||||
from `HERMES_KANBAN_DB` → extracts `context_peer: <name>` → injects
|
||||
it as `user_id` → Honcho creates the session with the correct peer.
|
||||
|
||||
3. **Gateway session starts** (Discord/Telegram) → normal flow with
|
||||
platform user ID → monkey-patch is bypassed (user_id already set).
|
||||
|
||||
4. **Missing config or env** → returns None → Honcho behaves exactly as
|
||||
before (creates `user-default-*` peers — safe fallback).
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
# 1. Install the plugin
|
||||
hermes plugins install gitea:code.lazyworkhorse.net/Hermes/hermes-identity-plugin
|
||||
# 1. Install the plugin from Gitea
|
||||
hermes plugins install ssh://git@code.lazyworkhorse.net:2222/Hermes/hermes-identity-plugin.git
|
||||
|
||||
# 2. Apply the Honcho injector patch (see docs/honcho-injector.md)
|
||||
# 3. Create the config file
|
||||
# 2. Create the config file (persistent volume)
|
||||
cp config.sample.json /opt/data/identity-config.json
|
||||
# 4. Edit /opt/data/identity-config.json with your mappings
|
||||
# 5. Restart gateways
|
||||
|
||||
# 3. Edit /opt/data/identity-config.json with your mappings
|
||||
# 4. Restart gateways to pick up the plugin
|
||||
```
|
||||
|
||||
## Config file: `/opt/data/identity-config.json`
|
||||
@@ -56,7 +65,9 @@ cp config.sample.json /opt/data/identity-config.json
|
||||
{
|
||||
"mappings": [
|
||||
{"platform": "discord", "id": "479136126737711105", "peer": "thierry"},
|
||||
{"platform": "telegram", "id": "123456789", "peer": "thierry"}
|
||||
{"platform": "telegram", "id": "123456789", "peer": "thierry"},
|
||||
{"platform": "matrix", "id": "@thierry:example.org", "peer": "thierry"},
|
||||
{"platform": "terminal", "id": "default", "peer": "thierry"}
|
||||
],
|
||||
"boards": {
|
||||
"default": "thierry",
|
||||
@@ -69,7 +80,7 @@ cp config.sample.json /opt/data/identity-config.json
|
||||
|
||||
## Task body convention
|
||||
|
||||
Every kanban task MUST include a `context_peer` in its body:
|
||||
Every kanban task SHOULD include a `context_peer` in its body:
|
||||
|
||||
```markdown
|
||||
Do research on Postgres migration costs.
|
||||
@@ -79,23 +90,25 @@ context_peer: thierry
|
||||
```
|
||||
```
|
||||
|
||||
Profiles (Claire, Ashley, Finn, Matt) MUST include this when calling
|
||||
`kanban_create`. The `enforce_context_peer` config flag controls whether
|
||||
missing `context_peer` causes an error.
|
||||
Profiles (Claire, Ashley, Finn, Matt) set this when calling `kanban_create`.
|
||||
|
||||
**If `context_peer` is missing**, the plugin falls back to the board
|
||||
config (e.g., `boards.default` → `thierry`). If no board config either,
|
||||
it uses `fallback_peer`. If that's also unset → `user-default-*` (safe).
|
||||
|
||||
## Commands
|
||||
|
||||
- `/identity status` — show current config and resolved peer
|
||||
- `/identity list` — list all mappings
|
||||
- `/identity add discord <id> <peer>` — add a new mapping
|
||||
- `/identity rm <index>` — remove mapping
|
||||
- `/identity board <slug> <peer>` — set board peer
|
||||
- `/identity rm <index>` — remove mapping by index
|
||||
- `/identity board <slug> <peer>` — set board's default peer
|
||||
- `/identity help` — full help
|
||||
|
||||
## Enforcing the convention
|
||||
## Safety
|
||||
|
||||
Add this to the kanban-worker skill or the profile's system prompt:
|
||||
|
||||
> When creating a kanban task with `kanban_create`, you MUST include
|
||||
> `context_peer: <peer_name>` in the task body as a metadata block.
|
||||
> Use the user's Honcho peer name — not your own profile name.
|
||||
- The monkey-patch is applied ONLY at plugin load time, before any session.
|
||||
- If the plugin is uninstalled or fails to load, Honcho is untouched.
|
||||
- If the config file is missing, all resolution returns None → Honcho
|
||||
creates `user-default-*` as today.
|
||||
- No data loss risk. No changes to any file in the Hermes repo.
|
||||
|
||||
Reference in New Issue
Block a user