Agent Zero AI framework
Avoid reload prompts for scoped plugin changes
Alessandro758f74fd7578
diff --git a/helpers/plugins.py b/helpers/plugins.pyindex 14d9a37be..4441cbea0 100644--- a/helpers/plugins.py+++ b/helpers/plugins.py@@ -121,7 +121,7 @@ class PluginUpdateInfo(BaseModel):def register_watchdogs():- def on_plugin_change(events: list[WatchItem]):+ def on_plugin_change(events: list[WatchItem], frontend_reload: bool = True):plugin_names: list[str] = []for path, _event in events:path = path.replace("\\", "/")@@ -132,7 +132,11 @@ def register_watchdogs():plugin_names.append(plugin_name)print_style.PrintStyle.debug("Plugins watchdog triggered", plugin_names)python_change = any(path.endswith('.py') for path, _event in events)- after_plugin_change(plugin_names or None, python_change=python_change)+ after_plugin_change(+ plugin_names or None,+ python_change=python_change,+ frontend_reload=frontend_reload,+ )relevant_patterns = ["**/extensions/**/*", TOGGLE_FILE_PATTERN, HOOKS_SCRIPT]@@ -162,7 +166,7 @@ def register_watchdogs():*expand_patterns(f"*/{projects.PROJECT_META_DIR}/plugins/"),*expand_patterns(f"*/{projects.PROJECT_META_DIR}/agents/*/plugins/"),],- handler=on_plugin_change,+ handler=lambda events: on_plugin_change(events, frontend_reload=False),)# add watchdogs for plugin overrides in /agents/plugins and /usr/agents/plugins@@ -173,16 +177,21 @@ def register_watchdogs():files.get_abs_path(subagents.USER_AGENTS_DIR),],patterns=[*expand_patterns(f"*/plugins/*/")],- handler=on_plugin_change,+ handler=lambda events: on_plugin_change(events, frontend_reload=False),)@extension.extensible-def after_plugin_change(plugin_names: list[str] | None = None, python_change:bool=False):+def after_plugin_change(+ plugin_names: list[str] | None = None,+ python_change: bool = False,+ frontend_reload: bool = True,+):clear_plugin_cache(plugin_names)if python_change:refresh_plugin_modules(plugin_names)- send_frontend_reload_notification(plugin_names)+ if frontend_reload:+ send_frontend_reload_notification(plugin_names)def refresh_plugin_modules(plugin_names: list[str] | None = None):@@ -582,7 +591,9 @@ def toggle_plugin(files.write_file(enabled_file, "")else:files.write_file(disabled_file, "")- after_plugin_change([plugin_name])+ after_plugin_change(+ [plugin_name], frontend_reload=not (project_name or agent_profile)+ )@extension.extensiblediff --git a/helpers/plugins.py.dox.md b/helpers/plugins.py.dox.mdindex e5c1e77e1..6eb0310f3 100644--- a/helpers/plugins.py.dox.md+++ b/helpers/plugins.py.dox.md@@ -17,7 +17,7 @@- `PluginUpdateInfo` (`BaseModel`)- Top-level functions:- `register_watchdogs()`-- `after_plugin_change(plugin_names: list[str] | None=..., python_change: bool=...)`+- `after_plugin_change(plugin_names: list[str] | None=..., python_change: bool=..., frontend_reload: bool=...)`- `refresh_plugin_modules(plugin_names: list[str] | None=...)`- `clear_plugin_cache(plugin_names: list[str] | None=...)`- `get_plugin_roots(plugin_name: str=...) -> List[str]`: Plugin root directories, ordered by priority (user first).@@ -53,6 +53,8 @@stale global or scoped disable files, and disable attempts are rejected.- Config hooks receive `hook_context={"caller": caller}` with one of `ui`,`agent`, or `api`; this is behavioral context, not an authorization boundary.+- Project- and agent-scoped plugin changes invalidate runtime caches without a+ frontend reload prompt because the loaded WebUI extension bundle is global.- Update this file whenever public functions, classes, persistence behavior, path/security assumptions, side effects, or cross-module contracts change.- Observed side-effect areas: filesystem reads, filesystem writes, filesystem deletion, WebSocket state, plugin state, settings/state persistence, secret handling.- Imported dependency areas include: `__future__`, `asyncio`, `glob`, `helpers`, `helpers.defer`, `helpers.watchdog`, `json`, `pathlib`, `pydantic`, `re`, `regex`, `time`, `typing`.diff --git a/tests/test_plugin_activation_ui.py b/tests/test_plugin_activation_ui.pyindex 43505b715..7799b7f29 100644--- a/tests/test_plugin_activation_ui.py+++ b/tests/test_plugin_activation_ui.py@@ -147,9 +147,44 @@ def test_scoped_plugin_without_settings_form_exposes_configuration_index():assert "context.pluginMeta?.has_config_screen" in settings_html+def test_scoped_plugin_watchdogs_skip_frontend_reload(monkeypatch):+ handlers = {}+ changes = []+ monkeypatch.setattr(+ plugins.watchdog,+ "add_watchdog",+ lambda **kwargs: handlers.setdefault(kwargs["id"], kwargs["handler"]),+ )+ monkeypatch.setattr(+ plugins,+ "after_plugin_change",+ lambda names=None, python_change=False, frontend_reload=True: changes.append(+ (names, python_change, frontend_reload)+ ),+ )++ plugins.register_watchdogs()+ handlers["plugins_agents"](+ [["/tmp/usr/agents/custom/plugins/_code_execution/.toggle-0", "delete"]]+ )+ handlers["plugins_roots"](+ [["/tmp/plugins/_code_execution/.toggle-0", "delete"]]+ )++ assert changes == [+ (["_code_execution"], False, False),+ (["_code_execution"], False, True),+ ]++def test_toggle_plugin_writes_project_scope_file_immediately(tmp_path, monkeypatch):monkeypatch.setattr(files, "_base_dir", str(tmp_path))- monkeypatch.setattr(plugins, "after_plugin_change", lambda *_args, **_kwargs: None)+ changes = []+ monkeypatch.setattr(+ plugins,+ "after_plugin_change",+ lambda names, **kwargs: changes.append((names, kwargs)),+ )monkeypatch.setitem(sys.modules,"helpers.projects",@@ -175,3 +210,7 @@ def test_toggle_plugin_writes_project_scope_file_immediately(tmp_path, monkeypatassert (scoped_plugin_dir / ".toggle-1").exists()assert not (scoped_plugin_dir / ".toggle-0").exists()+ assert changes == [+ (["example"], {"frontend_reload": False}),+ (["example"], {"frontend_reload": False}),+ ]