Skip to content
Back to skills

Hermes Core Patching

ASecurity

Use when patching Hermes' own source, core or Desktop, in a live install.

  • 2 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 21, 2026
ai-agentspythongobashnodetestinggitapi

Works with

  • terminal
  • cli
  • api

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned December 3, 2026

npx -y skills add Rafaelrr5/agent-cortex --skill hermes-core-patching --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Hermes Core Patching?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Hermes Core Patching
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/rafaelrr5-hermes-core-patching/badge)](https://www.skillsdirectory.com/skills/rafaelrr5-hermes-core-patching)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: hermes-core-patching
description: "Use when patching Hermes' own source, core or Desktop, in a live install."
version: 1.0.0
author: Rafael Rocha Ribeiro (github.com/Rafaelrr5)
license: MIT
platforms: [linux, macos, windows]
metadata:
  agent:
    tags: [hermes, python, core, editable-install, pytest, carried-patch, baseline, desktop]
    related_skills: [isolated-worktree-testing, delegated-agent-supervision, measurement-validity, hermes-provider-credentials]
---

# Patching Hermes' own source in a live install

Behaviour described here was checked against upstream `NousResearch/hermes-agent`
`main` at commit `4e4cf69d9b` (`pyproject.toml` version string `0.0.0`). Re-verify the
file references below if your checkout is much newer.

`$HERMES_HOME` below means the Hermes install root (default `~/.hermes`; on Windows
`%LOCALAPPDATA%\hermes`).

## When to Use

A bug or missing behaviour lives in Hermes' **own Python source** (`agent/`,
`hermes_cli/`, `gateway/`, `tools/`, `plugins/`) and the user wants it fixed, not
worked around. Typical openers:

- "this provider keeps cutting off, check whether it's the implementation"
- "fix it", after you diagnosed something in the core
- a client, adapter or tool behaves wrongly and no config setting reaches it

**Desktop/Electron UX with no setting** (where links open, pane defaults, gestures) is
the same class with a different build loop: prove no setting exists, check upstream,
flip the smallest routing default, invert the tests that lock the old default, and
rebuild with `hermes desktop --build-only --force-build`. Full procedure in
`references/desktop-renderer-patching.md`. The core rules below (re-read before
editing, real reproduction, carried-patch reporting, no commit unasked) apply to both.

**Not this skill:** choosing or configuring credentials/providers →
`hermes-provider-credentials`.

The defining constraint of this class: **you are editing the source of the process you
are currently running from.** Everything below follows from that.

## Step 1 — Locate the tree and confirm it is editable

A git install is an editable install of the `hermes-agent` package, so the source tree
is the checkout under `$HERMES_HOME/hermes-agent`. Confirm:

```bash
cd "$HERMES_HOME/hermes-agent"
git log --oneline -1          # must succeed: this is a git checkout
```

If it is not a git checkout (packaged or bundled desktop install), there is no source
to patch — say so and stop at workarounds.

Editable install means **your edit is live for the next process you spawn**, with no
build step (the opposite of the Desktop side). You can validate a core fix end to end
by running a script with the same Python interpreter Hermes runs on.

## Step 2 — Reproduce against the real thing before touching source

Do not patch from a reading of the code. Replay the failing path **byte-for-byte outside**
Hermes first (a standalone script that speaks the same protocol or calls the same
class), and get a number: how often, under which input shape, with which control
condition flipped.

This separates *the component is broken* from *the component is fine and something
upstream feeds it badly*, which changes the fix completely. Run variants in parallel
(`concurrent.futures`) when each costs seconds; a 4x6 matrix of input shapes is a
minute, and it turns "seems flaky" into a table. Carry that table into the report:
"0/12 vs 6/6" ends an argument that prose cannot.

## Step 3 — Re-read every file immediately before editing it

