Skip to content

The agent that grows with you

fix(plugins): subdir installs stay updatable via re-install from the recorded source

teknium14a564706da24
diff --git a/hermes_cli/plugins_cmd.py b/hermes_cli/plugins_cmd.py
index b7c65fe521d..736711080e0 100644
--- a/hermes_cli/plugins_cmd.py
+++ b/hermes_cli/plugins_cmd.py
@@ -890,7 +890,8 @@ def cmd_install(
def _pull_plugin_update(target: Path, pinned_msg, not_git_msg, before_pull=None) -> str:
- """Shared ``update`` core: refuse pinned / non-git checkouts, ``git pull``, record the new
+ """Shared ``update`` core: refuse pinned checkouts, ``git pull`` (or re-install from the
+ recorded source when the tree carries no ``.git`` — subdirectory installs), record the new
revision. Returns the pull output; raises :class:`PluginOperationError` on any refusal.
*pinned_msg(install_record)* / *not_git_msg()* build the caller-specific error text."""
metadata = _read_install_metadata()
@@ -898,7 +899,12 @@ def _pull_plugin_update(target: Path, pinned_msg, not_git_msg, before_pull=None)
if install_record.get("pinned") is True:
raise PluginOperationError(pinned_msg(install_record))
if not (target / ".git").exists():
- raise PluginOperationError(not_git_msg())
+ source = install_record.get("source")
+ if not isinstance(source, str) or not source:
+ raise PluginOperationError(not_git_msg())
+ if before_pull is not None:
+ before_pull()
+ return _reclone_plugin_update(source, install_record.get("revision"))
# A URL install whose name/repo later landed on the kill list must not keep pulling new code.
from hermes_cli import plugins_cmd_catalog as catalog
catalog.refuse_if_installed_removed(target.name, target)
@@ -916,6 +922,19 @@ def _pull_plugin_update(target: Path, pinned_msg, not_git_msg, before_pull=None)
return output
+def _reclone_plugin_update(source: str, previous_revision: object) -> str:
+ """Update a plugin whose tree is not a git checkout: a subdirectory install ships only
+ ``<clone>/<subdir>``, so the ``.git`` stays in the temp clone (#65314). Re-run the install
+ from the recorded source (same URL, same subdir) and swap the fresh tree in; the metadata
+ revision is rewritten by the installer. Returns pull-shaped output for the callers."""
+ new_target, _manifest, _name = _install_plugin_core(source, force=True)
+ revision = str(_read_install_metadata().get(new_target.name, {}).get("revision") or "")
+ previous = previous_revision if isinstance(previous_revision, str) else ""
+ if revision and revision == previous:
+ return "Already up to date."
+ return f"Re-installed from {source}: {previous[:8]}..{revision[:8]}"
+
+
def cmd_update(name: str) -> None:
"""Update an installed plugin by pulling latest from its git remote."""
from rich.markup import escape
diff --git a/tests/hermes_cli/test_plugins_cmd.py b/tests/hermes_cli/test_plugins_cmd.py
index 598a72966ab..d6f3af7b4ce 100644
--- a/tests/hermes_cli/test_plugins_cmd.py
+++ b/tests/hermes_cli/test_plugins_cmd.py
@@ -776,6 +776,39 @@ class TestSubdirInstallE2E:
with pytest.raises(PluginOperationError, match="does not exist"):
pc._install_plugin_core(identifier, force=False)
+ def test_subdir_install_stays_updatable(self, tmp_path, monkeypatch):
+ """A subdir install ships no ``.git`` (it stays in the temp clone), so ``plugins update``
+ must re-install from the recorded source instead of refusing (#65314)."""
+ if shutil.which("git") is None:
+ pytest.skip("git not available")
+ import subprocess as sp
+
+ from hermes_cli import plugins_cmd as pc
+
+ repo_root = tmp_path / "monorepo"
+ self._make_repo_with_subdir_plugin(repo_root)
+ plugins_dir = tmp_path / "installed"
+ plugins_dir.mkdir()
+ monkeypatch.setattr(pc, "_plugins_dir", lambda: plugins_dir)
+ monkeypatch.setattr(pc, "_install_metadata_path", lambda: plugins_dir / ".install-metadata.json")
+ target, _manifest, _name = pc._install_plugin_core(f"file://{repo_root}#my-plugin", force=False)
+ assert not (target / ".git").exists()
+
+ (repo_root / "my-plugin" / "__init__.py").write_text("VERSION = 2\n", encoding="utf-8")
+ env = {**os.environ, "GIT_AUTHOR_NAME": "t", "GIT_AUTHOR_EMAIL": "t@t",
+ "GIT_COMMITTER_NAME": "t", "GIT_COMMITTER_EMAIL": "t@t"}
+ sp.run(["git", "commit", "-qam", "v2"], cwd=repo_root, check=True, env=env)
+ new_sha = sp.run(["git", "rev-parse", "HEAD"], cwd=repo_root, check=True,
+ capture_output=True, text=True).stdout.strip()
+
+ output = pc._pull_plugin_update(target, lambda rec: "pinned", lambda: "not git")
+
+ assert "VERSION = 2" in (target / "__init__.py").read_text(encoding="utf-8")
+ assert pc._read_install_metadata()["my-plugin"]["revision"] == new_sha
+ assert "Already up to date" not in output
+ # A second update with nothing new upstream reports up to date, like `git pull`.
+ assert "Already up to date" in pc._pull_plugin_update(target, lambda rec: "pinned", lambda: "not git")
+
def test_installs_portable_root_package_disabled(self, tmp_path, monkeypatch):
if shutil.which("git") is None:
pytest.skip("git not available")