tools/ holds model tools. These six files register none: they snapshot and restore a working directory for the agent loop, /rollback, /undo's changed-files line and `hermes checkpoints`. They move next to the agent loop that takes the checkpoints: tools/checkpoint_manager.py -> agent/checkpoints/manager.py tools/checkpoint_maintenance.py -> agent/checkpoints/maintenance.py tools/checkpoint_pruning.py -> agent/checkpoints/pruning.py tools/checkpoint_refs.py -> agent/checkpoints/refs.py tools/checkpoint_undo_hint.py -> agent/checkpoints/undo_hint.py tools/checkpoint_manager_profile_rename.py -> agent/checkpoints/manager_profile_rename.py agent/checkpoints/__init__.py is a docstring only. Nine test files move to tests/agent/checkpoints/. Every importer changes its import line in place, inside the same function. Nothing stays at the old paths: none of the six names is on the plugin API list, the shipped-release list or the old-updater list. Behaviour is unchanged. The four loggers keep their tools.checkpoint_* names, so the lines stay under `hermes logs --component tools`. The folder is not a root checkpoints/ package because the checkpoint store is HERMES_HOME/checkpoints, which is the same directory as such a package on an install whose checkout root is HERMES_HOME. agent.* is already packaged, so pyproject.toml and the lists of root packages do not change. The import and docs rewrites were made by scripts/move/rewrite_imports.py and rewrite_docs.py.
24 lines
1.1 KiB
Python
24 lines
1.1 KiB
Python
"""The one reading of a ``/rollback`` argument every surface shares: a list number or a checkpoint hash.
|
|
|
|
A hash copied from the ``/rollback`` list keeps naming the same checkpoint after another is taken (a
|
|
list position moves), and a short hash can be all digits. A digit string without a leading zero is a
|
|
list number while it is in range (``1..N``); any other string of 4+ characters (the hash minimum) is a
|
|
hash. Shorter out-of-range digits stay main's "Invalid checkpoint number" error.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
_MIN_HASH = 4
|
|
|
|
|
|
def resolve_checkpoint_ref(checkpoints: list, ref: str) -> str:
|
|
"""The commit ``ref`` names in ``checkpoints`` (``list_checkpoints``, newest first). Raises
|
|
``ValueError`` for an out-of-range list number; any other string is passed through as a hash
|
|
(``restore``/``diff`` validate it)."""
|
|
ref = (ref or "").strip()
|
|
if ref.isdigit() and not ref.startswith("0"):
|
|
if int(ref) <= len(checkpoints):
|
|
return checkpoints[int(ref) - 1].get("hash", ref)
|
|
if ref.isdigit() and len(ref) < _MIN_HASH:
|
|
raise ValueError(f"Invalid checkpoint number. Use 1-{len(checkpoints)}.")
|
|
return ref
|