56 Commits

Author SHA1 Message Date
yoniebans
be3d6affc8 refactor(state)!: remove the old session store
hermes_state.py becomes the stand-in plugins import, the rest of the legacy store and its test folder go, and the per-process modules the backend imported from main move under persistence/sqlite/_state/. The backend checks PID namespaces and lease holders through process_identity and its WAL setup through sqlite_support, and its error module takes the shared predicates and classification from storage_errors, so neither helper set has a second copy. The backend, sqlite_support.py and the tests that pin those modules reach their final imports, and the backend-import guard allows no file outside persistence/. The modules no caller imports any more go with it: the agent's onboarding rules (now in session_rules) and gateway/session_admission.py.

The stand-in's SessionDB releases its store on close() and, used again afterwards, opens it again with a warning, as the old class reopened its connection, unless the file at its path was replaced or the store is latched corrupt; a read-only one raises. A close during a call releases the store when the call returns. A named source wins over a source list in its session listing and count.

An agent given a writable stand-in SessionDB as session_db= and no persistence= takes the store handle that SessionDB forwards to as its persistence, so its turn flush, token counts, compression and session row writes go through the storage interface, as an agent given the old SessionDB wrote through it.

The backend-import guard also holds the backend's remaining reads of the process or task home, each with its reason, and refuses any other and any import of the stand-in inside persistence/sqlite/.

Plugin context engines get the agent's store as persistence= beside the deprecated session_db=, in each hook whose signature accepts that keyword, including the rebind after /new, /resume and /branch, and the context engine guide and the plugin guide's replacement table name it. A test fails once the running release reaches the stand-in's removal release, listing what goes with the stand-in.