**The checkout can move under you mid-session.** `hermes update` (run by you, by
another session, or by Desktop's update flow) can land a refactor between your first
read and your first patch, renaming symbols and shifting line counts. Symptoms: a patch
reports success but the surrounding diff looks unfamiliar, or `old_string` fails to
match text you are sure you read.

Defensive habit: `git log --oneline -1` plus a fresh read of the target **in the same
batch as the edit**. If the commit hash changed since your survey, redo the survey.

## Step 4 — Get a clean baseline WITHOUT touching the live checkout

Before blaming your diff for a red test, find out what was already red. Hermes ships a
guard (`tools/self_repo_guard.py`) that **blocks** commands which would rewrite the
working tree of the checkout backing the running process: `git checkout`, `switch`,
`rebase`, `merge`, `pull`, `restore`, `clean`, `cherry-pick`, `revert`, `bisect`,
`reset --hard/--merge/--keep`, `stash` (push/pop/apply; `list`/`show`/`drop` are
allowed), and `worktree move/remove` targeting it. Its block message names the route:
a separate worktree or a shared clone on real disk (not `/tmp`, which is often
RAM-backed), deleted when done.

```bash
SCRATCH="$HERMES_HOME/cache/scratch"
git clone --shared -q "$HERMES_HOME/hermes-agent" "$SCRATCH/base"   # cheap, same objects
cd "$SCRATCH/base"
scripts/run_tests.sh tests/<the suspect file>
```

`run_tests.sh` provisions the checkout's own test environment (it re-executes itself
under `scripts/run-in-hermes-env` when needed), so the clone needs no venv wiring.

Compare failure lists. Identical set = pre-existing on `main`, not yours; say that
plainly in the report instead of ignoring it or calling the run clean.

Never get the baseline by reversing your own patch in the live tree (`git apply -R`, run
tests, re-apply) either. A timeout or kill between the two applies leaves the fix
silently reverted, and the next restart loads the old code. If the live tree also holds
other sessions' uncommitted changes, a clone of HEAD is not the same baseline: copy the
working tree (`rsync -a --exclude=.git --exclude=node_modules`), reverse only your diff
inside the copy with `patch -p1 -R`, and compare the two failure lists.

