Split adapter.py monolith into focused modules; restore Ruff complexity defaults (issue #12)
CI / Gateway plugin tests (pull_request) Successful in 4m59s
CI / Kotlin tests (android host + desktop) (pull_request) Successful in 7m5s

adapter.py was a 3,493-line monolith. Split it into focused modules with
clear separation of responsibilities, bringing it down to ~857 lines:

- Module-level helpers: hooks, classify, pickers, commands, setup,
  defaults, secrets
- Frame-handler mixins: inbound, tool_frames, push_frames, media_frames,
  picker_frames, channel_frames, query_frames
- mixin_base: IrisAdapterBase (declaration-only base for shared attrs)
- adapter.py now holds only IrisAdapter (the composition of the 7 mixins
  + BasePlatformAdapter), register(), and test-facing re-exports

The mixins come before BasePlatformAdapter in the MRO so their methods
override the base; super() calls (e.g. send_image) still resolve to
BasePlatformAdapter. No circular imports; dispatch.py and http_server.py
(instance-method callers) are unaffected.

Ruff complexity ceilings (PLR0911/0912/0913/0915) restored to Ruff's
built-in defaults (12/50/6/5) instead of "just above the current maxima",
which ratchets the bar down as code grows. The existing genuinely-complex
functions (frame builders mirroring the wire schema, the QR matrix builder,
the dispatch table) carry an explicit `# noqa: PLR09xx` marking them as
reviewed, frozen exceptions; new code is held to the default ceilings.

All 125 tests green (94 test_android + 31 test_android_http); no new ruff
errors introduced.
This commit is contained in:
ARIA committed 2026-08-24 20:55:00 +02:00
1 parent 7faaf2aa1c
commit b8e756c3dd
26 files changed
+3101 -2775

No files matched your search

+17 -11
View File
@@ -4,11 +4,17 @@
# hermes-agent/.venv/bin/python -m ruff check gateway-plugin
#
# The rule set is deliberately broad (pycodestyle, pyflakes, isort, pyupgrade,
# bugbear, flake8-simplify, pylint, return, comprehensions). Thresholds below
# reflect the plugin's real shape: it is a single large dispatch surface
# (adapter.py) plus a wire-protocol layer (protocol.py) whose frame builders
# mirror the schema, so the complexity ceilings are set just above the current
# maxima rather than an idealized small-function target.
# bugbear, flake8-simplify, pylint, return, comprehensions).
#
# The pylint complexity ceilings (PLR0911/0912/0913/0915) are left at Ruff's
# built-in defaults (see [lint.pylint]). We deliberately do NOT raise them to
# "just above the current maxima": that ratchets the bar down every time code
# grows (LLM maintenance adds functions, it does not refactor them), so new
# complex code would silently pass. Instead, the handful of genuinely complex
# functions that already exist (frame builders that mirror the wire schema,
# the QR matrix builder, the dispatch table) carry an explicit
# `# noqa: PLR09xx` marking them as reviewed, frozen exceptions. New code is
# held to the default ceilings.
line-length = 100
@@ -32,12 +38,12 @@ select = [
ignore = ["PLC0415"]
[lint.pylint]
# Current maxima in the codebase: 22 branches, 64 statements, 9 returns,
# 8 args (protocol.py:252 frame builder is the lone 11-arg outlier, noqa'd).
max-branches = 24
max-statements = 70
max-returns = 9
max-args = 8
# Ruff's built-in defaults. Existing outliers are noqa'd at the def line
# (search for `# noqa: PLR09`), not absorbed into a raised ceiling.
max-branches = 12
max-statements = 50
max-returns = 6
max-args = 5
[lint.per-file-ignores]
# The e2e / ws_probe drivers are assertion scripts: scenario numbers and