release_unheld_media and collect_unheld_api_images take a store only: their SessionDB branches, which no caller reaches, go with the gateway's own copies of the admission and transcript queries.
2026-11-17 19:10:57 +01:00
alt-glitch
23ddc546a7 fix(move): scan files that name only a moved file
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.
2026-11-16 18:09:00 +05:30
alt-glitch
5e53407e2c fix(move): a path joined through a folder variable to a moved file is flagged
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.
2026-11-16 18:09:00 +05:30
alt-glitch
3e931466c0 fix(move): files that leave a folder that stays move alone
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.
2026-11-16 17:23:26 +05:30
alt-glitch
fdbb12005b fix(migrate-branch): a renamed name must keep its quoting state on the branch's line
_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.
2026-11-13 20:47:06 +00:00
alt-glitch
44cbf070fc fix(move): migrate-branch --continue keeps unstaged edits and --push refuses a slashed default branch
--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.
2026-11-13 20:47:06 +00:00
alt-glitch
101d061571 fix(move): migrate-branch resumes mid-move and keeps the branch's own text in resolved hunks
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.
2026-11-13 20:47:06 +00:00
alt-glitch
7955edf517 fix(move): migrate-branch runs on real move chunks and rewrites extensionless Python scripts
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.
2026-11-13 20:47:06 +00:00
alt-glitch
7cd5840f78 fix(move): migrate-branch never drops main's or the chunk's changes on a conflict
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.
2026-11-13 20:47:06 +00:00
alt-glitch
285cc20598 feat(move): just migrate-branch carries a branch across module moves
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.
2026-11-13 20:47:06 +00:00
alt-glitch
edd4b3ed51 fix(move): docs pass keeps gateway.platforms before a placeholder as written
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.
2026-11-13 20:47:05 +00:00
alt-glitch
3d7774434f fix(move): count a skipped whole-folder glob only when its folder moves
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.
2026-11-13 20:47:05 +00:00
alt-glitch
1a91ce56b7 fix(move): docs pass keeps whole-folder globs on ambiguous names such as cron/* as written
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.
2026-11-13 20:47:05 +00:00
alt-glitch
d3cb8b4f67 fix(move): docs pass leaves commit and tag permalinks to moved files unchanged
Only a blob/main/ link follows the move; a commit or tag link points at a tree that keeps the old path.
2026-11-13 20:47:05 +00:00
alt-glitch
ddc718e679 fix(move): docs pass runs from a copy of scripts/move outside the checkout
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.
2026-11-13 20:47:05 +00:00
alt-glitch
82e9576c63 fix(move): docs pass skips generated old-path files by path, not by a first-line header 2026-11-13 20:47:05 +00:00
alt-glitch
8309d5967f fix(move): docs pass rewrites a name only where it is code or resolves to a moved module
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.
2026-11-13 20:47:05 +00:00
alt-glitch
e5928a41ac fix(move): read docs with utf-8-sig and keep a BOM on write in rewrite_docs
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.
2026-11-13 20:47:05 +00:00
alt-glitch
f013b0b471 style(move): satisfy the repo ruff config in rewrite_docs 2026-11-13 20:47:05 +00:00
alt-glitch
82b3de05e7 feat(move): rewrite moved paths and module names in docs and comments 2026-11-13 20:47:05 +00:00
alt-glitch
0401485f3c fix(move): commit B for a chunk with nothing to rewrite; copy rows keep their package in the list
`just move-chunk` stopped with "nothing to commit" when no tool changed a file (a moved leaf that nothing
imports), and left commit A as the head. The command now makes commit B without changes, so every chunk has
the same two commits and a second run has nothing left to do.

The package list in pyproject.toml keeps an old package name while a generated file lives under it. A
`copy` row was not counted, so a package kept only by copy rows would have lost its line. No row is in
that position today: both copy rows sit under hermes_cli, which by-path rows keep.
2026-11-13 20:47:05 +00:00
alt-glitch
8a16a8ec90 fix(move): keep import order in multi-name imports; stop instead of deleting ignored files at a move destination
The import rewrite now splits a multi-name import statement in the order of its names, so each module still loads in the same order.
move_roots now deletes only __pycache__ folders at hermes_agent/<ROOT> and refuses when any other file is there.
2026-11-13 20:47:05 +00:00
alt-glitch
a899d5fb50 fix(move): keep the old name in an __import__ whose result the rewrite would change
An __import__ through a variable, a helper, an empty fromlist or five arguments keeps its old module name.

move_roots refuses a Windows ROOT that has a root but no drive (\outside).

The --from-commit help says commit A also holds the MOVES update.
2026-11-13 20:47:05 +00:00
alt-glitch
c2f4063d29 fix(move): refuse a move-chunk ROOT outside the repository before clearing anything
build_chunk.py refuses an absolute ROOT or one with .. instead of deleting that folder before git mv fails.
2026-11-13 20:47:05 +00:00
alt-glitch
62cee6eac6 fix(move): keep the launcher-wrapper exclusion away from a row a later chunk deletes
The row sat directly under the old-updater test row, which the hermes_cli chunk deletes in its hand
fixes, so that pick conflicted on every rebuild. It is now the last row of EXCLUDED.
2026-11-13 20:47:05 +00:00
alt-glitch
7a20cb0edb fix(move): regenerate the skill docs in a chunk, and keep the launcher wrapper's bootstrap import
The docs pass rewrites paths in SKILL.md files, the inputs of website/scripts/generate-skill-docs.py, and
skips the generated pages. Nothing regenerated them, so the docs job failed from the first chunk that
touched a path a skill names. The chunk command and just move-generate now run that generator.

scripts/build/launcher_wrapper.py is the text of minted launchers. It imports hermes_bootstrap first: the
root file, which repairs a torn update and installs the old-name finder before hermes_agent is importable.
The rewrite turned it into hermes_agent.hermes_bootstrap; it is now an excluded site.
2026-11-13 20:47:05 +00:00
alt-glitch
38ecd6d7a1 fix(move): keep a hand-written old-path file in the update startup list
The pyproject rewrite kept an old path in update-startup-files only while a generated file lived there.
The root hermes_bootstrap.py stays hand-written, so its entry was replaced by the new path and updates
stopped syntax-checking the file every launcher imports first.
2026-11-13 20:47:05 +00:00
alt-glitch
c19c9112b6 fix(move): codemod rewrites the startup-file list, keeps names another install reads, adds late() and run-time patch-target sinks 2026-11-13 20:47:05 +00:00
alt-glitch
238faf371d fix(move): by-hand rows for module-name lists anchor the start of the statement 2026-11-13 20:47:05 +00:00
alt-glitch
9efebc8073 refactor(move): share the DEFAULT_CONFIG key reader between the codemod and the docs pass
config_keys moves to renames.py; rewrite_imports.py imports it instead of keeping its own copy.
2026-11-13 20:47:05 +00:00
alt-glitch
64580fce4c fix(move): drop package-list rows of moved packages with no old-path file
A packages.find row ("pkg", "pkg.*") of a moved package stays while
required_names.py gives it a generated old-path file, and goes otherwise:
hermes_agent.* already ships the new place.
2026-11-13 20:47:05 +00:00
alt-glitch
68e6088601 fix(move): codemod rewrites a string only where the code takes a module name
Decision D47. The call-argument sink and the module:attr reading rewrote hook
events, session keys, config keys, i18n keys and message text. A string now
changes only in a sink (sinks.py): import functions and helpers whose
parameter reaches one, validated patch targets, sys.modules keys, logger
names, -m/-c argv pairs, commands given to a process, Python code given to an
interpreter. A name, loop or table that feeds a sink is followed, and
rewritten only when every use feeds a sink. Every other string that names a
moved module or path is flagged with a class of its own.

import a becomes from hermes_agent import a (ruff PLR0402), except where the
from-form changes behaviour: a try that tells a missing module apart, and a
function that removes modules from sys.modules, keep the module form with
noqa. __import__("pkg.mod").Attr gets fromlist. Moved modules under folders
without __init__.py resolve. Code split across literals and f-strings is
edited piece by piece (pieces.py). Path flags need a moved file or folder
after the top folder, so tools/list and hermes-agent/ are not paths.
2026-11-13 20:47:05 +00:00
alt-glitch
b212b83b0e fix(move): exclusion rows follow the base tree and anchor only persisted text
The bot_desktop row anchored text that left the base in ecf7061700, so the
shipped module name was rewritten; it now anchors the base spelling. The
_launcher_script row covered the whole def, including a live import; it now
anchors the minted return statement (anchor_spans widens a return like a def).
print_runtime_command's --module default is persisted text. Two test sites
that exercise old top-level names on purpose get OLD_NAMES rows.
KEPT_NAMES names the reasons whose module names tests may mirror.
2026-11-13 20:47:05 +00:00
alt-glitch
dca9438261 feat(move): add move-chunk, one command for commits A and B of a chunk 2026-11-13 20:47:05 +00:00
alt-glitch
a4c8094d8e fix(move): codemod keeps import bindings, rewrites call-arg strings and pyproject entry points
`import a` became `import hermes_agent.a`, which binds `hermes_agent` for the whole
function: an earlier `hermes_agent.x` read there raised UnboundLocalError (practice
chunk 04, tests/hermes_state/test_fts_layout_drift.py). It now becomes
`import hermes_agent.a as a` and its uses keep their spelling. A function-local
`import a.b` whose new root another read in that function needs is flagged.

A string passed to a call is rewritten when its whole value names a moved module,
`module.attr` or `module:attr` of a name the module defines (`where="batch_runner.AIAgent"`,
`_tools_mod("tui_gateway.checkpoints")`); a bare top-level name needs `(module, attr)`
evidence (`_lazy("hermes_state", "SessionDB")`); a dotted name that only starts with
one is flagged. `"-m", "<mod>"` pairs in call arguments and f-string target heads
(`f"pkg.mod.{name}"`) are rewritten. DEFAULT_CONFIG keys (`agent.reasoning_effort`,
also a module) never change.

pyproject.toml entry points and package-data keys follow their module; package lists
are flagged (the old directory may still hold a shim). The run ends by naming
`just move-generate`, which regenerates the files built from rewritten docstrings.
2026-11-13 20:47:05 +00:00
alt-glitch
d689166f45 fix(move): the codemod never rewrites scripts/move/, whose exclusion anchors hold old names as data 2026-11-13 20:47:05 +00:00
alt-glitch
9948c8f1b1 fix(move): exclusions key on anchor text, BOM and non-UTF-8 files survive, deleted modules skip
Exclusion rows were (path, first line, last line) of the pre-move file. The codemod runs after
commit A, when the file sits at its new path, so no row ever matched a moved file
(hermes_cli/_old_updater.py was rewritten on chunk 11), and in migrate-branch a branch's
inserted lines shifted the site out of its range. Rows are now (path, anchor, reason): the path
also matches the file's new path through this move and the compat MOVES table, and the anchor is
exact source text, widened to the whole def, class or assignment it starts. A row whose anchor is
gone is flagged instead of silently doing nothing. Rows regenerated against origin/main.

A UTF-8 BOM is kept on rewrite; a .py file that is not UTF-8 is skipped with an `undecodable`
flag instead of crashing the whole run. A moved module the working tree no longer has (a branch
deleted it) is left out of the plan instead of raising FileNotFoundError.

String literals were checked against every moved path with a freshly compiled regex each; with
853 paths on chunk 11 that overflowed re's cache and took 80% of the run. One precompiled pattern
now, and the plan goes to each worker once.
2026-11-13 20:47:05 +00:00
alt-glitch
51f0112157 refactor(move): shorten by-hand matcher reasons 2026-11-13 20:47:05 +00:00
alt-glitch
38b461e85a feat(move): leave excluded sites alone, flag identity matchers and exc.name literals as by-hand 2026-11-13 20:47:05 +00:00
alt-glitch
72c161817d feat(move): rewrite programs in strings by parsing them, and flag the ones that do not parse 2026-11-13 20:47:05 +00:00
alt-glitch
860626e922 feat(move): rewrite patch, import and importorskip string targets that resolve in the moved tree 2026-11-13 20:47:05 +00:00
alt-glitch
fb4e37ebaf fix(move): rewrite sys.modules keys on any sys alias and assertLogs logger names 2026-11-13 20:47:05 +00:00
alt-glitch
bced17d3c8 fix(move): rewrite extensionless files that start with a Python shebang 2026-11-13 20:47:05 +00:00
alt-glitch
3fd7b7b4f8 feat(move): rewrite import lines and -m arguments inside code strings
Child-process code passed as python -c text or a string template has no compat finder,
so an old name there fails only at run time; the rehearsal on tui_gateway found 13.
2026-11-13 20:47:05 +00:00
alt-glitch
60d15c0372 feat(move): rewrite old module names from a move commit and flag what it leaves
scripts/move/renames.py reads old -> new dotted module names from a git mv commit.
scripts/move/rewrite_imports.py rewrites imports and their attribute chains with LibCST, plus
the strings the strict compat finder in tests cannot see: -m module arguments of child
processes, sys.modules keys and logger names. Every other site that names a moved module or
path is printed as a flag with its class, and the run fails until it is resolved.
libcst joins the dev dependency group; just move-rewrite runs it.
2026-11-13 20:47:05 +00:00
alt-glitch
33426a018e fix(shims): platform folders pass a release's scan; an exists file is a marker that refuses to load
Released code takes plugins/platforms/<name>/ for a bundled platform only when the folder holds __init__.py
and plugin.yaml, and loads <name>/gateway_env.py by path only after that. The list kept gateway_env.py for
16 platforms and nothing else, so after plugins moves the scan found no platform and never read those files.
An updater that restarts paused gateways itself after the swap reads that scan to strip platform credentials
from a served profile's environment (by the code: v0.22.7 and v0.23.0, and v0.23.1 on Windows). Measured with
a v0.23.1 process whose checkout was swapped: 24 prefixes with no platform found, 60 with all 26.

Each of the 26 platform folders now keeps a marker __init__.py (kind exists) and a byte copy of plugin.yaml
(kind copy). The gateway_env.py rows become by-path, which is what a release does with them.

An exists file used to be a forwarding shim. It is now a marker that raises ImportError naming the moved
module. A gateway that started before the update and loads a platform late would otherwise get the moved
adapter, which is not an instance of the adapter base class it holds; it now fails with a message that says
to restart.
2026-11-13 20:45:11 +00:00
alt-glitch
d818406f00 fix(shims): -m launches forward into their own tree; copy rows cover data files
Two cases the generated old-path files did not handle.

A `python -m <old name>` launch puts the current folder first on sys.path. When that folder holds another
hermes_agent/ package (a developer's checkout opened as a workspace), the old-path package found it and
forwarded into the wrong tree. The generated file now puts its own root first for a `-m` launch, as it
already did when run as a script.

A `copy` row keeps a byte copy of a moved file at its old path. The generator resolved every row to
`<module>.py`, so a row for a data file would have copied the sibling module's source. A row whose name is
not a .py file now copies that file. Released apps fetch such a file from main by URL.
2026-11-13 18:48:18 +00:00
alt-glitch
2e6d0e6767 fix(shims): a generated old-path file run as a script reaches the update repair
After a failed forward the generated file imported hermes_bootstrap only when Python was locating a module
for `python -m` (sys.argv[:1] == ["-m"]). A file that runs as __main__ (`python cli.py`, a documented
command) is a process entry too: with hermes_agent/compat/__init__.py cut short by a killed update it raised
SyntaxError and the checkout was not restored. Both launches now reach the bootstrap; a plain import still
re-raises without it, and a healthy launch never gets to this branch.
2026-11-13 18:45:33 +00:00
alt-glitch
ca771e9650 fix(move-shims): an old-name python -m launch on a healthy tree no longer runs the whole bootstrap
The generated old-path file imported the root hermes_bootstrap on every python -m launch, so light targets that never imported it (an old updater's abort recovery, uninstall) ran launch preparation and dependency activation, and exited 1 when activation failed.
It now forwards first and imports hermes_bootstrap only when forwarding fails during a python -m launch (a torn or moved-aside hermes_agent), then forwards once more. The torn-update test tears the compat package itself, so it fails when the repair comes after the compat import.
2026-11-13 18:45:33 +00:00
alt-glitch
f0a4d954b8 fix(move-shims): an old-name python -m launch reaches the killed-update repair before hermes_agent imports
Package shims import the root hermes_bootstrap first during a python -m launch, and relaunch_command reads the -m module from sys.orig_argv while Python is still locating it.
Six acp_adapter modules that an editor ACP server imports lazily get old-path files.
2026-11-13 18:45:33 +00:00