tools/ holds model tools. These three files register none: they send a
message to a platform for `hermes send` and for cron delivery, through
gateway adapters and gateway config. They move to the gateway package:
tools/send_message_tool.py -> gateway/outbound/send.py
tools/send_message_senders.py -> gateway/outbound/senders.py
tools/send_message_targets.py -> gateway/outbound/targets.py
Twelve test files move with them to tests/gateway/outbound/. Every importer
changes its import line in place. Nothing stays at the old paths: none of
the three names is on the plugin API list, the shipped-release list or the
old-updater list.
Behaviour is unchanged. The logger name stays tools.send_message_tool in
the three files and in the QQ Bot sender that shares it, so the lines stay
under `hermes logs --component tools`. The boundary-lint baseline changes
12 keys and no count, because its keys carry the module path of the
underscore names five bundled plugins import.
The import and docs rewrites were made by scripts/move/rewrite_imports.py
and rewrite_docs.py.
The codemod picked the files to read by the old top-level folder name and the old paths. A file that joins a folder variable to a moved file's name mentions neither, so it was never read and its path was never flagged. The names of the files that left a folder that stays are now search words too. For a whole-package move that set is empty and the files read are the same.
When a file leaves a folder that stays, the folder's name no longer counts
as moved, so the only trace of the old place in a join is the file's own
name. rewrite_imports.py flagged that name only when the join started at a
repository-root expression: tools_dir = ROOT / "tools" followed by
tools_dir / "blueprints.py" kept its old path with no flag.
A path join that ends in the name of a file that left a folder that stays
is now flagged whatever expression holds the folder. For a whole-package
move that set of files is empty, so its output is unchanged.
rewrite_imports.py and rewrite_docs.py treated every folder above a moved
file as a moved folder. That holds when a whole package moves. When a few
files leave a folder it does not: moving three files from tools/ to cron/
printed 58 flags that named tools/, tests/ and tests/tools/ as moved, and
rewrote every `tools/*.py` glob in the docs to `cron/*.py`.
A folder now counts as moved only when every tracked file under it moved.
renames.py holds that rule once (emptied_folders) together with the path
questions the import and TOML passes ask (MovedPaths); the docs pass reads
the same rule. A path built from pieces is flagged by the name of the
outermost file or folder the move took away, so a file that left a folder
that stays is still found. A docs glob follows a move only when every file
it matches moved together under its own name; otherwise it stays as
written and is counted as partial-glob.
rewrite_imports.py takes --no-compat-table for a move whose old names no
release, updater or plugin imports. The default still writes the table,
so build_chunk.py and migrate_branch.py are unchanged.
Whole-folder moves give the same output as before: on
`git mv acp_adapter hermes_agent/acp_adapter` both scripts print the same
log and write the same diff with and without this change.
utils.py held three subjects in one 871-line file. It is now a package with
one module per subject: utils/files.py (atomic writes, temp files, file mode
and owner, signatures and digests, JSON and YAML file helpers), utils/urls.py
(the base_url helpers) and utils/env.py (truthy values, env numbers, proxy
env helpers). utils/__init__.py re-exports every public name, so no importer
changes. Function bodies are unchanged, no function-level import moved, and
the logger keeps the name "utils".
Tests patch a name in the module that now defines it. Patches stay on the
package where production reads the name through a function-level
"from utils import". The tests of utils itself move to tests/utils/.
A root module that becomes a folder drops out of anything that copies root
*.py files plus a fixed list of packages, so the fixtures that build a partial
source tree now list utils, as do pyproject's packages.find, three check
scripts and the CI change classifier.
packaged-imports knew 69 packages while setuptools ships 181: pyproject's
packages.find leaves `namespaces` at its default of true, so folders
without __init__.py (most of plugins.*) ship too, and the 92 of them
holding Python were never scanned. The shipped set is now every
directory with tracked Python, plus its parents, filtered by `include`,
as setuptools does. Git paths are read as PurePosixPath, so the dotted
names also match on Windows, where str(Path) uses backslashes and the
guard found nothing. test_files_under_a_namespace_directory_are_scanned
fails on the previous guard.
Root AGENTS.md's package section disagreed with three area rules:
- "add none" now excepts the flat siblings tui_gateway/AGENTS.md (RPC
methods) and tools/AGENTS.md (backends) still prescribe;
- the tools/environments/ example says its table still sits in
terminal_tool_backends.py;
- input parsing also allows the area's wire model (Pydantic in
tui_gateway).
Root is 12,038 of its 12,100 characters.
Both changes are the reviewer's patches as posted.
The scan that flags a package the wheel would drop read production
source from a test, which tests/AGENTS.md bans. It is now
scripts/check_packaged_imports.py, registered as `packaged-imports` in
scripts/check with its own lint.yml step, beside `tool-discovery`; the
hook fixture copies it like every guard. It uses only the standard
library: tomllib for the include patterns, the find_packages walk done
over `git ls-files` (a package is reachable only through parent
packages), and ast for imports.
`from acp_adapter import server` and `from . import server` now count
`acp_adapter.server` as imported, not only `acp_adapter`, so a submodule
turned into a folder is caught whichever form imports it.
tests/scripts/test_check_packaged_imports.py covers a root module turned
into a folder, both from-import forms, and a clean tree, on temporary
repos. On the real tree the guard passes, and fails with `toolsets` or
`acp_adapter.server` when either module becomes a folder.
Two review findings on the folder rule:
- A root module or an acp_adapter/ module turned into a folder drops out
of setup.py's _root_py_modules and ships only if
[tool.setuptools.packages.find] include matches it. The FILE_LINES fix
text now names that step, and
test_every_package_packaged_code_imports_is_found fails when packaged
code imports a regular package the wheel would not ship (moving
toolsets.py to toolsets/__init__.py fails it with ['toolsets']).
- Discovery skips a tool package without __init__.py, so
check_tool_discovery counts only candidates whose package has one,
and its message says so. An intent-added tools/newpkg/tool.py with no
__init__.py now fails the guard.
Both changes are the reviewer's patches as suggested.
The file-size fix text asks for a <stem>/ folder, but nothing said what
a good folder looks like. Root AGENTS.md's facade section becomes
"Packages and Python shape":
- <stem>/__init__.py is the facade: its docstring names each module's
job, __all__ is the surface, PEP 562 __getattr__ when eager imports
would cycle, and it holds no behaviour (tools/connectors/ is the model).
- A family folder keeps its ABC or Protocol, one module per variant and
a name-to-variant table (tools/environments/).
- Flat <stem>_<topic>.py siblings stay until touched; none are added.
- A Shape bullet: code imports on 3.11; importing has no side effects;
input is parsed where it enters into a frozen dataclass, Enum or
Literal; one return shape per function; dispatch by table; objects,
not mixins; no module constant kept only for tests to patch.
The rules live in AGENTS.md because that is what agents load on every
turn; root stays inside its 12,100-character budget (11,831). The
FILE_LINES fix text and CONTRIBUTING's Code Style section point at the
section.
tests/scripts/test_code_health_cli.py builds fixture repos with a hand-kept
copy of every guard scripts/check runs; the new guard and what it imports
(tools/registry.py, hermes_constants.py) were missing, so three hook tests
failed on "can't open file". The guard drops its empty-scan branch, which
failed any tree with no tools, and exposes `unreached_registrations` so
tests/scripts/test_check_tool_discovery.py can prove it flags a module
registering outside `<pkg>/tool.py` on a temp repo.
The repo-wide check that every module registering a tool at import is one
discovery imports parsed production source from a test, which
tests/AGENTS.md bans. It is now the `tool-discovery` guard
(scripts/check_tool_discovery.py), run by `scripts/check` and its lint.yml
step, using discovery's own `_module_registers_tools` and
`_tool_module_candidates`.
The FILE_LINES/CC/FUNC_LINES fix text told contributors to split a big file
into a flat `<stem>_<topic>.py` sibling, which is how tools/ grew to 315 flat
files and tests/hermes_cli/ to 1,928. It now says to turn `<stem>.py` into a
`<stem>/` package and move code into a topic module there.
Inside a tools/ package, discovery imports only `<pkg>/tool.py`
(tools/registry.py `_tool_module_candidates`), so a module named anything else
that calls registry.register() at import is dropped without an error. A new
test lists every tracked module under tools/ that registers at import and
fails, naming the module, when discovery would not import it. Root AGENTS.md
and CONTRIBUTING.md carry the same rule.
The attached-client page listed a hand-picked "Method catalog (selected)"
that included methods the shared gateway's /api/ws socket refuses
(session.title, session.usage, session.activate, session.compress,
session.branch, session.close, session.status). Nothing told a client
author that `x-canonical-methods` (53 names) is the set of methods with a
hermes-gateway-v1 wire model of their own, not the set the gateway serves
(it serves 114), or that some methods only reach an older handler.
`scripts/gen_serve_handler_ledger.py` already derives, per method, how
/api/ws answers it. It now also writes that split into the page between
markers, and its `--check` and test fail when the page is stale. The page
explains the authority-first dispatch, the older-handler rule, and what
`x-canonical-methods` means, and the live-session paragraph names the
methods to use on the shared gateway.
scripts/install.ps1 is generated from pm/lock.json; without regenerating it
a fresh install still fetched 2.53.0.3 and the bootstrap-pins drift check
failed.
Refs #148835
The video plugin already reaches tools.fal_common for its managed client,
queue wait and error helpers (all baselined); the direct-key client sits in
the same module so both FAL tools build it the same way.
Follow-up to the salvaged #134062 commit. Drop its repo-walking
structural test (banned shape per tests/AGENTS.md) and instead assert the
read-only-tree mirror actually carries .npmrc to where npm ci runs. The
.npmrc comments now say what the gate mirrors: the root .npmrc carries
only engine-strict; the 14-day floor lives in pnpm-workspace.yaml's
minimumReleaseAge, which npm never reads.
Fixes#134019
npm reads project config only from the directory that owns the
package.json, so scripts/whatsapp-bridge and plugins/platforms/photon/
sidecar never inherited the root .npmrc's min-release-age=14 and their
lockfiles resolved without the cooldown - pinning versions published
days earlier (#134019).
The bridge holds WhatsApp session credentials, parses inbound messages
from arbitrary senders, and the gateway npm-installs exactly the locked
versions for every user (_ensure_bridge_deps), so the gate cannot be
applied user-side.
- add scripts/whatsapp-bridge/.npmrc and plugins/platforms/photon/
sidecar/.npmrc with min-release-age=14, matching the root
- include .npmrc in the photon sidecar _MIRROR_FILES whitelist so the
read-only-tree mirror keeps the gate where npm ci actually runs
- add a structural guard test: every directory with a package-lock.json
must carry a .npmrc with the same floor
The _git() helper ran git with text=True but no encoding=, which the
footgun checker rejects (locale codec on Windows); pass encoding='utf-8',
errors='replace', and the same in the test file's git() helper.
pr_head() checked for the commit only before each fetch, so a head that
only the final fetch retrieved still resolved to "" (PR head unavailable).
Resolve it once after the loop instead.
Refs #128930
Co-authored-by: BearHuddleston <196404565+BearHuddleston@users.noreply.github.com>
A pull_request checkout is refs/pull/N/merge, whose first parent is main's
tip, so merge-base origin/main HEAD always succeeded and the gate could never
reject. The step now gets github.event.pull_request.head.sha, fails closed
when that commit cannot be resolved, and also rejects a head whose root
commits are not all already in main (a main-descended branch that merged an
unrelated history).
Fixes#128930
Co-authored-by: beardthelion <56458543+beardthelion@users.noreply.github.com>
Self-chat rejections logged the full chat/sender id of every other chat
on the owner's account, unconditionally; they now go through
redactWhatsAppId() like the debug events. libsignal's console.info
session dumps (private/root/base keys) are collapsed to their label by
the console wrapper, which now also covers console.info. bridge.log
rotates to one .1 generation above 5 MB when the adapter opens it at
spawn, and full/pre-update backups skip both generations.
Fixes#149860
update_cmd_force_stop now imports tools/process_registry.py (the left-behind
sweep) and gateway/host_topology.py (served homes), so a change to either can
break `hermes update` and must start e2e_upgrade (test_update_ci_routing).
`python -m hermes_cli.main update` from releases before update_cmd.py was split
out runs cmd_update/_cmd_update_impl as `__main__`, so in_historical_update()
did not see them and e.g. bc747001eec5's post-pull update_managed_uv() import
raised instead of handing off, leaving the update half-done. A `__main__` frame
now counts when its code was compiled from this checkout's hermes_cli/main.py;
the current tree's own entry points stay live code via the sentinel local.
The shim runtime tests discovered shims by parsing source (banned in tests).
The shim list is now data (tests/fixtures/retired_updater_shims.json, 63 shims,
generated from the former scan); scripts/ci/check_retired_shims_manifest.py runs
the AST scan as a repo-guards step and fails on drift or an empty scan.
The probe's stdout is appended to $GITHUB_OUTPUT, so a CR/LF in the
fetched generated_at, a skill's source key, or a JSON decode error
would start a new key=value line and could forge status=ok, silencing
the watchdog. Flatten those remote-derived values before formatting.
Fixes#108382
The self-updater gate rejects any plugin script that both fetches from
GitHub and writes or renames files. rom-studio (#153798) trips it on
kit/kit.ts, which downloads the third-party poryscript 3.6.1 compiler
from its own release, checks a fixed sha256 and unpacks it into
kit/.cache. It never fetches or replaces rom-studio's own files, so the
pin stays the only update path (README rule 3).
Teknium ruled to allow it. A maintainer now lists such a file in
scripts/ci/catalog_self_updater_allowlist.json by repo, pinned sha, path
and the file's sha256: a re-pin, an edit to that file or a second
fetching file is gated again. The list lives under scripts/ci/, which an
entry PR may not touch (catalog_changed_entries.py), so a submitter
cannot add themselves. Rule 3 in both rule blocks names the exception.
Review (kvnloo): drop_dead_history only looked at facts with a `previous`
list, so a tool only a deleted checkout pinned (no history) kept its entry
forever. gc now judges every tool row: one with no owners (pre-history)
or matching this checkout's own lock stays, otherwise a row lives while
any owning checkout's install state dir exists. A tool left with no live
row loses its fact.
A checkout that finds an entry another checkout recorded now claims it, so
that checkout's deletion cannot reclaim an entry still in use.
prune_staged_store kept every history row facts.json carries, so a cached
build store shipped superseded tool entries. No other checkout shares a
build store: drop all history before computing the keep set.
Also correct tool_store_pins.py: facts.json now keeps other checkouts' pins
as history, so the remaining reason not to share the account store is that
provisioning other pins writes into it under a concurrent run.
adapter_forwarded.py is a sibling extracted from adapter.py, which already imports
agent.compression_marker.elide/ELISION_MARKER_MAX_LEN (baselined) for the unfurl budget.
The sibling reuses the same marker so forwards and unfurls elide identically; the
published plugin API has no truncation helper to use instead.
_rename_like() compared the sequence of quote characters on the line and the token line-up. A branch
that moved the quotes from the module name to another argument, use(tui_gateway, "callback"), kept
both, so the resolver renamed the bare name into hermes_agent.tui_gateway, an attribute lookup. Each
renamed token's quote parity must now match its lined-up base token; such a line stays a conflict.
--continue stops when tracked files have unstaged changes, which the import rewrite step would discard.
--push compares the branch with the remote default branch's full name, so release/stable is refused too.
just migrate-branch --continue and --abort reuse the interpreter the first run set up, so they start after commit A moved hermes_cli.
A resolved hunk renames only the token that lines up with the renamed one, on a line whose quotes are unchanged; anything else stops.
Commit A of a chunk may also modify hermes_agent/compat/moves.py, which just move-chunk amends into it.
Python scripts without a .py extension that the branch changed go to the import rewriter.
A conflict in a file the branch rewrote was resolved with `git checkout --ours` on the whole
file. That dropped every other hunk the import-rewrite merge brought: main's commits when main
was merged into the chunk between A and B, and hand fixes when commit C carried the trailer.
Now git merges every non-conflicting hunk, and a conflicting hunk is resolved only when one side
changed nothing but module names there (both sides read with moved names spelled the old way); a
line that side renamed keeps the rename, and a line the other side edited takes the same
whole-token rename when that is all the renaming side changed on it. Every other hunk stops with its file and line. The same
rule applies to the final merge of the target.
Commit B is no longer "the last commit with the trailer". Trailers may carry a role
(`Hermes-Move: NN-name move|codemod|fix`); without roles, A is the first trailer commit and B is
only A's direct child, so later trailer commits are hand fixes that arrive with the target.
Also:
- files the branch added only inside a new subdirectory of a package A moved whole are moved to
the new path (git's directory rename detection leaves them behind), then rewritten;
- the codemod gets only files that still exist (a branch that deletes a moved file no longer
wedges on --continue);
- docs lines the branch added are rewritten with scripts/move/rewrite_docs.py, and any non-Python
line the branch added that still names a moved module or path is listed and stops the run
unless --accept-flags;
- --push pushes HEAD to refs/heads/<branch> on the branch's own remote and refuses the remote's
default branch; a detached HEAD is refused up front.
scripts/move/migrate_branch.py finds the move chunks a branch is missing by
their Hermes-Move trailer and, for each in landing order, merges the commit
before the rename, merges the rename with directory rename detection, runs
scripts/move/rewrite_imports.py on the Python files the branch changed, and
merges the import rewrite keeping the branch version of those files. It then
merges the target. Any other conflict stops the run; --continue resumes and
--abort restores the branch. Merges only; the remote is touched only with
--push.
The config.yaml key gateway.platforms.<name>.enabled was rewritten to
hermes_agent.gateway.platforms.<name>.enabled. The config-path deny list
matches gateway.platforms. only when a real segment follows, and a name
token stops at a placeholder or a wildcard, so the bare gateway.platforms
was read as the package. A config path that is also a package, alone or
before a placeholder or wildcard, now stays as written and is counted as
flagged-config-or-module for a person to check.
The docs pass counted a `bare-dir` skip for every `cron/*`, `tools/*` or
`plugins/**` it saw, even in a chunk that does not move that folder, so the
skip counts in the build log were inflated. The check now runs only for a
folder the chunk moves. What the pass writes is unchanged.
Add a test that a whole-folder glob on a moved folder that is not ambiguous
(`tui_gateway/*`) is still rewritten, and that an unmoved `cron/*` counts no
skip.
A glob that takes every file of a folder whose name is also a HERMES_HOME dir or an MCP method family (cron/*, tools/*, plugins/**) is skipped like the bare folder; a file pattern such as cron/*.py still follows the move.
rewrite_docs.py imports the old-path file generator only when it checks a .py path, so a copy of scripts/move outside the checkout no longer exits or fails to import.
English that follows from/import in running prose ("from providers like X") and config keys named like a
moved package (plugins.enabled, providers.<id>.api_key) were rewritten to hermes_agent.* names.
- from M import ... / import M / -m M are rewritten only as code: in a code span, a code fence, a >>> line, or
an import statement that parses as Python and starts its line. A bare top-level word alone is never
rewritten. import M becomes from hermes_agent import M.
- A dotted name is rewritten when it names a moved module or package, or a moved module plus an attribute it
defines; a bare package that is also a config section (agent, plugins, providers, ...) needs the attribute.
- DEFAULT_CONFIG keys (shared reader in renames.py, found wherever hermes_cli moved to) and i18n keys
(locales/en.yaml, first argument of t()) are left alone.
- Files generate_shims.py wrote are skipped.
The windows-footguns check flagged three reads/writes in rewrite_docs without
the policy encoding. Reads now use utf-8-sig; a file that started with a BOM
gets it back via write_bytes so rewritten files keep their bytes.