Skip to content

The agent that grows with you

feat(telemetry): record plugin installs as extension-install events

teknium1ed798cf85cf4
diff --git a/hermes_cli/plugin_packs.py b/hermes_cli/plugin_packs.py
index 68c36de7b6a..a041a6b5e15 100644
--- a/hermes_cli/plugin_packs.py
+++ b/hermes_cli/plugin_packs.py
@@ -360,6 +360,7 @@ def install_pack_plugins(
_set_plugin_enabled,
)
from hermes_cli.plugins_admission import AdmissionRefused
+ from hermes_cli.plugins_cmd_install import recorded_install
results: List[PackInstallResult] = []
def _fail(display: str, error: str) -> None:
@@ -373,8 +374,10 @@ def install_pack_plugins(
continue
console.print(f"[dim]Installing {display} @ {rp.entry.ref[:12]}...[/dim]")
try:
- target, manifest, installed_name = _install_plugin_core(
- rp.identifier, force=force, ref=rp.entry.ref)
+ # A bare pack name resolved through the plugin catalog; repo entries are custom sources.
+ target, manifest, installed_name = recorded_install(
+ lambda: _install_plugin_core(rp.identifier, force=force, ref=rp.entry.ref),
+ catalog_name=None if rp.entry.repo else rp.entry.name, identifier=rp.identifier)
except PluginOperationError as exc:
_fail(display, str(exc))
continue
diff --git a/hermes_cli/plugins_cmd_install.py b/hermes_cli/plugins_cmd_install.py
index 8c76d4a80d9..58ac0032700 100644
--- a/hermes_cli/plugins_cmd_install.py
+++ b/hermes_cli/plugins_cmd_install.py
@@ -12,7 +12,7 @@ import os
import sys
import tempfile
from pathlib import Path
-from typing import Any, Optional
+from typing import Any, Callable, Optional
from hermes_cli.cli_output import line_input
@@ -403,6 +403,24 @@ def _install_plugin_core(
return target, installed_manifest, installed_manifest.get("name") or target.name
+def recorded_install(install: Callable[[], tuple], *, catalog_name: Optional[str], identifier: str) -> tuple:
+ """Run one plugin install attempt (a core ``(target, manifest, installed_name)`` call) and record
+ it as a shared-metrics extension install: failed when it raises, success unless it replaced an
+ already-installed plugin (a reinstall is not an install)."""
+ from hermes_cli.observability.shared_metrics_events import record_extension_install
+
+ source = "catalog" if catalog_name else ("local" if identifier.startswith("file://") else "url")
+ before = set(_pc()._read_install_metadata())
+ try:
+ result = install()
+ except Exception:
+ record_extension_install(kind="plugin", source=source, name=catalog_name, outcome="failed")
+ raise
+ if result[2] not in before:
+ record_extension_install(kind="plugin", source=source, name=catalog_name, outcome="success")
+ return result
+
+
def cmd_install(
identifier: str,
force: bool = False,
@@ -454,15 +472,18 @@ def cmd_install(
console.print(format_scan_report(scan_result))
return _pc()._is_tty() and _pc()._ask_yes(" Install anyway? Only continue if you trust the source. [y/N]: ")
- try:
+ def _install() -> tuple:
if entry is not None:
- target, installed_manifest, installed_name = catalog.install_catalog_entry(
+ return catalog.install_catalog_entry(
entry, force=force, ref=ref, allow_removed=allow_removed, scan_decision_cb=_interactive_scan_decision,
python_deps=not no_deps)
- else:
- target, installed_manifest, installed_name = _pc()._install_plugin_core(
- identifier, force=force, ref=ref, scan_decision_cb=_interactive_scan_decision,
- python_deps=not no_deps, allow_removed=allow_removed)
+ return _pc()._install_plugin_core(
+ identifier, force=force, ref=ref, scan_decision_cb=_interactive_scan_decision,
+ python_deps=not no_deps, allow_removed=allow_removed)
+
+ try:
+ target, installed_manifest, installed_name = recorded_install(
+ _install, catalog_name=entry.name if entry is not None else None, identifier=identifier)
except _pc().PluginOperationError as e:
_pc()._fail(console, f"[red]{'Blocked' if isinstance(e, _pc().PluginScanBlocked) else 'Error'}:[/red] {e}")
if not _pc()._looks_like_plugin_dir(target):
@@ -563,13 +584,14 @@ def dashboard_install_plugin(
pass
except _pc().PluginOperationError as exc:
return {"ok": False, "error": str(exc)}
- try:
+ def _install() -> tuple:
if entry is not None:
- target, installed_manifest, installed_name = catalog.install_catalog_entry(
- entry, force=force, allow_removed=False)
- else:
- target, installed_manifest, installed_name = _pc()._install_plugin_core(
- identifier, force=force, ref=(ref or "").strip() or None)
+ return catalog.install_catalog_entry(entry, force=force, allow_removed=False)
+ return _pc()._install_plugin_core(identifier, force=force, ref=(ref or "").strip() or None)
+
+ try:
+ target, installed_manifest, installed_name = recorded_install(
+ _install, catalog_name=entry.name if entry is not None else None, identifier=identifier)
except _pc().PluginScanBlocked as exc:
fields = ("pattern_id", "severity", "category", "file", "line", "description")
return {
diff --git a/tests/hermes_cli/test_plugins_cmd_catalog.py b/tests/hermes_cli/test_plugins_cmd_catalog.py
index 9f5e360302e..dbe12ae5216 100644
--- a/tests/hermes_cli/test_plugins_cmd_catalog.py
+++ b/tests/hermes_cli/test_plugins_cmd_catalog.py
@@ -136,6 +136,17 @@ def test_kill_list_blocks_cli_dashboard_and_tui_paths(world, monkeypatch):
+def test_custom_install_records_an_anonymous_extension_install_and_reinstall_none(world, monkeypatch):
+ import hermes_cli.observability.shared_metrics_events as events
+
+ calls = []
+ monkeypatch.setattr(events, "record_extension_install", lambda **kw: calls.append(kw))
+ assert pc.dashboard_install_plugin(world["repo"].as_uri(), force=False, enable=False)["ok"]
+ assert pc.dashboard_install_plugin("", force=True, enable=False, catalog_name="cat-plugin")["ok"]
+
+ assert calls == [{"kind": "plugin", "source": "local", "name": None, "outcome": "success"}]
+
+
def test_owner_repo_hash_subdir_shorthand_resolves_like_the_catalog_spelling():
from hermes_cli.plugins_cmd import _resolve_git_url
assert _resolve_git_url("plastic-labs/honcho#hermes-plugin-honcho") == (