Skip to content

The agent that grows with you

docs: point contributors and agents at scripts/check and the ratchet

teknium1bc43117dc73f
diff --git a/AGENTS.md b/AGENTS.md
index 8e7529bae9b..118185946f0 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -207,7 +207,8 @@ environment. Non-interactive callers run under `scripts/run-in-hermes-env CMD...
For tests, use the independent test environment in `CONTRIBUTING.md` (or Nix);
PM activation's `PYTHONPATH` does not survive the test runner's environment scrub.
`scripts/run_tests.sh` probes `.venv`, then `venv`, then `$HOME/.hermes/hermes-agent/venv`
-(worktrees sharing the main checkout's venv).
+(worktrees sharing the main checkout's venv). **`python scripts/check`** runs every blocking lint
+check CI runs, with CI's pinned tools; run it before pushing (`--install-hook` = pre-commit hook).
## Project Structure
@@ -268,11 +269,10 @@ families: `hermes_state.py` (21), `gateway/run.py` (15), `tools/mcp_tool.py` (15
function so `monkeypatch.setattr(facade, "name", ...)` is the seam; a patch on the defining
module passes silently. Check the call site's binding before writing a patch target
(blind repointing to defining modules broke 130+ tests).
-- **Don't recreate god files.** A file passing ~2,000 lines or a function passing ~300 lines /
- cyclomatic complexity 30 is the signal to split along `<stem>_<topic>` FIRST, in its own
- commit. New behaviour goes in a new or topical sibling — never appended to a facade.
-- **No `if/elif` ladders ≥ 4 branches keyed on a name/kind** — use a dict/table → handler
- (`_SLASH_DISPATCH` in `cli.py`, `_command_handler_table` in the gateway are the shape).
+- **Size and complexity are ratcheted per unit** (`scripts/code_health/config.py`): new
+ functions CC ≤ 20, ≤ 300 lines, nesting ≤ 6; files ≤ 2,000 lines; units already over may only
+ go down. Split along `<stem>_<topic>` first, in its own commit; behaviour goes in a sibling,
+ never a facade; name ladders become a dict → handler (`_SLASH_DISPATCH`).
- **No re-export shims for internal moves** ("keep the old name importable"). Internal paths
are not API: plugins build on `ctx` and the documented ABCs. The one-time Sep 2026
decomposition compat layer for external plugins has been removed; never reintroduce one.
@@ -285,17 +285,15 @@ families: `hermes_state.py` (21), `gateway/run.py` (15), `tools/mcp_tool.py` (15
- No "defense-in-depth" wrappers, `try/except: pass` around code that cannot fail, or flags
nobody sets. Docstrings/comments keep the WHY, cut the WHAT.
-- **Never infer process identity from argv substrings** (`"serve" in cmdline`) — the bug class
- behind ~10 fleet-update issues (#90778, #87594, #78089, #76129, #91964). Use the canonical
+- **Never infer process identity from argv substrings** (`"serve" in cmdline`; ~10 fleet-update
+ bugs, #90778). Use the canonical
matchers `gateway.status.looks_like_gateway_command_line` and
`hermes_cli.update_cmd._hermes_holder_subcommand`; flag sets are DERIVED from the parser
(`_holder_value_flags()`), never hand-written; match FULL cmdlines and truncate only for
- display. Details: `hermes_cli/AGENTS.md`.
+ display. Details: `hermes_cli/AGENTS.md`. Ratcheted (HX003).
- **Never hardcode `~/.hermes`.** `get_hermes_home()` for code paths, `display_hermes_home()`
- for user-facing text (both from `hermes_constants`). Hardcoding breaks profiles (5 bugs in
- PR #3575). Profile operations themselves are HOME-anchored
- (`_get_profiles_root()` = `Path.home()/.hermes/profiles`) so `hermes -p x profile list`
- sees all profiles — intentional, not a bug.
+ for user-facing text (`hermes_constants`); ratcheted (HX001). `_get_profiles_root()` is
+ HOME-anchored on purpose, so `hermes -p x profile list` sees all profiles.
- **One process may serve many profiles; code that runs outside a turn binds the owning
profile scope explicitly.** A profile = home + secret scope + terminal scope, bound by
`gateway/run.py::_profile_runtime_scope` (turn), `tui_gateway/server.py::@_profile_scoped` +
@@ -308,7 +306,8 @@ families: `hermes_state.py` (21), `gateway/run.py` (15), `tools/mcp_tool.py` (15
deferred callbacks, RPC methods, config readers, thread hops (`spawn_context_thread`), child
spawns (`served_profile_child_env`, never `os.environ.copy()`). Fail-closed reads exist only after
`set_multiplex_active(True)`. Prove live with two homes (A→B→A) under multiplex, not one temp
- `HERMES_HOME`. Advisory lint: `scripts/check_profile_scope_patterns.py`.
+ `HERMES_HOME`. Ratcheted: HX002/HX004/HX005/HX012, PS-P05/P06; the full shape list is the
+ advisory `scripts/check_profile_scope_patterns.py`.
- **Machine facts and resource lookup go through `hermes_platform`.** `hermes_platform.host` is the
one answer for OS family, native architecture (`IsWow64Process2` → `platform.machine()`; never
`PROCESSOR_ARCHITECTURE` alone, it reads AMD64 under x64-on-ARM64 emulation), CPU identity, and
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 7906301f088..4d1bd3166b9 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -369,6 +369,7 @@ User message → AIAgent._run_agent_loop()
- **Error handling**: Catch specific exceptions. Log with `logger.warning()`/`logger.error()` — use `exc_info=True` for unexpected errors so stack traces appear in logs
- **Error messages**: every user-facing error message names the actual cause and the remediation step — never the proximate symptom. A missing API key is "no OpenRouter API key configured — set `OPENROUTER_API_KEY`", never "payment/credit error"; a failed request logs the exception class and message (secret-redacted) rather than an empty reason; a timed-out long job reports the timeout and where the job went, not a fallback-routing noise string. If you know the cause, say it; if you don't, say what you do know plus what to check — never a placeholder that points somewhere else.
- **Cross-platform**: Never assume Unix. See [Cross-Platform Compatibility](#cross-platform-compatibility)
+- **Code health ratchet**: `python scripts/check` runs every blocking lint check CI runs, with the same pinned tools (`--install-hook` makes it your pre-commit hook). Its code-health part gives every function and file its own cap: new functions stay at cyclomatic complexity ≤ 20, ≤ 300 lines and nesting ≤ 6, files at ≤ 2,000 lines, and code already over a target may only get smaller. Pattern rules (blind `except Exception`, missing timeouts, profile-scope hazards such as a hardcoded `~/.hermes` or a new `HERMES_*` env var) compare fingerprints, so existing debt never blocks you but a new instance does. Each finding prints its fix; a genuine exception takes `# health: allow <RULE> -- <why>` on the line, which reviewers read. Rules and targets: `scripts/code_health/config.py`.
### Fail loud at integration boundaries
@@ -973,9 +974,10 @@ refactor/description # Code restructuring
### Before submitting
1. **Run tests**: use `scripts/run_tests.sh` for the same environment and per-file isolation as CI.
-2. **Test manually**: Run `hermes` and exercise the code path you changed
-3. **Check cross-platform impact**: If you touch file I/O, process management, or terminal handling, consider macOS, Linux, and WSL2
-4. **Keep PRs focused**: One logical change per PR. Don't mix a bug fix with a refactor with a new feature.
+2. **Run the lint checks**: `python scripts/check` (the blocking lint lane, locally).
+3. **Test manually**: Run `hermes` and exercise the code path you changed
+4. **Check cross-platform impact**: If you touch file I/O, process management, or terminal handling, consider macOS, Linux, and WSL2
+5. **Keep PRs focused**: One logical change per PR. Don't mix a bug fix with a refactor with a new feature.
### PR description