The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(plugins): a forced reinstall of the same source keeps the user's files
John Paul Solivaddde0670104f
diff --git a/hermes_cli/plugins_cmd_install.py b/hermes_cli/plugins_cmd_install.pyindex 1e99c387818..3befb589784 100644--- a/hermes_cli/plugins_cmd_install.py+++ b/hermes_cli/plugins_cmd_install.py@@ -372,6 +372,18 @@ def _install_plugin_core(except ValueError as e:raise _pc().PluginOperationError(str(e)) from e_check_manifest_version(manifest, plugin_name)+ prior = old_metadata.get(plugin_name)+ # `install --force --ref` is the documented way to move a pin, so a reinstall of the same+ # source is an update: it replaces the plugin's code, never the user's state.+ tracked_edits: list[str] = []+ if (before_swap is None and force and target.is_dir() and not target.is_symlink()+ and isinstance(prior, dict) and prior.get("source") == source):+ from hermes_cli.plugins_cmd_catalog import _carry_user_files, _local_changes+ local, tracked_edits = _local_changes(target)++ def _carry(_manifest, tree):+ return _carry_user_files(target, tree, local)+ before_swap = _carry# A callback may merge user-owned state into the candidate tree; run it first so one scan# admits the final bytes.merged = before_swap(manifest, tmp_target) if before_swap is not None else None@@ -391,7 +403,6 @@ def _install_plugin_core(raise _pc().PluginOperationError(f"Plugin '{plugin_name}' already exists. Use force reinstall "f"or run `hermes plugins update {plugin_name}`.")- prior = old_metadata.get(plugin_name)if target.exists() and requested_revision is None and isinstance(prior, dict) and prior.get("pinned") is True:raise _pc().PluginOperationError(f"Plugin '{plugin_name}' is pinned. Reinstall it with an explicit "@@ -427,6 +438,14 @@ def _install_plugin_core(new_metadata = {**old_metadata, plugin_name: record}from hermes_cli.plugins_transaction import publish_plugin+ if tracked_edits:+ from hermes_cli.plugins_cmd_catalog import _stash_local_files+ # Outside the plugins dir: the discovery scanners recurse into every subdirectory there.+ backup = plugins_dir.parent / "plugins-backup" / f"{target.name}-{str(prior.get('revision') or 'old')[:8]}"+ _stash_local_files(target, tracked_edits, backup)+ _pc()._console().print(+ f"[yellow]Local edits to {len(tracked_edits)} tracked file(s) were not carried over; "+ f"copies are under {backup} (re-apply by hand).[/yellow]")try:publish_plugin(tmp_target, target, old_metadata, new_metadata, require_consent=True,assume_consent=assume_deps_consent)diff --git a/hermes_cli/subcommands/plugins.py b/hermes_cli/subcommands/plugins.pyindex 47501b6c2e4..fe703ee56ee 100644--- a/hermes_cli/subcommands/plugins.py+++ b/hermes_cli/subcommands/plugins.py@@ -22,7 +22,8 @@ def build_plugins_parser(subparsers, *, cmd_plugins: Callable) -> None:help="Bare plugin catalog entry name (see `hermes plugins search`), Git URL, or owner/repo ""shorthand (e.g. anpicasso/hermes-plugin-chrome-profiles)")plugins_install.add_argument(- "--force", "-f", action="store_true", help="Remove existing plugin and reinstall")+ "--force", "-f", action="store_true",+ help="Reinstall over an existing plugin (from the same source, your untracked files are kept)")plugins_install.add_argument("--ref", metavar="COMMIT_SHA",help="Install exactly one immutable 40-character Git commit SHA")diff --git a/tests/hermes_cli/test_plugin_install_ref.py b/tests/hermes_cli/test_plugin_install_ref.pyindex 4d5b33e059a..5f879add763 100644--- a/tests/hermes_cli/test_plugin_install_ref.py+++ b/tests/hermes_cli/test_plugin_install_ref.py@@ -284,6 +284,46 @@ def test_force_reinstall_does_not_drift_pin_without_explicit_new_ref(assert _metadata(home)["demo"]["revision"] == new_sha[email protected]("move", ["pinned-new-ref", "unpinned-reinstall", "other-source"])+def test_force_reinstall_of_the_same_source_keeps_the_users_files(monkeypatch, tmp_path, move):+ """Moving a pin is documented as ``install --force --ref``; like ``update`` it replaces the plugin's+ code, not the user's state. Untracked/ignored files stay live, edits to tracked files go to+ plugins-backup, and nothing the new revision ships is overwritten by the old tree. Another+ repository under the same plugin name is another plugin and still starts clean."""+ from hermes_cli.plugins_cmd import _install_plugin_core++ (tmp_path / "first").mkdir()+ repo, _old, _new = _plugin_repo(tmp_path / "first")+ (repo / ".gitignore").write_text("data/\n", encoding="utf-8")+ old_sha = _commit(repo, "ignore data", "old")+ home = tmp_path / "home"+ monkeypatch.setenv("HERMES_HOME", str(home))+ target, _manifest, _name = _install_plugin_core(+ repo.as_uri(), force=False, ref=old_sha if move == "pinned-new-ref" else None)+ (target / "data").mkdir()+ (target / "data" / "state.json").write_text('{"user": 1}', encoding="utf-8")+ (target / "settings.local.yaml").write_text("mode: mine\n", encoding="utf-8")+ (target / "marker.txt").write_text("edited", encoding="utf-8")+ new_sha = _commit(repo, "newer", "newer")+ if move == "other-source":+ (tmp_path / "other").mkdir()+ repo, _old, new_sha = _plugin_repo(tmp_path / "other")++ target, _manifest, _name = _install_plugin_core(+ repo.as_uri(), force=True, ref=new_sha if move == "pinned-new-ref" else None)++ assert _git(target, "rev-parse", "HEAD") == new_sha+ kept = move != "other-source"+ assert (target / "marker.txt").read_text() == ("newer" if kept else "new")+ assert (target / "data" / "state.json").exists() is kept+ assert (target / "settings.local.yaml").exists() is kept+ backups = list((home / "plugins-backup").glob("demo-*"))+ assert [(b / "marker.txt").read_text() for b in backups] == (["edited"] if kept else [])+ if kept:+ assert (target / "data" / "state.json").read_text() == '{"user": 1}'+ assert (target / "settings.local.yaml").read_text() == "mode: mine\n"++def test_unpinned_install_and_force_reinstall_keep_tracking_head(monkeypatch, tmp_path):from hermes_cli.plugins_cmd import _install_plugin_corediff --git a/website/docs/user-guide/features/plugins.md b/website/docs/user-guide/features/plugins.mdindex 6782dd9976a..c58dd0f6d64 100644--- a/website/docs/user-guide/features/plugins.md+++ b/website/docs/user-guide/features/plugins.md@@ -203,7 +203,12 @@ Hermes checks out the commit detached, verifies that `HEAD` exactly matches therequested SHA, and records the canonical source, installed revision, and pinstatus in the current profile. `hermes plugins update` refuses to move a pinnedplugin; choose a new exact commit explicitly with-`hermes plugins install <source> --force --ref <new-commit>`. The+`hermes plugins install <source> --force --ref <new-commit>`. Like an+update, a forced reinstall from the source the plugin was installed from+replaces its code but keeps your files: untracked and git-ignored files stay in+place, and edits to tracked files are copied to+`~/.hermes/plugins-backup/<name>-<sha>/`. A reinstall from a different source+starts clean; to reset a plugin completely, `hermes plugins remove` it first. Theprofile-local install metadata contains no config values, environment values,secrets, or capability grants.