The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
Merge remote-tracking branch 'origin/main' into ethie/pm-clean
ethernet87aa0b55de21
diff --cc hermes_cli/__init__.pyindex d7e37a0e854,9fbe17c0b80..ed527a0585e--- a/hermes_cli/__init__.py+++ b/hermes_cli/__init__.py@@@ -3,41 -3,8 +3,41 @@@import osimport sys- __release_date__ = "2026.9.21"-__version__ = "0.21.5"+ __release_date__ = "2026.9.24"+# Declared for type checkers and the old-updater surface audit; served lazily by __getattr__.+__version__: str+++def __getattr__(name: str) -> str:+ """Old-updater compat: shipped updaters import ``__version__`` after the checkout swap.++ tests/compat/old_updater_surface.json freezes that import. In-tree code resolves+ identity through hermes_cli.version_info.get_version_info(); this reads only the+ install stamp -- never git -- and keeps the pre-stamp placeholder when a checkout+ has no stamp.++ Lazy because ``pm`` is not importable when this package loads: a venv+ editable-installed from a pre-PM tree maps only the top-level packages it knew+ at install time, and the repo root reaches ``sys.path`` only once+ ``hermes_bootstrap`` runs -- after this ``__init__``, from ``hermes_cli.main``.+ """+ if name != "__version__":+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")+ from hermes_cli.steward import read_install_stamp+ try:+ from pm.paths import repo_root+ except ModuleNotFoundError as exc:+ if exc.name != "pm" and not (exc.name or "").startswith("pm."):+ raise+ # The old editable finder may not know the new pm package yet.+ import json+ from pathlib import Path+ try:+ stamp = json.loads((Path(__file__).resolve().parents[1] / "install-stamp.json").read_text(encoding="utf-8-sig"))+ return str(stamp.get("baseVersion") or "0.0.0")+ except (OSError, ValueError, AttributeError):+ return "0.0.0"+ return str(read_install_stamp(repo_root()).get("baseVersion") or "0.0.0")def _ensure_utf8():diff --cc hermes_cli/profile_distribution.pyindex 769fac2e636,767946deae9..bc75209d751--- a/hermes_cli/profile_distribution.py+++ b/hermes_cli/profile_distribution.py@@@ -15,13 -15,12 +15,14 @@@ import subprocesimport tempfilefrom dataclasses import dataclass, fieldfrom datetime import datetime, timezone-from pathlib import Path, PurePosixPath+from pathlib import Pathfrom typing import Any, Dict, List, Optional, Tuple-import yaml+import hermes_yaml as yamlfrom hermes_cli._subprocess_compat import noninteractive_git_env+from hermes_cli.archive_safe import normalize_archive_parts++from hermes_cli.profiles import DEFAULT_EXPORT_EXCLUDE_ROOTfrom utils import rmtree_readonly@@@ -33,13 -32,45 +34,27 @@@ ENV_EXAMPLE_FILENAME = ".env.EXAMPLE# ``distribution_owned:``. config.yaml is dist-owned but preserved on update by default.DEFAULT_DIST_OWNED: Tuple[str, ...] = ("SOUL.md", "config.yaml", "mcp.json", "skills", "cron", MANIFEST_FILENAME)-# Paths NEVER part of a distribution: user-owned, protected on update. Keep consistent with-# ``profiles.py`` export exclusions plus the ``local/`` convention for user customizations.-USER_OWNED_EXCLUDE: frozenset = frozenset({- # Credentials & runtime secrets- "auth.json", ".env",- # Databases & runtime state- "state.db", "state.db-shm", "state.db-wal",- "hermes_state.db", "response_store.db",- "response_store.db-shm", "response_store.db-wal",- "gateway.pid", "gateway_state.json", "processes.json",- "auth.lock", "active_profile", ".update_check",- "errors.log", ".hermes_history",- # User data- "memories", "sessions", "logs", "plans", "workspace", "home",- "image_cache", "audio_cache", "document_cache",- "browser_screenshots", "checkpoints", "sandboxes",- "backups", "cache",- # Infrastructure- "hermes-agent", ".worktrees", "profiles", "bin", "node_modules",- # User customization namespace- "local",+# Distribution-specific user data extends the shared profile/runtime exclusions.- from hermes_cli.profiles import DEFAULT_EXPORT_EXCLUDE_ROOT-+USER_OWNED_EXCLUDE: frozenset = DEFAULT_EXPORT_EXCLUDE_ROOT | frozenset({- "memories", "sessions", "plans", "workspace", "home", "backups", "local",++ "memories", "sessions", "plans", "workspace", "home", "backups", "cache", "local",})+ # Profile distributions own cron definitions, not scheduler state. The runtime has+ # one canonical multi-record store; every sibling under cron/ is runtime data.+ _CRON_STORE_REL = ("cron", "jobs.json")+++ def _is_distribution_runtime_path(parts: Tuple[str, ...]) -> bool:+ """Runtime-owned entries nested under otherwise distribution-owned roots."""+ if len(parts) < 2:+ return False+ if parts[0] == "cron":+ return parts[:2] != _CRON_STORE_REL+ # Root-level dot entries under skills are Hermes bookkeeping (.hub,+ # .usage.json, curator state, bundled manifest, locks, archives, ...).+ return parts[0] == "skills" and len(parts) == 2 and parts[1].startswith(".")++class DistributionError(Exception):"""Raised for distribution install/update failures."""@@@ -135,7 -166,7 +150,7 @@@ def read_manifest(profile_dir: Path) -if not mf_path.is_file():return Nonetry:- data = yaml.safe_load(mf_path.read_text(encoding="utf-8-sig")) # utf-8-sig: tolerate BOM (ours)- data = yaml.safe_load(mf_path.read_text(encoding="utf-8"))++ data = yaml.safe_load(mf_path.read_text(encoding="utf-8-sig"))except Exception as exc:raise DistributionError(f"Failed to parse {mf_path}: {exc}") from excreturn DistributionManifest.from_dict(data or {})@@@ -334,11 -364,10 +348,11 @@@ def _owned_entries(staged: Path, manifereturn# Path-aware allowlist: copy exactly the declared paths.for rel in explicit_owned:- rel_parts = PurePosixPath(rel).parts- if not rel_parts or rel_parts[0] in USER_OWNED_EXCLUDE or _is_distribution_runtime_path(rel_parts):+ try:+ rel_parts = tuple(normalize_archive_parts(rel))+ except ValueError:continue- if rel_parts[0] in USER_OWNED_EXCLUDE:- if ".." in rel_parts or PurePosixPath(rel).is_absolute():++ if rel_parts[0] in USER_OWNED_EXCLUDE or _is_distribution_runtime_path(rel_parts):continuesrc = staged.joinpath(*rel_parts)if src.exists():diff --cc tests/hermes_cli/test_profile_distribution.pyindex caed32af395,a82058039f8..58d9e3d1363--- a/tests/hermes_cli/test_profile_distribution.py+++ b/tests/hermes_cli/test_profile_distribution.py@@@ -14,8 -15,8 +15,9 @@@ import shutiimport statimport subprocessimport sys+ from datetime import datetime, timedelta, timezonefrom pathlib import Path+from types import SimpleNamespaceimport pytestdiff --cc tests/tools/test_write_approval.pyindex 107d200aeda,061e0c54b33..c9ea5d3ae49--- a/tests/tools/test_write_approval.py+++ b/tests/tools/test_write_approval.py@@@ -170,6 -185,83 +171,82 @@@ def test_handle_approve_surfaces_overwrassert "Approved 1" in out and entry in outassert store.memory_entries == ["RULE B: CI is per-head."]++ _KEPT = "Repo lives in ~/src/app; tests via make test"+ _REVIEWED = "Staging DB: pg-staging-2 (old cluster, retiring)"+++ def _review_stages_remove(shape):+ """Seed memory, then stage a remove the way the unattended background review does."""+ from tools.memory_tool import MemoryStore, memory_tool+ from tools.skill_provenance import (reset_current_write_origin, reset_review_attended,+ set_current_write_origin, set_review_attended)+ store = MemoryStore(); store.load_from_disk()+ for entry in (_KEPT, _REVIEWED):+ assert store.add("memory", entry)["success"]+ op = {"action": "remove", "old_text": "Staging DB"}+ kwargs = op if shape == "single" else {"operations": [op, {"action": "add", "content": "Deploys via make ship"}]}+ origin, attended = set_current_write_origin("background_review"), set_review_attended(False)+ try:+ staged = json.loads(memory_tool(target="memory", store=store, **kwargs))+ finally:+ reset_review_attended(attended)+ reset_current_write_origin(origin)+ assert staged["staged"] is True, staged+ return store, staged["pending_id"]+++ @pytest.mark.parametrize("shape", ["single", "batch"])+ def test_approve_refuses_staged_remove_whose_entry_changed(hermes_home, shape):+ """Approval re-ran the staged old_text search against the file as it is THEN, so it+ deleted the newer entry the live agent had written in place, which the approver never saw."""+ from hermes_cli.write_approval_commands import handle_pending_subcommand+ from tools.memory_tool import load_on_disk_store, memory_tool+ from tools import write_approval as wa+ store, pid = _review_stages_remove(shape)+ newer = "Staging DB: pg-staging-3 (migrated 2026-09-20, creds in vault 'stg')"+ assert json.loads(memory_tool(action="replace", old_text="pg-staging-2", content=newer, store=store))["success"]++ out = handle_pending_subcommand(wa.MEMORY, ["approve", pid], memory_store=load_on_disk_store())++ assert load_on_disk_store().memory_entries == [_KEPT, newer], out+ assert "changed since it was staged" in out+ assert wa.get_pending(wa.MEMORY, pid) is not None+ # The pending list shows the whole entry the write targets, not just its search string.+ assert _REVIEWED in handle_pending_subcommand(wa.MEMORY, ["pending"])+++ @pytest.mark.parametrize("shape", ["single", "batch"])+ def test_approve_names_the_entry_a_remove_deleted(hermes_home, shape):+ """Approve listed what a replace overwrote but was silent about what a remove deleted."""+ from hermes_cli.write_approval_commands import handle_pending_subcommand+ from tools.memory_tool import load_on_disk_store+ from tools import write_approval as wa+ _store, pid = _review_stages_remove(shape)+ out = handle_pending_subcommand(wa.MEMORY, ["approve", pid], memory_store=load_on_disk_store())+ assert _REVIEWED not in load_on_disk_store().memory_entries, out+ assert _REVIEWED in out+++ def test_approve_refuses_unpinned_legacy_remove(hermes_home):+ """A record staged before removes were pinned to their full entry has no verifiable target,+ so approve refuses it (keeping the record) instead of replaying its old_text search."""+ from hermes_cli.write_approval_commands import handle_pending_subcommand+ from tools.memory_tool import load_on_disk_store+ from tools import write_approval as wa+ _store, pid = _review_stages_remove("single")+ path = wa._pending_path(wa.MEMORY, pid)+ record = json.loads(path.read_text(encoding="utf-8"))+ record["payload"].pop("matched_entry", None)+ path.write_text(json.dumps(record), encoding="utf-8")+ assert "unpinned legacy target" in handle_pending_subcommand(wa.MEMORY, ["pending"])++ out = handle_pending_subcommand(wa.MEMORY, ["approve", pid], memory_store=load_on_disk_store())++ assert "Approved 0" in out and "predates entry pinning" in out, out+ assert _REVIEWED in load_on_disk_store().memory_entries+ assert wa.get_pending(wa.MEMORY, pid) is not None+-def test_handle_approval_on(hermes_home):from hermes_cli.write_approval_commands import handle_pending_subcommandfrom tools import write_approval as wa