The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(code-health): oversized-file fix text names the cheap way to comply
Tekniumdf81f543f820
diff --git a/AGENTS.md b/AGENTS.mdindex b1be0e4ae0f..1804f99afdc 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -273,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`): newfunctions 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+ go down (a file already past 2,000 lines may not grow: move a function out to offset, or put new+ tests in a new test file). Split along `<stem>_<topic>` first, in its owncommit (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 pathsdiff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex 8c84c41e151..ced4d38d5a9 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, 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`.+- **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: offset the growth by moving an existing function into a `<stem>_<topic>` sibling, or put new tests in a new test file). 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 boundariesdiff --git a/scripts/code_health/config.py b/scripts/code_health/config.pyindex c8fb158a30b..de0152ab1b9 100644--- a/scripts/code_health/config.py+++ b/scripts/code_health/config.py@@ -31,8 +31,9 @@ METRIC_FIX = {" branch ladder with a dict/table -> handler","FUNC_LINES": "extract phases into named helpers or a topical sibling module","NESTING": "return early, or extract the inner block into a helper",- "FILE_LINES": "split along `<stem>_<topic>` (facade + siblings, see root AGENTS.md); new"- " behaviour goes in a new or topical sibling, never appended to a facade",+ "FILE_LINES": "offset the growth in the same PR: move an existing function or class into a"+ " topical sibling `<stem>_<topic>.py` (moved code keeps its cap; see root AGENTS.md), or put"+ " new tests in a new `test_<stem>_<topic>.py`; new behaviour never goes into a facade","MEASURE": "the file must parse and measure (a file that cannot be measured cannot be"" judged); fix the syntax, or report the measurer bug",}