Delete the clone when done, and `cd` out of it first (Windows refuses to delete a
directory that is any process's working directory).

## Step 5 — Test with the project runner, never bare pytest

```bash
cd "$HERMES_HOME/hermes-agent"
scripts/run_tests.sh tests/agent/test_a.py tests/agent/test_b.py
```

The project's own rule (root `AGENTS.md`): always `scripts/run_tests.sh`, never bare
`pytest`. The runner starts from an empty environment (`env -i`) so no credential
variable leaks in, sets `TZ=UTC`, `LANG=C.UTF-8` and `PYTHONHASHSEED=0`, and runs each
test file in its own `pytest` subprocess. `tests/conftest.py` additionally blanks
credential-shaped variables and sandboxes `HERMES_HOME`. Bare `pytest` on a machine
with live API keys is the classic "green locally, red in CI" generator.

The runner is **file-granular**: name files or directories; bare pytest flags such as
`-k 'pattern'` are forwarded to every per-file run.

Operational notes:

- The agent's foreground terminal timeout caps at 600 s by default; longer calls are
  promoted to a tracked background process. A handful of files is fast, so name them.
- Piping the run through `tail` reports `tail`'s exit code, not the suite's. Read the
  summary line, not the exit code.
- When the runner finds the environment missing or stale it re-runs under
  `scripts/run-in-hermes-env`, which provisions tooling and can fail offline. Fix the
  environment and retry the runner first. Only if that is impossible, run the named files
  with the checkout's own interpreter (`<venv python> -m pytest <file>`) with provider
  keys unset, `TZ=UTC` and a temporary `HERMES_HOME`, and say in the report that this run
  bypassed the runner. It is a disclosed stopgap, not CI parity, and the rule above still
  stands.

## Step 6 — Tests that state the invariant, not the shape

The project's contribution rules reject change-detector tests and ask for "1–2
invariant tests per fix, proven red on the base". Per fix, assert a **contract**:

- Good: "a message with no `id` produces no bytes on the wire" plus the counterpart "a
  message with an `id` still gets its error reply". Both halves — a one-sided test
  passes when the fix over-corrects.
- Good: "the second turn re-ran session setup but never the one-time handshake" — a
  relationship between two observations, which is what reuse *means*.
- Bad: asserting a literal count, a model list, a config version.

When a refactor changes a private method's signature, the fakes in the test file change
with it. Update the fake to the new contract instead of leaving a compatibility shim.

**A stub that models pooling/lifecycle must mirror both sides of the real
bookkeeping.** Stubbing "acquire" to only *add* to the busy set, while the real one also
*removes* from the idle list, produces a duplicate-entry failure that looks like a bug in
your production code and is not.

## Step 7 — Prove it on the real dependency, then report

Unit green is not the deliverable. Drive the patched class against the actual external
thing (the real CLI, the real endpoint) with Hermes' own interpreter, and print the
numbers the user cares about: latency per turn, finish reasons, resource state after
`close()`, no orphan processes.

Report shape:

- one short section per fix, each naming **what outcome that fix buys**;
- a small table of the load-bearing design decisions ("change this and X breaks"), not
  a narration of the edit;
- the measured before/after;
- pre-existing failures called out as pre-existing, with how you verified;
- `git diff --stat` and an explicit "nothing committed yet — branch and PR, or leave it
  in the working tree?" Do not commit or push to the user's install unasked.

Name the maintenance cost: an uncommitted core patch is a **carried patch**.
`hermes update` autostashes local changes and may leave them parked in `git stash`
instead of re-applied. Check upstream before re-applying after an update.

## Example: subprocess protocol bridges

For a bridge that drives an external agent CLI over a JSON-RPC-style protocol, test the
protocol seams, not only completion text:

- Resubmitted transcripts must render tool calls and tool results explicitly (call ID,
  name, arguments, linked result); assistant tool-call messages often have no content.
- Treat a permission request whose operation payload is missing or unparseable as a
  denial — never allow what your guards could not inspect.
- Extract fallback JSON tool calls with `json.JSONDecoder.raw_decode`, not a
  brace-matching regex; arguments contain nested braces.
- Make pooled-subprocess `close()` race-safe against a concurrent spawn (a lock-protected
  generation token), and verify notifications without an ID get no reply while requests
  with one still do.

## Pitfalls

- **`hermes chat -q` does not run your patched code.** The CLI relays the turn to the
  running gateway (`hermes_cli/gateway_chat.py`), so a core patch stays invisible until
  that gateway restarts. Probe in-runtime instead: `hermes --print-runtime-command -- chat`
  prints the exact interpreter command as JSON, and you can call the patched function from
  there. Do the end-to-end proof only after the gateway reload, from a helper started
  outside the gateway's process tree (on Windows, for example, via WMI), since the session
  doing the work usually dies with the gateway.
- **Compare the gateway's start time with the patched files' mtime before restarting.**
  If the gateway started after the edit, it already runs the fix. A restart would drop
  in-flight sessions, including the one doing the work, for no gain.
- **A test harness may only kill what it spawned.** Track the PID and port of the process
  you launched; killing by command-line pattern also takes down servers other sessions are
  using. Use a dedicated test port, and for token-protected local servers read the token
  first, or every probe returns 403 and proves nothing.
- **A rule that exists but "didn't apply" often lives on only one of several entry
  paths.** The gateway reaches the same busy decision from more than one admission path
  (both `gateway/run_inbound.py` and `gateway/session_ingress_live_turn.py` call
  `_hm_busy_preempt`), so an exemption added on one can be missing on the other. Find the
  log line that acted, find every caller that can emit it, and patch the path the event
  actually took. A test that fails without the fix shows you picked the right one.
- **When an input handler "does nothing" in some state, read its early-return gates in
  order.** A flag that looks idle-only (such as "agent running") can stay true during the
  very action the handler should interrupt, so the interrupt branch must sit before that
  gate.
- **Never recursive-grep from the repo root.** The tree is large enough that an unscoped
  grep can blow a tool timeout. Scope to `agent/`, `hermes_cli/`, `gateway/`, `tools/`,
  with a `*.py` glob.
- **Many entry points are thin forwarders.** Grepping `def <name>` in the facade module
  returns nothing while the body sits in a `<stem>_<topic>.py` sibling. Search by topic
  across the directory.
- **Patch where production *reads*, not where the symbol is defined.** Siblings often do
  `from <facade> import name` inside a function, so the facade is the patch seam; a
  monkeypatch on the defining module passes silently and tests nothing.
- **Don't fix two things and present them as one.** When a session yields a config fix
  and a code fix, state which one cures the reported symptom, or the user may later
  revert the load-bearing one.
- **Don't call a defect "unfixed upstream" after fixing it locally.** Update any notes
  that recorded the old state in the same pass, or the next session re-diagnoses solved
  work.
- **Resource pools need the failure path decided explicitly.** Anything reused across
  calls (subprocess, connection, session) must be *discarded*, not recycled, when the
  turn raised — an unread reply left on the wire gets attributed to the next request.
  Decide the concurrency rule too, and write it in the docstring.
- **Tests never write to the real `$HERMES_HOME`.** The project rules forbid it; use
  `tmp_path` and `monkeypatch`.

Files in this skill

  • SKILL.md10.8 KB
  • references/desktop-renderer-patching.md3.9 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.