Agent Zero AI framework
Plugin UX Consolidation (pre-upstream-merge snapshot)
Alessandrof78849065745
diff --git a/plugins/example_agent/plugin.json b/plugins/example_agent/plugin.jsonindex c5c599690..81661b42b 100644--- a/plugins/example_agent/plugin.json+++ b/plugins/example_agent/plugin.json@@ -1,8 +1,9 @@{- "name": "Example Agent",+ "title": "Example Agent","description": "Example agent plugin demonstrating the Agent Zero plugin system.","version": "1.0.0","settings_sections": [],"per_project_config": true,- "per_agent_config": false+ "per_agent_config": false,+ "always_enabled": true}diff --git a/plugins/memory/plugin.json b/plugins/memory/plugin.jsonindex 4063b918d..0afa0fbc1 100644--- a/plugins/memory/plugin.json+++ b/plugins/memory/plugin.json@@ -1,5 +1,5 @@{- "name": "Memory",+ "title": "Memory","description": "Provides persistent memory capabilities to Agent Zero agents.","version": "1.0.0","settings_sections": ["agent"],diff --git a/python/api/plugins.py b/python/api/plugins.pyindex b5b6b4248..54c7bdf90 100644--- a/python/api/plugins.py+++ b/python/api/plugins.py@@ -82,7 +82,14 @@ class Plugins(ApiHandler):agent_profile="*",only_first=False,)- allowed_paths = {c.get("path", "") for c in configs}+ toggles = plugins.find_plugin_assets(+ plugins.TOGGLE_FILE_PATTERN,+ plugin_name=plugin_name,+ project_name="*",+ agent_profile="*",+ only_first=False,+ )+ allowed_paths = {c.get("path", "") for c in configs + toggles}if path not in allowed_paths:return Response(status=400, response="Invalid path")@@ -108,4 +115,20 @@ class Plugins(ApiHandler):plugins.save_plugin_config(plugin_name, project_name, agent_profile, settings)return {"ok": True}+ if action == "toggle_plugin":+ plugin_name = input.get("plugin_name", "")+ enabled = input.get("enabled")+ project_name = input.get("project_name", "")+ agent_profile = input.get("agent_profile", "")++ if not plugin_name:+ return Response(status=400, response="Missing plugin_name")+ if enabled is None:+ return Response(status=400, response="Missing enabled state")++ plugins.toggle_plugin(+ plugin_name, bool(enabled), project_name, agent_profile+ )+ return {"ok": True}+return Response(status=400, response=f"Unknown action: {action}")diff --git a/python/helpers/files.py b/python/helpers/files.pyindex 130c65dd2..de04b65ef 100644--- a/python/helpers/files.py+++ b/python/helpers/files.py@@ -425,7 +425,11 @@ def write_file(relative_path: str, content: str, encoding: str = "utf-8"):def delete_file(relative_path: str):abs_path = get_abs_path(relative_path)- os.remove(abs_path)+ if os.path.exists(abs_path):+ try:+ os.remove(abs_path)+ except OSError:+ passdef write_file_bin(relative_path: str, content: bytes):abs_path = get_abs_path(relative_path)diff --git a/python/helpers/plugins.py b/python/helpers/plugins.pyindex 36d5e8e9a..55086f0d1 100644--- a/python/helpers/plugins.py+++ b/python/helpers/plugins.py@@ -1,6 +1,6 @@from __future__ import annotations-import re, json+import re, json, globfrom pathlib import Pathfrom typing import Any, Dict, List, Literal, Optional, TYPE_CHECKING, TypedDict@@ -27,11 +27,11 @@ CONFIG_FILE_NAME = "config.json"CONFIG_DEFAULT_FILE_NAME = "config.default.json"DISABLED_FILE_NAME = ".toggle-0"ENABLED_FILE_NAME = ".toggle-1"-TOGGLE_FILE_PATTERN = "*.toggle-[01]"+TOGGLE_FILE_PATTERN = ".toggle-[01]"class PluginMetadata(BaseModel):- name: str = ""+ title: str = ""description: str = ""version: str = ""settings_sections: List[str] = Field(default_factory=list)@@ -49,6 +49,7 @@ class PluginListItem(BaseModel):settings_sections: List[str] = Field(default_factory=list)per_project_config: bool = Falseper_agent_config: bool = False+ always_enabled: bool = Falseis_custom: bool = Falsehas_main_screen: bool = Falsehas_config_screen: bool = False@@ -95,17 +96,18 @@ def get_enhanced_plugins_list()has_main_screen = files.exists(str(d / "webui" / "main.html"))has_config_screen = files.exists(str(d / "webui" / "config.html"))- toggle_state = get_toggle_state(meta.name)+ toggle_state = get_toggle_state(d.name)results.append(PluginListItem(name=d.name,path=str(d),- display_name=meta.name or d.name,+ display_name=meta.title or d.name,description=meta.description,version=meta.version,settings_sections=meta.settings_sections,per_project_config=meta.per_project_config,per_agent_config=meta.per_agent_config,+ always_enabled=meta.always_enabled,is_custom=is_custom,has_main_screen=has_main_screen,has_config_screen=has_config_screen,@@ -206,8 +208,10 @@ def get_enabled_plugins(agent: Agent | None):include_project=True,)- # go through agent paths in reverse order and determine the state- for agent_path in reversed(agent_paths):+ # go through agent paths in forward order and determine the state+ # subagents.get_paths returns [default, user, project] (priority low to high)+ # we want high priority to override low priority.+ for agent_path in agent_paths:if enabled:enabled = not files.exists(files.get_abs_path(agent_path, DISABLED_FILE_NAME)@@ -227,13 +231,15 @@ def get_toggle_state(plugin_name: str) -> ToggleState:meta = get_plugin_meta(plugin_name)if not meta:return "disabled"- if meta.always_enabled:- return "enabled"state = "enabled"# toggles inside of user directory (there should be only one, but let's make it work in any case)- usr_toggles = files.find_existing_paths_by_pattern(files.get_abs_path(files.USER_DIR, files.PLUGINS_DIR, plugin_name, TOGGLE_FILE_PATTERN))+ usr_toggles = files.find_existing_paths_by_pattern(+ files.get_abs_path(+ files.USER_DIR, files.PLUGINS_DIR, plugin_name, TOGGLE_FILE_PATTERN+ )+ )for toggle in usr_toggles:if toggle.endswith(ENABLED_FILE_NAME):state = "enabled"@@ -249,9 +255,19 @@ def get_toggle_state(plugin_name: str) -> ToggleState:agent_profile="*" if meta.per_agent_config else "",only_first=False,)- if len(configs) > len(usr_toggles):- state = "advanced"+ # Advanced if there are specific overrides (project or agent specific)+ specific_overrides = [+ c for c in configs+ if c.get("project_name") or c.get("agent_profile")+ ]++ if len(specific_overrides) > 0:+ state = "advanced"++ if state != "advanced" and meta.always_enabled:+ return "enabled"+return state@@ -261,11 +277,13 @@ def toggle_plugin(enabled_file = determine_plugin_asset_path(plugin_name, project_name, agent_profile, ENABLED_FILE_NAME)disabled_file = determine_plugin_asset_path(plugin_name, project_name, agent_profile, DISABLED_FILE_NAME)+ # ensure clean state by deleting both potential files first+ files.delete_file(enabled_file)+ files.delete_file(disabled_file)+if enabled:- files.delete_file(disabled_file)files.write_file(enabled_file, "")else:- files.delete_file(enabled_file)files.write_file(disabled_file, "")@@ -350,9 +368,10 @@ def find_plugin_assets(results: list[PluginAssetFile] = []def _collect(path: str, proj: str, profile: str) -> bool:+ is_glob = glob.has_magic(path)matched_paths = (files.find_existing_paths_by_pattern(path)- if "*" in path+ if is_globelse ([path] if files.exists(path) else []))diff --git a/webui/components/plugins/list/plugin-list.html b/webui/components/plugins/list/plugin-list.htmlindex d0da81797..9f286bed3 100644--- a/webui/components/plugins/list/plugin-list.html+++ b/webui/components/plugins/list/plugin-list.html@@ -95,6 +95,20 @@</template></div></div>++ <div class="plugin-controls-row">+ <select class="plugin-status-select"+ @change="$store.pluginListStore.updateToggle(plugin, $event.target.value)"+ @click.stop+ :disabled="plugin.always_enabled">+ <option value="enabled" :selected="plugin.toggle_state === 'enabled'">ON</option>+ <option value="disabled" :selected="plugin.toggle_state === 'disabled'">OFF</option>+ <template x-if="plugin.per_project_config || plugin.per_agent_config">+ <option value="advanced" :selected="plugin.toggle_state === 'advanced'">Advanced</option>+ </template>+ </select>+ </div>+<div class="plugin-description" x-text="plugin.description || 'No description provided.'"></div></div></template>@@ -201,6 +215,30 @@font-size: 1.1rem;}+ .plugin-controls-row {+ margin-top: 0.5rem;+ display: flex;+ align-items: center;+ justify-content: flex-end;+ }++ .plugin-status-select {+ padding: 0.3rem 2rem 0.3rem 0.6rem;+ font-size: 0.9rem;+ border: 1px solid var(--color-border);+ border-radius: 4px;+ background: var(--color-bg-primary);+ color: var(--color-text-primary);+ cursor: pointer;+ height: 2.2rem;+ }++ .plugin-status-select:disabled {+ opacity: 0.7;+ cursor: default;+ background: var(--color-bg-secondary);+ }+.plugin-description {margin-top: 0.35rem;color: var(--color-text-secondary);diff --git a/webui/components/plugins/list/pluginListStore.js b/webui/components/plugins/list/pluginListStore.jsindex 62558a20e..c2d244211 100644--- a/webui/components/plugins/list/pluginListStore.js+++ b/webui/components/plugins/list/pluginListStore.js@@ -1,6 +1,7 @@import { createStore } from "/js/AlpineStore.js";import * as api from "/js/api.js";import "/components/plugins/plugin-settings-store.js";+import "/components/plugins/toggle/plugin-toggle-store.js";import {store as notificationStore,defaultPriority,@@ -56,10 +57,18 @@ const model = {async openPluginConfig(plugin) {if (!plugin?.name || !plugin?.has_config_screen) return;try {+ // Initialize toggle store for activation state UI in settings modal+ const pluginToggleStore = Alpine.store("pluginToggle");+ if (pluginToggleStore?.open) await pluginToggleStore.open(plugin);+const pluginSettingsStore = Alpine.store("pluginSettings");if (!pluginSettingsStore?.open) {throw new Error("Plugin settings store is unavailable.");}+ // Set saveMode before open() so loadSettings picks up the right mode+ if (plugin.settings_sections?.includes('core')) {+ pluginSettingsStore.saveMode = 'core';+ }await pluginSettingsStore.open(plugin.name);window.openModal?.("components/plugins/plugin-settings.html");} catch (e) {@@ -67,6 +76,47 @@ const model = {}},+ async openPluginAdvancedToggle(plugin) {+ if (!plugin?.name) return;+ this.selectedPlugin = plugin;+ try {+ const pluginToggleStore = Alpine.store("pluginToggle");+ if (!pluginToggleStore?.open) {+ throw new Error("Plugin toggle store is unavailable.");+ }+ await pluginToggleStore.open(plugin);+ window.openModal?.("components/plugins/toggle/plugin-toggle-advanced.html");+ } catch (e) {+ showErrorNotification(e, "Failed to open plugin switch");+ }+ },++ async updateToggle(plugin, value) {+ if (!plugin?.name) return;++ if (value === 'advanced') {+ await this.openPluginAdvancedToggle(plugin);+ return;+ }++ const enabled = value === 'enabled';+ this.loading = true; // Show loading state+ try {+ const response = await api.callJsonApi("plugins", {+ action: "toggle_plugin",+ plugin_name: plugin.name,+ enabled: enabled,+ project_name: "", // Global+ agent_profile: "" // Global+ });+ if (response?.error) throw new Error(response.error);+ await this.refresh();+ } catch (e) {+ showErrorNotification(e, "Failed to toggle plugin");+ this.loading = false;+ }+ },+openPluginInfo(plugin) {if (!plugin) return;this.selectedPlugin = plugin;diff --git a/webui/components/plugins/plugin-settings-store.js b/webui/components/plugins/plugin-settings-store.jsindex 6aa1e1c1b..2ded1396c 100644--- a/webui/components/plugins/plugin-settings-store.js+++ b/webui/components/plugins/plugin-settings-store.js@@ -52,6 +52,14 @@ const model = {}await this.loadSettings();++ // Mirror scope change to pluginToggle so activation state stays in sync+ const toggleStore = Alpine.store('pluginToggle');+ if (toggleStore) {+ toggleStore.projectName = nextProject;+ toggleStore.agentProfileKey = nextProfile;+ toggleStore.calculateStatus();+ }},// where the settings were actually loaded from@@ -166,17 +174,19 @@ const model = {error: null,// Called by the subsection button before openModal()- async open(pluginName) {+ // Optional scope: { projectName, agentProfileKey } — skips redundant global loadSettings()+ // when the caller already knows which scope to open at.+ async open(pluginName, { projectName = "", agentProfileKey = "" } = {}) {this.pluginName = pluginName;this.pluginMeta = null;this.settings = {};this.settingsSnapshotJson = "";this.error = null;this.saveMode = 'plugin';- this.projectName = "";- this.agentProfileKey = "";- this.previousProjectName = "";- this.previousAgentProfileKey = "";+ this.projectName = projectName;+ this.agentProfileKey = agentProfileKey;+ this.previousProjectName = projectName;+ this.previousAgentProfileKey = agentProfileKey;this.loadedPath = "";this.loadedProjectName = "";this.loadedAgentProfile = "";diff --git a/webui/components/plugins/plugin-settings.html b/webui/components/plugins/plugin-settings.htmlindex 51cf32106..a6af8e7f9 100644--- a/webui/components/plugins/plugin-settings.html+++ b/webui/components/plugins/plugin-settings.html@@ -23,6 +23,7 @@<label class="plugin-settings-toolbar-item"><span class="plugin-settings-toolbar-label">Project</span><select x-model="$store.pluginSettings.projectName"+ x-init="$nextTick(() => $el.value = $store.pluginSettings.projectName)"@change="$store.pluginSettings.onScopeChanged()"><option value="">Global</option><template x-for="project in $store.pluginSettings.projects" :key="project.key">@@ -34,6 +35,7 @@<label class="plugin-settings-toolbar-item"><span class="plugin-settings-toolbar-label">Agent profile</span><select x-model="$store.pluginSettings.agentProfileKey"+ x-init="$nextTick(() => $el.value = $store.pluginSettings.agentProfileKey)"@change="$store.pluginSettings.onScopeChanged()"><option value="">All profiles</option><template x-for="profile in $store.pluginSettings.agentProfiles" :key="profile.key">@@ -47,6 +49,27 @@</button></div>++ <!-- Activation row: ON/OFF toggle + link to Advanced per-scope modal -->+ <div class="plugin-settings-toolbar plugin-activation-toolbar" x-show="$store.pluginToggle">+ <div class="plugin-settings-toolbar-row">+ <div class="plugin-activation-toggle-group">+ <label class="toggle">+ <input type="checkbox"+ :checked="$store.pluginToggle?.status === 'enabled'"+ :disabled="$store.pluginToggle?.alwaysEnabled || $store.pluginToggle?.isSaving"+ @change="$store.pluginToggle.setEnabled($event.target.checked)">+ <span class="toggler"></span>+ </label>+ <span class="plugin-toggle-status-text" x-text="$store.pluginToggle?.statusLabel"></span>+ </div>+ <button type="button" class="button plugin-settings-toolbar-button"+ @click="window.openModal?.('components/plugins/toggle/plugin-toggle-advanced.html')">+ <span class="icon material-symbols-outlined">toggle_on</span>+ Switch+ </button>+ </div>+ </div></div><div x-show="$store.pluginSettings.scopeMismatchMessage" class="plugin-settings-scope-info">@@ -203,6 +226,23 @@color: var(--color-text-secondary);margin-top: 0.25rem;}++ .plugin-activation-toolbar {+ padding-top: 0.75rem;+ padding-bottom: 0.75rem;+ }++ .plugin-activation-toggle-group {+ display: flex;+ align-items: center;+ gap: 0.75rem;+ }++ .plugin-toggle-status-text {+ font-weight: 600;+ color: var(--color-text-primary);+ min-width: 2rem;+ }</style></body></html>diff --git a/webui/components/plugins/toggle/plugin-toggle-advanced.html b/webui/components/plugins/toggle/plugin-toggle-advanced.htmlindex 51cf32106..6a7b839b8 100644--- a/webui/components/plugins/toggle/plugin-toggle-advanced.html+++ b/webui/components/plugins/toggle/plugin-toggle-advanced.html@@ -1,97 +1,137 @@<html><head>- <title>Plugin Settings</title>+ <title>Plugin Switch</title><script type="module">- import { store } from "/components/plugins/plugin-settings-store.js";+ import { store } from "/components/plugins/toggle/plugin-toggle-store.js";</script></head><body><div x-data>- <template x-if="$store.pluginSettings">- <div x-create="$store.pluginSettings.onModalOpen()"- x-destroy="$store.pluginSettings.cleanup()">-- <!-- Context toolbar: Project + Agent profile (mirrors skills list) -->- <div class="plugin-settings-scope-section">- <div class="plugin-settings-scope-header">- <div class="plugin-settings-scope-title">Settings scope</div>- <div class="plugin-settings-scope-desc">This plugin supports settings per project or agent profile.</div>- </div>- <div class="plugin-settings-toolbar">- <div class="plugin-settings-toolbar-row">-- <label class="plugin-settings-toolbar-item">- <span class="plugin-settings-toolbar-label">Project</span>- <select x-model="$store.pluginSettings.projectName"- @change="$store.pluginSettings.onScopeChanged()">- <option value="">Global</option>- <template x-for="project in $store.pluginSettings.projects" :key="project.key">- <option :value="project.key" x-text="project.label"></option>- </template>- </select>- </label>-- <label class="plugin-settings-toolbar-item">- <span class="plugin-settings-toolbar-label">Agent profile</span>- <select x-model="$store.pluginSettings.agentProfileKey"- @change="$store.pluginSettings.onScopeChanged()">- <option value="">All profiles</option>- <template x-for="profile in $store.pluginSettings.agentProfiles" :key="profile.key">- <option :value="profile.key" x-text="profile.label"></option>- </template>- </select>- </label>-- <button type="button" class="button plugin-settings-toolbar-button" title="Show existing configurations" @click="$store.pluginSettings.openConfigListModal()">- <span class="icon material-symbols-outlined">list</span>- </button>-- </div>- </div>-- <div x-show="$store.pluginSettings.scopeMismatchMessage" class="plugin-settings-scope-info">- <span class="material-symbols-outlined">info</span>- <span x-text="$store.pluginSettings.scopeMismatchMessage"></span>- </div>- </div>+ <template x-if="$store.pluginToggle">+ <div x-create="$store.pluginToggle.open($store.pluginListStore?.selectedPlugin || '')"+ x-destroy="$store.pluginToggle.cleanup()"><!-- Error -->- <div x-show="$store.pluginSettings.error" class="plugin-settings-error">+ <div x-show="$store.pluginToggle.error" class="plugin-settings-error"><span class="material-symbols-outlined">error</span>- <span x-text="$store.pluginSettings.error"></span>+ <span x-text="$store.pluginToggle.error"></span></div><!-- Loading -->- <div x-show="$store.pluginSettings.isLoading" class="plugin-settings-loading">+ <div x-show="$store.pluginToggle.isLoading" class="plugin-settings-loading"><span class="material-symbols-outlined spinning">progress_activity</span>- <span>Loading settings...</span>+ <span>Loading status...</span></div>- <!-- Plugin settings body: plugin provides /plugins/<name>/webui/config.html -->- <div x-show="!$store.pluginSettings.isLoading"- class="plugin-settings-body"- x-html="$store.pluginSettings.settingsComponentHtml">+ <!-- Main UI -->+ <div x-show="!$store.pluginToggle.isLoading">++ <!-- Scope selector + per-scope ON/OFF -->+ <div class="plugin-settings-scope-section">+ <div class="plugin-settings-scope-header">+ <div class="plugin-settings-scope-title">Scope</div>+ <div class="plugin-settings-scope-desc">Select which project or agent profile to configure.</div>+ </div>+ <div class="plugin-settings-toolbar">+ <div class="plugin-settings-toolbar-row">++ <label class="plugin-settings-toolbar-item">+ <span class="plugin-settings-toolbar-label">Project</span>+ <select x-model="$store.pluginToggle.projectName"+ @change="$store.pluginToggle.onScopeChanged()">+ <option value="">Global</option>+ <template x-for="p in $store.pluginToggle.projects" :key="p.key">+ <option :value="p.key" x-text="p.label"></option>+ </template>+ </select>+ </label>++ <label class="plugin-settings-toolbar-item">+ <span class="plugin-settings-toolbar-label">Agent profile</span>+ <select x-model="$store.pluginToggle.agentProfileKey"+ @change="$store.pluginToggle.onScopeChanged()">+ <option value="">All profiles</option>+ <template x-for="a in $store.pluginToggle.agentProfiles" :key="a.key">+ <option :value="a.key" x-text="a.label"></option>+ </template>+ </select>+ </label>++ <div class="plugin-settings-toolbar-item plugin-status-toggle-item">+ <label class="toggle">+ <input type="checkbox"+ :checked="$store.pluginToggle.status === 'enabled'"+ :disabled="$store.pluginToggle.alwaysEnabled || $store.pluginToggle.isSaving"+ @change="$store.pluginToggle.setEnabled($event.target.checked)">+ <span class="toggler"></span>+ </label>+ <span class="plugin-toggle-status-text" x-text="$store.pluginToggle.statusLabel"></span>+ </div>++ <button type="button" class="button plugin-settings-toolbar-button" title="View all scope configs" @click="$store.pluginToggle.openConfigListModal()">+ <span class="icon material-symbols-outlined">list</span>+ </button>++ </div>+ </div>++ <div x-show="$store.pluginToggle.noScopeRuleMessage" class="plugin-settings-scope-info">+ <span class="material-symbols-outlined">info</span>+ <span x-text="$store.pluginToggle.noScopeRuleMessage"></span>+ </div>+ </div>+</div></div></template></div>- <!-- Footer (pinned outside scroll area) -->+ <!-- Footer --><div class="modal-footer" data-modal-footer>- <button class="btn btn-ok"- @click="$store.pluginSettings.save()"- :disabled="$store.pluginSettings?.isSaving || $store.pluginSettings?.isLoading">- Save+ <button type="button" class="btn btn-ok footer-btn-left" @click="$store.pluginToggle.openConfigWithScope()">+ <span class="icon material-symbols-outlined">settings</span>+ Configure Plugin</button>- <button class="btn btn-cancel"- @click="window.closeModal?.()">- Cancel+ <button class="btn btn-cancel" @click="window.closeModal?.()">+ Close</button></div><style>- .plugin-settings-toolbar, .plugin-settings-body {+ .footer-btn-left {+ margin-left: var(--spacing-lg);+ margin-right: auto;+ }++ /* Shared scope layout — mirrors plugin-settings.html */+ .plugin-settings-scope-section {+ border: 1px solid var(--color-border);+ border-radius: 4px;+ margin: 1rem;+ padding: 0;+ overflow: hidden;+ }++ .plugin-settings-scope-header {+ padding: 0.75rem 1rem;+ border-bottom: 1px solid var(--color-border);+ background: var(--color-bg-secondary);+ }++ .plugin-settings-scope-title {+ font-weight: 600;+ font-size: var(--font-size-normal);+ color: var(--color-text-primary);+ }++ .plugin-settings-scope-desc {+ font-size: var(--font-size-small);+ color: var(--color-text-secondary);+ margin-top: 0.25rem;+ }++ .plugin-settings-toolbar {padding: 1rem;}@@ -111,10 +151,9 @@margin: 0;}- .plugin-settings-toolbar-button {- flex: 0 0 auto;- padding: 0.5rem 0.75rem;- height: 2.5rem;+ .plugin-settings-toolbar-item select {+ flex: 1 1 auto;+ min-width: 0;}.plugin-settings-toolbar-label {@@ -123,9 +162,10 @@white-space: nowrap;}- .plugin-settings-toolbar-item select {- flex: 1 1 auto;- min-width: 0;+ .plugin-settings-toolbar-button {+ flex: 0 0 auto;+ padding: 0.5rem 0.75rem;+ height: 2.5rem;}.plugin-settings-scope-info {@@ -137,6 +177,11 @@font-size: var(--font-size-small);}+ .plugin-settings-body {+ padding: 1rem;+ min-height: 4rem;+ }+@media (max-width: 640px) {.plugin-settings-toolbar-item {flex-basis: 100%;@@ -144,6 +189,15 @@}}+ .plugin-settings-loading {+ display: flex;+ align-items: center;+ justify-content: center;+ gap: 0.5rem;+ padding: 2rem;+ color: var(--color-text-secondary);+ }+.plugin-settings-error {display: flex;align-items: center;@@ -156,19 +210,6 @@font-size: var(--font-size-small);}- .plugin-settings-loading {- display: flex;- align-items: center;- justify-content: center;- gap: 0.5rem;- padding: 2rem;- color: var(--color-text-secondary);- }-- .plugin-settings-body {- min-height: 4rem;- }-.spinning {animation: spin 1s linear infinite;}@@ -178,30 +219,17 @@to { transform: rotate(360deg); }}- .plugin-settings-scope-section {- border: 1px solid var(--color-border);- border-radius: 4px;- margin: 1rem;- padding: 0;- overflow: hidden;- }-- .plugin-settings-scope-header {- padding: 0.75rem 1rem;- border-bottom: 1px solid var(--color-border);- background: var(--color-bg-secondary);+ .plugin-status-toggle-item {+ display: flex;+ align-items: center;+ gap: 0.75rem;+ flex: 0 0 auto;}- .plugin-settings-scope-title {+ .plugin-toggle-status-text {font-weight: 600;- font-size: var(--font-size-normal);color: var(--color-text-primary);- }-- .plugin-settings-scope-desc {- font-size: var(--font-size-small);- color: var(--color-text-secondary);- margin-top: 0.25rem;+ min-width: 2rem;}</style></body>diff --git a/webui/components/plugins/toggle/plugin-toggle-store.js b/webui/components/plugins/toggle/plugin-toggle-store.jsindex 6aa1e1c1b..a656bf262 100644--- a/webui/components/plugins/toggle/plugin-toggle-store.js+++ b/webui/components/plugins/toggle/plugin-toggle-store.js@@ -1,100 +1,88 @@import { createStore } from "/js/AlpineStore.js";+import { store as settingsStore } from "/components/plugins/plugin-settings-store.js";const fetchApi = globalThis.fetchApi;const model = {- // which plugin this modal is showingpluginName: null,- pluginMeta: null,-- // context selectors (mirrors skills list pattern)++ // Context selectorsprojects: [],agentProfiles: [],projectName: "",agentProfileKey: "",- // plugin settings data (plugins bind their fields here)- settings: {},+ // State+ isLoading: false,+ isSaving: false,+ error: null,++ // Status: 'enabled' | 'disabled'+ status: 'enabled',+ alwaysEnabled: false,+ explicitPath: null,+ configs: [],++ async open(plugin) {+ this.isLoading = true;+ this.error = null;+ this.projects = [];+ this.agentProfiles = [];+ this.projectName = "";+ this.agentProfileKey = "";+ this.configs = [];- settingsSnapshotJson: "",- previousProjectName: "",- previousAgentProfileKey: "",+ const pluginName = typeof plugin === 'string' ? plugin : plugin?.name;+ this.pluginName = pluginName;+ this.alwaysEnabled = typeof plugin === 'object' ? !!plugin.always_enabled : false;- _toComparableJson(value) {try {- return JSON.stringify(value ?? {});- } catch {- return "";+ await Promise.all([this.loadProjects(), this.loadAgentProfiles()]);+ await this.loadConfigs();+ } finally {+ this.isLoading = false;}},- get hasUnsavedChanges() {- return this._toComparableJson(this.settings) !== (this.settingsSnapshotJson || "");- },-- confirmDiscardUnsavedChanges() {- if (!this.hasUnsavedChanges) return true;- return window.confirm("You have unsaved changes that will be lost. Continue?");+ cleanup() {+ this.pluginName = null;+ this.projectName = "";+ this.agentProfileKey = "";+ this.error = null;+ this.configs = [];},- async onScopeChanged() {- const nextProject = this.projectName || "";- const nextProfile = this.agentProfileKey || "";- const prevProject = this.previousProjectName || "";- const prevProfile = this.previousAgentProfileKey || "";-- if (nextProject === prevProject && nextProfile === prevProfile) return;-- if (!this.confirmDiscardUnsavedChanges()) {- this.projectName = prevProject;- this.agentProfileKey = prevProfile;- return;+ async loadProjects() {+ try {+ const response = await fetchApi("/projects", {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({ action: "list_options" }),+ });+ const data = await response.json().catch(() => ({}));+ this.projects = data.ok ? (data.data || []) : [];+ } catch {+ this.projects = [];}-- await this.loadSettings();- },-- // where the settings were actually loaded from- loadedPath: "",- loadedProjectName: "",- loadedAgentProfile: "",-- projectLabel(key) {- if (!key) return "Global";- const found = (this.projects || []).find((p) => p.key === key);- return found?.label || key;- },-- agentProfileLabel(key) {- if (!key) return "All profiles";- const found = (this.agentProfiles || []).find((p) => p.key === key);- return found?.label || key;},- get scopeMismatchMessage() {- const selectedProject = this.projectName || "";- const selectedProfile = this.agentProfileKey || "";- const loadedProject = this.loadedProjectName || "";- const loadedProfile = this.loadedAgentProfile || "";-- if (!this.loadedPath) return "";- if (selectedProject === loadedProject && selectedProfile === loadedProfile) return "";-- return `Settings do not yet exist for this combination, settings from ${this.projectLabel(loadedProject)}, ${this.agentProfileLabel(loadedProfile)} (${this.loadedPath}) will apply.`;- },-- configs: [],- isListingConfigs: false,- configsError: null,-- async openConfigListModal() {- await window.openModal?.("/components/plugins/plugin-configs.html");+ async loadAgentProfiles() {+ try {+ const response = await fetchApi("/agents", {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({ action: "list" }),+ });+ const data = await response.json().catch(() => ({}));+ this.agentProfiles = data.ok ? (data.data || []) : [];+ } catch {+ this.agentProfiles = [];+ }},- async loadConfigList() {+ async loadConfigs() {if (!this.pluginName) return;- this.isListingConfigs = true;- this.configsError = null;+ this.isLoading = true;try {const response = await fetchApi("/plugins", {method: "POST",@@ -102,217 +90,156 @@ const model = {body: JSON.stringify({action: "list_configs",plugin_name: this.pluginName,+ asset_type: "toggle"}),});const result = await response.json().catch(() => ({}));this.configs = result.ok ? (result.data || []) : [];- if (!result.ok) this.configsError = result.error || "Failed to load configurations";+ this.calculateStatus();} catch (e) {- this.configsError = e?.message || "Failed to load configurations";- this.configs = [];+ this.error = e?.message || "Failed to load configurations";} finally {- this.isListingConfigs = false;+ this.isLoading = false;}},- async switchToConfig(projectName, agentProfile) {- if (!this.confirmDiscardUnsavedChanges()) return;- this.projectName = projectName || "";- this.agentProfileKey = agentProfile || "";- await this.loadSettings();- await window.closeModal?.();- },-- async deleteConfig(projectName, agentProfile) {+ async openConfigWithScope() {if (!this.pluginName) return;- try {- const cfg = (this.configs || []).find(- (c) => (c?.project_name || "") === (projectName || "") && (c?.agent_profile || "") === (agentProfile || "")- );- const path = cfg?.path || "";- if (!path) {- this.configsError = "Configuration path not found";- return;- }- const response = await fetchApi("/plugins", {- method: "POST",- headers: { "Content-Type": "application/json" },- body: JSON.stringify({- action: "delete_config",- plugin_name: this.pluginName,- path,- }),+ if (settingsStore.pluginName !== this.pluginName) {+ // Different plugin — full init with current scope+ await settingsStore.open(this.pluginName, {+ projectName: this.projectName || "",+ agentProfileKey: this.agentProfileKey || "",});- const result = await response.json().catch(() => ({}));- if (!result.ok) {- this.configsError = result.error || "Delete failed";- return;- }-- this.configsError = null;- await this.loadConfigList();- } catch (e) {- this.configsError = e?.message || "Delete failed";+ } else {+ // Same plugin — push current scope explicitly.+ // onScopeChanged() syncs on @change events, but if the user never touched+ // the scope selectors after the modal opened the settings store may still+ // hold a stale scope from a prior session.+ settingsStore.projectName = this.projectName || "";+ settingsStore.agentProfileKey = this.agentProfileKey || "";}+ await window.openModal?.("components/plugins/plugin-settings.html");},- // 'plugin' = save to plugin settings API- // 'core' = save via $store.settings.saveSettings() (for plugins that surface core settings)- saveMode: 'plugin',-- isLoading: false,- isSaving: false,- error: null,-- // Called by the subsection button before openModal()- async open(pluginName) {- this.pluginName = pluginName;- this.pluginMeta = null;- this.settings = {};- this.settingsSnapshotJson = "";- this.error = null;- this.saveMode = 'plugin';- this.projectName = "";- this.agentProfileKey = "";- this.previousProjectName = "";- this.previousAgentProfileKey = "";- this.loadedPath = "";- this.loadedProjectName = "";- this.loadedAgentProfile = "";- await Promise.all([this.loadProjects(), this.loadAgentProfiles()]);- await this.loadSettings();- },-- // Called by x-create inside the modal on every open- async onModalOpen() {- if (this.pluginName) await this.loadSettings();+ async openConfigListModal() {+ await window.openModal?.("/components/plugins/toggle/plugin-toggles.html");},- async loadAgentProfiles() {- try {- const response = await fetchApi("/agents", {- method: "POST",- headers: { "Content-Type": "application/json" },- body: JSON.stringify({ action: "list" }),- });- const data = await response.json().catch(() => ({}));- this.agentProfiles = data.ok ? (data.data || []) : [];- } catch {- this.agentProfiles = [];- }+ async loadConfigList() {+ await this.loadConfigs();},- async loadProjects() {- try {- const response = await fetchApi("/projects", {- method: "POST",- headers: { "Content-Type": "application/json" },- body: JSON.stringify({ action: "list_options" }),- });- const data = await response.json().catch(() => ({}));- this.projects = data.ok ? (data.data || []) : [];- } catch {- this.projects = [];- }+ async switchToConfig(projectName, agentProfile) {+ this.projectName = projectName || "";+ this.agentProfileKey = agentProfile || "";+ this.onScopeChanged();+ await window.closeModal?.();},- async loadSettings() {- if (!this.pluginName) return;+ async deleteConfig(path) {+ if (!this.pluginName || !path) return;this.isLoading = true;- this.error = null;try {const response = await fetchApi("/plugins", {method: "POST",headers: { "Content-Type": "application/json" },body: JSON.stringify({- action: "get_config",+ action: "delete_config",plugin_name: this.pluginName,- project_name: this.projectName || "",- agent_profile: this.agentProfileKey || "",+ path: path}),});- const result = await response.json().catch(() => ({}));- this.settings = result.ok ? (result.data || {}) : {};- this.loadedPath = result.loaded_path || "";- this.loadedProjectName = result.loaded_project_name || "";- this.loadedAgentProfile = result.loaded_agent_profile || "";- if (!result.ok) this.error = result.error || "Failed to load settings";+ const result = await response.json();+ if (!result.ok) throw new Error(result.error);+ await this.loadConfigs();} catch (e) {- this.error = e?.message || "Failed to load settings";- this.settings = {};+ this.error = e.message || "Delete failed";} finally {- this.settingsSnapshotJson = this._toComparableJson(this.settings);- this.previousProjectName = this.projectName || "";- this.previousAgentProfileKey = this.agentProfileKey || "";this.isLoading = false;}},- async save() {- if (!this.pluginName) return;-- // Core-backed plugins (e.g. memory) delegate to the settings store- if (this.saveMode === 'core') {- const coreStore = Alpine.store('settings');- if (coreStore?.saveSettings) {- const ok = await coreStore.saveSettings();- if (ok) window.closeModal?.();- }+ calculateStatus() {+ if (this.alwaysEnabled) {+ this.explicitPath = null;+ this.status = 'enabled';return;}- // Plugin-specific settings: persist to plugin settings API+ const p = this.projectName || "";+ const a = this.agentProfileKey || "";+ const explicit = this.configs.find(+ c => (c.project_name||"") === p && (c.agent_profile||"") === a+ );++ if (explicit) {+ this.explicitPath = explicit.path;+ this.status = explicit.path.endsWith(".toggle-1") ? 'enabled' : 'disabled';+ } else {+ this.explicitPath = null;+ this.status = 'enabled'; // default when no explicit config+ }+ },++ async setEnabled(enabled) {+ if (!this.pluginName || this.alwaysEnabled) return;this.isSaving = true;- this.error = null;try {const response = await fetchApi("/plugins", {method: "POST",headers: { "Content-Type": "application/json" },body: JSON.stringify({- action: "save_config",+ action: "toggle_plugin",plugin_name: this.pluginName,project_name: this.projectName || "",agent_profile: this.agentProfileKey || "",- settings: this.settings,+ enabled: enabled}),});- const result = await response.json().catch(() => ({}));- if (!result.ok) this.error = result.error || "Save failed";- else {- this.settingsSnapshotJson = this._toComparableJson(this.settings);- window.closeModal?.();- }+ const result = await response.json();+ if (!result.ok) throw new Error(result.error);+ await new Promise(r => setTimeout(r, 100));+ await this.loadConfigs();} catch (e) {- this.error = e?.message || "Save failed";+ this.error = e.message || "Failed to save";} finally {this.isSaving = false;}},- cleanup() {- this.pluginName = null;- this.pluginMeta = null;- this.settings = {};- this.settingsSnapshotJson = "";- this.previousProjectName = "";- this.previousAgentProfileKey = "";- this.loadedPath = "";- this.loadedProjectName = "";- this.loadedAgentProfile = "";- this.error = null;- this.isLoading = false;- this.isSaving = false;- this.isListingConfigs = false;- this.configsError = null;- this.configs = [];+ async onScopeChanged() {+ this.calculateStatus();++ // Sync scope with settings store so its loadSettings picks up the right context+ settingsStore.projectName = this.projectName || "";+ settingsStore.agentProfileKey = this.agentProfileKey || "";+ await settingsStore.loadSettings();+ },++ projectLabel(key) {+ if (!key) return "Global";+ const found = (this.projects || []).find(p => p.key === key);+ return found?.label || key;+ },++ agentProfileLabel(key) {+ if (!key) return "All profiles";+ const found = (this.agentProfiles || []).find(p => p.key === key);+ return found?.label || key;},- // Reactive URL for the plugin's settings component (used with x-html injection)- get settingsComponentHtml() {- if (!this.pluginName) return "";- return `<x-component path="/plugins/${this.pluginName}/webui/config.html"></x-component>`;+ get statusLabel() {+ return this.status === 'enabled' ? 'ON' : 'OFF';},++ get noScopeRuleMessage() {+ if (this.alwaysEnabled || this.isLoading) return "";+ if (this.configs.length === 0) return "No activation rules configured. Plugin defaults to ON.";+ if (!this.explicitPath) return "No rule set for this scope. Status defaults to ON.";+ return "";+ }};-export const store = createStore("pluginSettings", model);+export const store = createStore("pluginToggle", model);diff --git a/webui/components/plugins/toggle/plugin-toggles.html b/webui/components/plugins/toggle/plugin-toggles.htmlindex 4daac6641..e6c14a5e9 100644--- a/webui/components/plugins/toggle/plugin-toggles.html+++ b/webui/components/plugins/toggle/plugin-toggles.html@@ -1,52 +1,56 @@<html><head>- <title>Existing plugin configurations</title>+ <title>Plugin Switch Configuration</title><script type="module">- import { store } from "/components/plugins/plugin-settings-store.js";+ import { store } from "/components/plugins/toggle/plugin-toggle-store.js";</script></head><body><div x-data>- <template x-if="$store.pluginSettings">- <div x-create="$store.pluginSettings.loadConfigList()" class="plugin-configs-container">+ <template x-if="$store.pluginToggle">+ <div x-create="$store.pluginToggle.loadConfigs()" class="plugin-configs-container">- <div x-show="$store.pluginSettings.configsError" class="plugin-configs-error">+ <div x-show="$store.pluginToggle.error" class="plugin-configs-error"><span class="material-symbols-outlined">error</span>- <span x-text="$store.pluginSettings.configsError"></span>+ <span x-text="$store.pluginToggle.error"></span></div>- <div x-show="$store.pluginSettings.isListingConfigs" class="plugin-configs-loading">+ <div x-show="$store.pluginToggle.isLoading" class="plugin-configs-loading"><span class="material-symbols-outlined spinning">progress_activity</span><span>Loading configurations...</span></div>- <div x-show="!$store.pluginSettings.isListingConfigs" class="plugin-configs-list">- <template x-if="($store.pluginSettings.configs || []).length === 0">- <div class="plugin-configs-empty">No configurations found.</div>+ <div x-show="!$store.pluginToggle.isLoading" class="plugin-configs-list">+ <template x-if="($store.pluginToggle.configs || []).length === 0">+ <div class="plugin-configs-empty">No status configurations found.</div></template>- <template x-for="cfg in ($store.pluginSettings.configs || [])" :key="(cfg.project_name || '') + '|' + (cfg.agent_profile || '')">+ <template x-for="cfg in ($store.pluginToggle.configs || [])" :key="(cfg.project_name || '') + '|' + (cfg.agent_profile || '')"><div class="plugin-configs-row"><div class="plugin-configs-scope"><div class="plugin-configs-scope-top"><div class="plugin-configs-scope-line"><span class="plugin-configs-scope-key">Project:</span>- <span x-text="$store.pluginSettings.projectLabel(cfg.project_name || '')"></span>+ <span x-text="$store.pluginToggle.projectLabel(cfg.project_name || '')"></span></div><div class="plugin-configs-scope-line"><span class="plugin-configs-scope-key">Agent profile:</span>- <span x-text="$store.pluginSettings.agentProfileLabel(cfg.agent_profile || '')"></span>+ <span x-text="$store.pluginToggle.agentProfileLabel(cfg.agent_profile || '')"></span></div></div>- <div class="plugin-configs-scope-sub" x-text="cfg.path || ''"></div>+ <div class="plugin-configs-scope-sub">+ <span x-text="cfg.path.endsWith('.toggle-1') ? 'ON' : 'OFF'"+ :class="cfg.path.endsWith('.toggle-1') ? 'text-success' : 'text-error'"></span>+ <span class="path-detail" x-text="cfg.path"></span>+ </div></div><div class="plugin-configs-actions">- <button type="button" class="button" @click="$store.pluginSettings.switchToConfig(cfg.project_name || '', cfg.agent_profile || '')">- <span class="icon material-symbols-outlined">list</span>- Show+ <button type="button" class="button" @click="$store.pluginToggle.switchToConfig(cfg.project_name || '', cfg.agent_profile || '')">+ <span class="icon material-symbols-outlined">edit</span>+ Edit</button>- <button type="button" class="button cancel icon-button" title="Delete" @click="$confirmClick($event, () => $store.pluginSettings.deleteConfig(cfg.project_name || '', cfg.agent_profile || ''))">+ <button type="button" class="button cancel icon-button" title="Delete" @click="$confirmClick($event, () => $store.pluginToggle.deleteConfig(cfg.path))"><span class="icon material-symbols-outlined">delete</span></button></div>@@ -125,10 +129,18 @@font-size: var(--font-size-small);color: var(--color-text-secondary);margin-top: 0.2rem;- white-space: normal;- overflow-wrap: break-word;- word-break: normal;+ display: flex;+ gap: 0.5rem;+ align-items: center;+ }++ .path-detail {+ opacity: 0.5;+ font-size: 0.8em;}++ .text-success { color: var(--color-success, #2ecc71); font-weight: 600; }+ .text-error { color: var(--color-error, #e74c3c); font-weight: 600; }.plugin-configs-actions {display: flex;