Skip to content

The agent that grows with you

docs: code-health hook refresh, noqa, moves, warnings and where the switch is read

Teknium0e939ec5c7be
diff --git a/AGENTS.md b/AGENTS.md
index c6d6580c71e..b1be0e4ae0f 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -209,7 +209,8 @@ PM activation's `PYTHONPATH` does not survive the test runner's environment scru
`scripts/run_tests.sh` probes `.venv`, then `venv`, then `$HOME/.hermes/hermes-agent/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-push` runs it on
-every push).
+every push; re-run it after pulling to refresh the hook). `# noqa` does not waive a ratchet finding:
+use `# health: allow <RULE> -- <why>`.
## Project Structure
@@ -272,7 +273,8 @@ families: `hermes_state.py` (21), `gateway/run.py` (15), `tools/mcp_tool.py` (15
(blind repointing to defining modules broke 130+ tests).
- **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 (a file already past 2,000 lines may not grow). Split along `<stem>_<topic>` first, in its own commit; behaviour goes in a sibling,
+ go down (a file already past 2,000 lines may not grow). Split along `<stem>_<topic>` first, in its own
+ commit (moved code keeps its cap and existing findings; a copy is new code); 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
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index ffce7d398ee..8c84c41e151 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -369,7 +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. To run it automatically, `python scripts/check --install-hook pre-push` checks each commit you push exactly as CI will judge the PR (`--install-hook` alone runs it on every commit instead, judging what you staged; `--uninstall-hook` removes either; `--no-verify` skips once). The hook covers every worktree of your clone and needs ruff 0.15.10 or `uv` on `PATH`. 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 (a file already past 2,000 lines may not grow: split it first). Pattern rules (blind `except Exception`, missing timeouts, profile-scope hazards such as a hardcoded `~/.hermes` or a new `HERMES_*` env var) track each existing violation where it sits, so existing debt never blocks you, but a new instance does, even one that replaces an identical violation you removed. A file the checker cannot parse or measure fails. Each finding prints its fix; a genuine exception takes a `# health: allow <RULE> -- <why>` comment on the line (or on a comment-only line directly above it), which reviewers read. Rules and targets: `scripts/code_health/config.py`. Maintainers switch the whole ratchet with `ENFORCEMENT` there (`blocking`, `advisory` or `off`): it is read from the base branch, so a one-line commit to main takes effect for every open PR, CI and local hooks alike, and a PR cannot relax its own check; one rule can be demoted with `blocking=False`.
+- **Code health ratchet**: `python scripts/check` runs every blocking lint check CI runs, with the same pinned tools. To run it automatically, `python scripts/check --install-hook pre-push` checks each commit you push exactly as CI will judge the PR (`--install-hook` alone runs it on every commit instead, judging what you staged; `--uninstall-hook` removes either; `--no-verify` skips once). The hook covers every worktree of your clone, judges each commit with that commit's own checker, prefers the repo's `.venv`/`venv` Python (3.11+), and needs ruff 0.15.10 or `uv` on `PATH`; re-run `--install-hook` after pulling to refresh the hook script. 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 (a file already past 2,000 lines may not grow: split it first). Pattern rules (blind `except Exception`, missing timeouts, profile-scope hazards such as a hardcoded `~/.hermes` or a new `HERMES_*` env var) track each existing violation where it sits, so existing debt never blocks you, but a new instance does, even one that replaces an identical violation you removed. Moving code keeps its history: a function or module-level statement moved to another file (and a moved function you lightly edit) keeps the cap and the existing violations it had, while a copy that leaves the original in place is new code. A file the checker cannot parse or measure fails. TypeScript complexity follows ESLint's `complexity` rule except where `scripts/code_health/ts_units.mjs` says otherwise. Each finding prints its fix; a genuine exception takes a `# health: allow <RULE> -- <why>` comment on the line (or on a comment-only line directly above it), which reviewers read; ruff's `# noqa` does not waive a ratchet finding, and a broad catch that logs must keep the traceback (`logger.exception` or `exc_info=True`). Heuristic rules print as warnings until a frozen replay of merged PRs shows they are precise enough to block. Rules and targets: `scripts/code_health/config.py`. Maintainers switch the whole ratchet with `ENFORCEMENT` there (`blocking`, `advisory` or `off`): it is always read from main (CI: the merge commit's first parent; local runs: `origin/main`), never from the branch under test, so a one-line commit to main reaches every open PR on its next CI run (a re-run reuses the old merge commit) and every local hook after a fetch, and a PR cannot relax its own check; one rule can be demoted with `blocking=False`.
### Fail loud at integration boundaries