Agent Zero AI framework
Refactor plugin/project helpers; add plugin UI
frdel5acb733b9e6e
diff --git a/agent.py b/agent.pyindex 183cf6d5f..58a4531f5 100644--- a/agent.py+++ b/agent.py@@ -646,7 +646,7 @@ class Agent:return system_promptdef parse_prompt(self, _prompt_file: str, **kwargs):- dirs = subagents.get_paths(self, "prompts", include_plugins=True)+ dirs = subagents.get_paths(self, "prompts")prompt = files.parse_file(_prompt_file, _directories=dirs, _agent=self, **kwargs@@ -654,7 +654,7 @@ class Agent:return promptdef read_prompt(self, file: str, **kwargs) -> str:- dirs = subagents.get_paths(self, "prompts", include_plugins=True)+ dirs = subagents.get_paths(self, "prompts")prompt = files.read_prompt_file(file, _directories=dirs, _agent=self, **kwargs)if files.is_full_json_template(prompt):@@ -990,7 +990,7 @@ class Agent:classes = []# search for tools in agent's folder hierarchy- paths = subagents.get_paths(self, "tools", name + ".py", default_root="python", include_plugins=True)+ paths = subagents.get_paths(self, "tools", name + ".py", default_root="python")for path in paths:try:diff --git a/plugins/example_agent/plugin.json b/plugins/example_agent/plugin.jsonindex e69de29bb..ac6b7e8cb 100644--- a/plugins/example_agent/plugin.json+++ b/plugins/example_agent/plugin.json@@ -0,0 +1,5 @@+{+ "description": "Example Agent Plugin",+ "per_project_config": true,+ "per_agent_config": false+}diff --git a/plugins/example_agent/webui/config.html b/plugins/example_agent/webui/config.htmlnew file mode 100644index 000000000..6d34ae1dc--- /dev/null+++ b/plugins/example_agent/webui/config.html@@ -0,0 +1,14 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>Example Agent Configuration</title>+</head>+<body>+ <div class="container">+ <h1>Example Agent Plugin Configuration</h1>+ <p>This is a dummy configuration page for the example agent plugin.</p>+ </div>+</body>+</html>diff --git a/plugins/memory/api/knowledge_path_get.py b/plugins/memory/api/knowledge_path_get.pyindex b643a1d2e..64121449f 100644--- a/plugins/memory/api/knowledge_path_get.py+++ b/plugins/memory/api/knowledge_path_get.py@@ -12,7 +12,7 @@ class GetKnowledgePath(ApiHandler):project_name = projects.get_context_project_name(context)if project_name:- knowledge_folder = projects.get_project_meta_folder(project_name, "knowledge")+ knowledge_folder = projects.get_project_meta(project_name, "knowledge")else:knowledge_folder = get_custom_knowledge_subdir_abs(context.agent0)diff --git a/plugins/memory/helpers/memory.py b/plugins/memory/helpers/memory.pyindex bad55011b..c283b4b1a 100644--- a/plugins/memory/helpers/memory.py+++ b/plugins/memory/helpers/memory.py@@ -486,9 +486,9 @@ def reload():def abs_db_dir(memory_subdir: str) -> str:# patch for projects, this way we don't need to re-work the structure of memory subdirsif memory_subdir.startswith("projects/"):- from python.helpers.projects import get_project_meta_folder+ from python.helpers.projects import get_project_meta- return files.get_abs_path(get_project_meta_folder(memory_subdir[9:]), "memory")+ return files.get_abs_path(get_project_meta(memory_subdir[9:]), "memory")# standard subdirsreturn files.get_abs_path("usr/memory", memory_subdir)@@ -496,10 +496,10 @@ def abs_db_dir(memory_subdir: str) -> str:def abs_knowledge_dir(knowledge_subdir: str, *sub_dirs: str) -> str:# patch for projects, this way we don't need to re-work the structure of knowledge subdirsif knowledge_subdir.startswith("projects/"):- from python.helpers.projects import get_project_meta_folder+ from python.helpers.projects import get_project_metareturn files.get_abs_path(- get_project_meta_folder(knowledge_subdir[9:]), "knowledge", *sub_dirs+ get_project_meta(knowledge_subdir[9:]), "knowledge", *sub_dirs)# standard subdirsif knowledge_subdir == "default":@@ -536,7 +536,7 @@ def get_context_memory_subdir(context: AgentContext) -> str:def get_existing_memory_subdirs() -> list[str]:try:from python.helpers.projects import (- get_project_meta_folder,+ get_project_meta,get_projects_parent_folder,)@@ -546,7 +546,7 @@ def get_existing_memory_subdirs() -> list[str]:project_subdirs = files.get_subdirectories(get_projects_parent_folder())for project_subdir in project_subdirs:if files.exists(- get_project_meta_folder(project_subdir), "memory", "index.faiss"+ get_project_meta(project_subdir), "memory", "index.faiss"):subdirs.append(f"projects/{project_subdir}")@@ -564,7 +564,7 @@ def get_knowledge_subdirs_by_memory_subdir(memory_subdir: str, default: list[str]) -> list[str]:if memory_subdir.startswith("projects/"):- from python.helpers.projects import get_project_meta_folder+ from python.helpers.projects import get_project_meta- default.append(get_project_meta_folder(memory_subdir[9:], "knowledge"))+ default.append(get_project_meta(memory_subdir[9:], "knowledge"))return defaultdiff --git a/plugins/memory/plugin.json b/plugins/memory/plugin.jsonindex e69de29bb..80df3e357 100644--- a/plugins/memory/plugin.json+++ b/plugins/memory/plugin.json@@ -0,0 +1,5 @@+{+ "description": "Memory Plugin",+ "per_project_config": true,+ "per_agent_config": true+}\ No newline at end of filediff --git a/plugins/memory/webui/config.html b/plugins/memory/webui/config.htmlnew file mode 100644index 000000000..6503585d0--- /dev/null+++ b/plugins/memory/webui/config.html@@ -0,0 +1,14 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>Memory Configuration</title>+</head>+<body>+ <div class="container">+ <h1>Memory Plugin Configuration</h1>+ <p>This is a dummy configuration page for the memory plugin.</p>+ </div>+</body>+</html>diff --git a/plugins/memory/webui/main.html b/plugins/memory/webui/main.htmlnew file mode 100644index 000000000..58ec2cc1e--- /dev/null+++ b/plugins/memory/webui/main.html@@ -0,0 +1,11 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>Memory Dashboard</title>+</head>+<body>+ <x-component path="/plugins/memory/webui/memory-dashboard.html"></x-component>+</body>+</html>diff --git a/python/api/plugins_list.py b/python/api/plugins_list.pynew file mode 100644index 000000000..25d612db7--- /dev/null+++ b/python/api/plugins_list.py@@ -0,0 +1,13 @@+from python.helpers.api import ApiHandler, Input, Output, Request+from python.helpers import plugins++class PluginsList(ApiHandler):+ async def process(self, input: Input, request: Request) -> Output:+ filter = input.get("filter", {})++ custom = filter.get("custom", False)+ builtin = filter.get("builtin", False)++ plugin_list = plugins.get_enhanced_plugins_list(custom=custom, builtin=builtin)++ return {"ok": True, "plugins": [p.model_dump(mode="json") for p in plugin_list]}diff --git a/python/api/skills.py b/python/api/skills.pyindex c0d9fd04d..b37e92d23 100644--- a/python/api/skills.py+++ b/python/api/skills.py@@ -44,7 +44,7 @@ class Skills(ApiHandler):]if project_name:roots.append(- projects.get_project_meta_folder(project_name, "agents", agent_profile, "skills")+ projects.get_project_meta(project_name, "agents", agent_profile, "skills"))skill_list = [diff --git a/python/helpers/extension.py b/python/helpers/extension.pyindex 40665ec35..72e080535 100644--- a/python/helpers/extension.py+++ b/python/helpers/extension.py@@ -33,7 +33,7 @@ async def call_extensions(paths = subagents.get_paths(agent, "extensions", extension_point, default_root="python")# Add plugin backend extension paths (plugins/*/extensions/python/{extension_point})- plugin_paths = plugins.get_plugin_paths("extensions", "python", extension_point)+ plugin_paths = plugins.get_enabled_plugin_paths(agent, "extensions", "python", extension_point)paths.extend(p for p in plugin_paths if p not in paths)all_exts = [cls for path in paths for cls in _get_extensions(path)]diff --git a/python/helpers/files.py b/python/helpers/files.pyindex f0d63381e..276e7eb37 100644--- a/python/helpers/files.py+++ b/python/helpers/files.py@@ -216,6 +216,13 @@ def read_file(relative_path: str, encoding="utf-8"):with open(absolute_path, "r", encoding=encoding) as f:return f.read()+def read_file_json(relative_path: str, encoding="utf-8"):+ # Try to get the absolute path for the file from the original directory or backup directories+ absolute_path = get_abs_path(relative_path)++ # Read the file content+ with open(absolute_path, "r", encoding=encoding) as f:+ return json.load(f)def read_file_bin(relative_path: str):# Try to get the absolute path for the file from the original directory or backup directoriesdiff --git a/python/helpers/plugins.py b/python/helpers/plugins.pyindex e980a964b..a2c8008b6 100644--- a/python/helpers/plugins.py+++ b/python/helpers/plugins.py@@ -1,11 +1,11 @@from __future__ import annotationsimport re, json-from dataclasses import dataclassfrom pathlib import Pathfrom typing import Any, Dict, List, Optional, TYPE_CHECKINGfrom python.helpers import files, print_style+from pydantic import BaseModelif TYPE_CHECKING:from agent import Agent@@ -17,150 +17,257 @@ _META_TARGET_RE = re.compile()META_FILE_NAME = "plugin.json"-SETTINGS_FILE_NAME = "settings.json"+CONFIG_FILE_NAME = "config.json"+DISABLED_FILE_NAME = ".disabled"+ENABLED_FILE_NAME = ".enabled"-@dataclass(slots=True)-class PluginListItem:++class PluginMetadata(BaseModel):+ description: str = ""+++class PluginListItem(BaseModel):name: str- path: Path+ path: str+ description: str = ""+ has_main_screen: bool = False+ has_config_screen: bool = Falsedef get_plugin_roots() -> List[str]:"""Plugin root directories, ordered by priority (user first)."""- # Project-specific plugins (commented out for now, will add project/agent plugins later)- # projects = files.find_existing_paths_by_pattern("usr/projects/*/.a0proj/plugins")return [- # *projects,files.get_abs_path(files.USER_DIR, files.PLUGINS_DIR),files.get_abs_path(files.PLUGINS_DIR),]-def list_plugins() -> List[PluginListItem]:- """Discover plugins by directory convention. First root wins on ID conflict."""- by_id: Dict[str, PluginListItem] = {}+def get_plugins_list():+ result: list[str] = []+ seen_names: set[str] = set()for root in get_plugin_roots():- root_path = Path(root)- if not root_path.exists():- continue- for d in sorted(root_path.iterdir(), key=lambda p: p.name):- if not d.is_dir() or d.name.startswith("."):+ for dir in Path(root).iterdir():+ if not dir.is_dir() or dir.name.startswith("."):+ continue+ if dir.name in seen_names:continue- if d.name not in by_id:- by_id[d.name] = PluginListItem(name=d.name, path=d)- return list(by_id.values())+ if files.exists(str(dir), META_FILE_NAME):+ seen_names.add(dir.name)+ result.append(dir.name)+ result.sort(key=lambda p: Path(p).name)+ return result+++def get_enhanced_plugins_list(+ custom: bool = True, builtin: bool = True+) -> List[PluginListItem]:+ """Discover plugins by directory convention. First root wins on ID conflict."""+ results = []++ def load_plugins(root_path: str):+ for d in sorted(Path(root_path).iterdir(), key=lambda p: p.name):+ try:+ if not d.is_dir() or d.name.startswith("."):+ continue+ meta = PluginMetadata.model_validate(+ files.read_file_json(str(d / META_FILE_NAME))+ )+ has_main_screen = files.exists(str(d / "webui" / "main.html"))+ has_config_screen = files.exists(str(d / "webui" / "config.html"))+ results.append(+ PluginListItem(+ name=d.name,+ path=str(d),+ description=meta.description,+ has_main_screen=has_main_screen,+ has_config_screen=has_config_screen,+ )+ )+ except:+ pass++ if custom:+ load_plugins(files.get_abs_path(files.USER_DIR, files.PLUGINS_DIR))+ if builtin:+ load_plugins(files.get_abs_path(files.PLUGINS_DIR))+ return resultsdef find_plugin_dir(plugin_name: str):- """Find a single plugin by ID."""if not plugin_name:return None# check if the plugin is in the user directory- user_plugin_path = files.get_abs_path(files.USER_DIR, files.PLUGINS_DIR, plugin_name, META_FILE_NAME)+ user_plugin_path = files.get_abs_path(+ files.USER_DIR, files.PLUGINS_DIR, plugin_name, META_FILE_NAME+ )if files.exists(user_plugin_path):return files.get_abs_path(files.USER_DIR, files.PLUGINS_DIR, plugin_name)-+# check if the plugin is in the default directory- default_plugin_path = files.get_abs_path(files.PLUGINS_DIR, plugin_name, META_FILE_NAME)+ default_plugin_path = files.get_abs_path(+ files.PLUGINS_DIR, plugin_name, META_FILE_NAME+ )if files.exists(default_plugin_path):return files.get_abs_path(files.PLUGINS_DIR, plugin_name)-+return Nonedef get_plugin_paths(*subpaths: str) -> List[str]:- """- Resolve existing directories under each plugin matching subpaths.-- Example:- get_plugin_paths("extensions", "python", "monologue_end")- -> ["/abs/plugins/memory/extensions/python/monologue_end", ...]- """- sub = "/".join(subpaths) if subpaths else ""+ sub = "*/" + "/".join(subpaths) if subpaths else "*"paths: List[str] = []- for plugin in list_plugins():- candidate = str(plugin.path / sub) if sub else str(plugin.path)- if Path(candidate).is_dir() and candidate not in paths:- paths.append(candidate)+ for root in get_plugin_roots():+ paths.extend(+ files.find_existing_paths_by_pattern(files.get_abs_path(root, sub))+ )return paths+def get_enabled_plugin_paths(agent:Agent|None, *subpaths: str) -> List[str]:+ enabled = get_enabled_plugins(agent)+ paths: list[str] = []-def get_webui_extensions(extension_point:str, filters:List[str]|None=None) -> List[Dict[str, Any]]:- entries: List[Dict[str, Any]] = []- effective_filters = filters or ["*"]- for plugin in list_plugins():- frontend_dir = plugin.path / "extensions" / "webui" / extension_point- if not frontend_dir.is_dir():+ for plugin in enabled:+ base_dir = find_plugin_dir(plugin)+ if not base_dir:continue- matched_files: List[Path] = []- seen: set[str] = set()- for pattern in effective_filters:- for p in frontend_dir.rglob(pattern):- if not p.is_file():- continue- p_str = str(p)- if p_str in seen:- continue- seen.add(p_str)- matched_files.append(p)- for ext_file in sorted(matched_files, key=lambda p: p.name):- try:- rel_path = files.deabsolute_path(str(ext_file))- entry: Dict[str, Any] = {- "plugin_name": plugin.name,- "path": rel_path,- }- entries.append(entry)- except Exception:- print_style.PrintStyle.error(f"Failed to load frontend extension file {ext_file}")+ if not subpaths:+ if files.exists(base_dir):+ paths.append(base_dir)+ continue++ path = files.get_abs_path(base_dir, *subpaths)+ if files.exists(path):+ paths.append(path)++ return paths+++def get_enabled_plugins(agent: Agent | None):+ plugins = get_plugins_list()+ active = []++ if agent:+ from python.helpers import subagents++ for plugin in plugins:+ # plugins are toggled via .enabled / .disabled files+ # every plugin is on by default, unless disabled in usr dir+ enabled = True++ if agent:+ agent_paths = subagents.get_paths(+ agent,+ files.PLUGINS_DIR,+ plugin,+ must_exist_completely=True,+ include_default=False,+ include_user=True,+ include_plugins=False,+ include_project=True+ )++ # go through agent paths in reverse order and determine the state+ for agent_path in reversed(agent_paths):+ if enabled:+ enabled = not files.exists(files.get_abs_path(agent_path, DISABLED_FILE_NAME))+ else:+ enabled = files.exists(files.get_abs_path(agent_path, ENABLED_FILE_NAME))+++ if enabled:+ active.append(plugin)++ return active++++def get_webui_extensions(extension_point: str, filters: List[str] | None = None):+ entries: List[str] = []+ effective_filters = filters or ["*"]++ for filter in effective_filters:+ extensions = get_plugin_paths("extensions", "webui", extension_point, filter)+ for extension in extensions:+ rel_path = files.deabsolute_path(extension)+ entries.append(rel_path)+return entries-def get_plugin_settings(plugin_name:str, agent:Agent|None):- file_path = find_plugin_file(plugin_name, SETTINGS_FILE_NAME, agent=agent)++def get_plugin_config(plugin_name: str, agent: Agent | None):+ file_path = find_plugin_asset(plugin_name, CONFIG_FILE_NAME, agent=agent)if file_path:return json.loads(files.read_file(file_path))return None-def save_plugin_settings(plugin_name:str, project_name:str, agent_profile:str, settings:dict):- file_path = determine_plugin_save_file_path(plugin_name, project_name, agent_profile, SETTINGS_FILE_NAME)++def save_plugin_config(+ plugin_name: str, project_name: str, agent_profile: str, settings: dict+):+ file_path = determine_plugin_asset_path(+ plugin_name, project_name, agent_profile, CONFIG_FILE_NAME+ )if file_path:files.write_file(file_path, json.dumps(settings))-def find_plugin_file(plugin_name:str, *subpaths:str, agent:Agent|None=None):- profile_name = agent.config.profile if agent and agent.config.profile else ""++def find_plugin_asset(plugin_name: str, *subpaths: str, agent: Agent | None = None):project_name = ""if agent:+ profile_name = agent.config.profile if agent and agent.config.profile else ""+from python.helpers import projects+project_name = projects.get_context_project_name(agent.context) or ""if project_name and profile_name:# project/.a0proj/agents/<profile>/plugins/<plugin_name>/...- project_agent_file = projects.get_project_meta_folder(- project_name, files.AGENTS_DIR, profile_name, files.PLUGINS_DIR, plugin_name, *subpaths+ project_agent_file = projects.get_project_meta(+ project_name,+ files.AGENTS_DIR,+ profile_name,+ files.PLUGINS_DIR,+ plugin_name,+ *subpaths,)if files.exists(project_agent_file):return project_agent_fileif project_name:# project/.a0proj/plugins/<plugin_name>/...- project_file = projects.get_project_meta_folder(project_name, files.PLUGINS_DIR, plugin_name, *subpaths)+ project_file = projects.get_project_meta(+ project_name, files.PLUGINS_DIR, plugin_name, *subpaths+ )if files.exists(project_file):return project_file- if profile_name:- from python.helpers import subagents- # usr/agents/<profile>/plugins/<plugin_name>/...- path = files.get_abs_path(subagents.USER_AGENTS_DIR, profile_name, files.PLUGINS_DIR, plugin_name, *subpaths)- if files.exists(path):- return path+ if profile_name:+ from python.helpers import subagents- # agents/<profile>/plugins/<plugin_name>/...- path = files.get_abs_path(subagents.DEFAULT_AGENTS_DIR, profile_name, files.PLUGINS_DIR, plugin_name, *subpaths)- if files.exists(path):- return path+ # usr/agents/<profile>/plugins/<plugin_name>/...+ path = files.get_abs_path(+ subagents.USER_AGENTS_DIR,+ profile_name,+ files.PLUGINS_DIR,+ plugin_name,+ *subpaths,+ )+ if files.exists(path):+ return path++ # agents/<profile>/plugins/<plugin_name>/...+ path = files.get_abs_path(+ subagents.DEFAULT_AGENTS_DIR,+ profile_name,+ files.PLUGINS_DIR,+ plugin_name,+ *subpaths,+ )+ if files.exists(path):+ return path# usr/plugins/<plugin_name>/...path = files.get_abs_path(files.USER_DIR, files.PLUGINS_DIR, plugin_name, *subpaths)@@ -173,15 +280,19 @@ def find_plugin_file(plugin_name:str, *subpaths:str, agent:Agent|None=None):return pathreturn None--def determine_plugin_save_file_path(plugin_name:str, project_name:str, agent_profile:str, *subpaths:str):+++def determine_plugin_asset_path(+ plugin_name: str, project_name: str, agent_profile: str, *subpaths: str+):base_path = files.get_abs_path(files.USER_DIR)-+if project_name:from python.helpers import projects- base_path = projects.get_project_meta_folder(project_name)++ base_path = projects.get_project_meta(project_name)if agent_profile:base_path = files.get_abs_path(base_path, files.AGENTS_DIR, agent_profile)- return files.get_abs_path(base_path, files.PLUGINS_DIR, plugin_name, *subpaths)\ No newline at end of file+ return files.get_abs_path(base_path, files.PLUGINS_DIR, plugin_name, *subpaths)diff --git a/python/helpers/projects.py b/python/helpers/projects.pyindex 40adc0c63..d40a7ab2f 100644--- a/python/helpers/projects.py+++ b/python/helpers/projects.py@@ -67,7 +67,7 @@ def get_project_folder(name: str):return files.get_abs_path(get_projects_parent_folder(), name)-def get_project_meta_folder(name: str, *sub_dirs: str):+def get_project_meta(name: str, *sub_dirs: str):return files.get_abs_path(get_project_folder(name), PROJECT_META_DIR, *sub_dirs)@@ -398,20 +398,20 @@ def get_context_project_name(context: "AgentContext") -> str | None:def load_project_variables(name: str):try:- abs_path = files.get_abs_path(get_project_meta_folder(name), "variables.env")+ abs_path = files.get_abs_path(get_project_meta(name), "variables.env")return files.read_file(abs_path)except Exception:return ""def save_project_variables(name: str, variables: str):- abs_path = files.get_abs_path(get_project_meta_folder(name), "variables.env")+ abs_path = files.get_abs_path(get_project_meta(name), "variables.env")files.write_file(abs_path, variables)def load_project_subagents(name: str) -> dict[str, SubAgentSettings]:try:- abs_path = files.get_abs_path(get_project_meta_folder(name), "agents.json")+ abs_path = files.get_abs_path(get_project_meta(name), "agents.json")data = dirty_json.parse(files.read_file(abs_path))if isinstance(data, dict):return _normalize_subagents(data) # type: ignore[arg-type,return-value]@@ -421,7 +421,7 @@ def load_project_subagents(name: str) -> dict[str, SubAgentSettings]:def save_project_subagents(name: str, subagents_data: dict[str, SubAgentSettings]):- abs_path = files.get_abs_path(get_project_meta_folder(name), "agents.json")+ abs_path = files.get_abs_path(get_project_meta(name), "agents.json")normalized = _normalize_subagents(subagents_data)content = dirty_json.stringify(normalized)files.write_file(abs_path, content)@@ -475,15 +475,15 @@ def get_context_memory_subdir(context: "AgentContext") -> str | None:def create_project_meta_folders(name: str):# create instructions folder- files.create_dir(get_project_meta_folder(name, PROJECT_INSTRUCTIONS_DIR))+ files.create_dir(get_project_meta(name, PROJECT_INSTRUCTIONS_DIR))# create knowledge folders (plugins create their own subdirs lazily)- files.create_dir(get_project_meta_folder(name, PROJECT_KNOWLEDGE_DIR))+ files.create_dir(get_project_meta(name, PROJECT_KNOWLEDGE_DIR))def get_knowledge_files_count(name: str):knowledge_folder = files.get_abs_path(- get_project_meta_folder(name, PROJECT_KNOWLEDGE_DIR)+ get_project_meta(name, PROJECT_KNOWLEDGE_DIR))return len(files.list_files_in_dir_recursively(knowledge_folder))diff --git a/python/helpers/secrets.py b/python/helpers/secrets.pyindex e87faca88..8cb8b0cbc 100644--- a/python/helpers/secrets.py+++ b/python/helpers/secrets.py@@ -519,7 +519,7 @@ def get_secrets_manager(context: "AgentContext|None" = None) -> SecretsManager:if context:project = projects.get_context_project_name(context)if project:- secret_files.append(files.get_abs_path(projects.get_project_meta_folder(project), "secrets.env"))+ secret_files.append(files.get_abs_path(projects.get_project_meta(project), "secrets.env"))return SecretsManager.get_instance(*secret_files)@@ -533,7 +533,7 @@ def get_project_secrets_manager(project_name: str, merge_with_global: bool = Falsecret_files.append(DEFAULT_SECRETS_FILE)# merged with project secrets if active- secret_files.append(files.get_abs_path(projects.get_project_meta_folder(project_name), "secrets.env"))+ secret_files.append(files.get_abs_path(projects.get_project_meta(project_name), "secrets.env"))return SecretsManager.get_instance(*secret_files)diff --git a/python/helpers/skills_import.py b/python/helpers/skills_import.pyindex 7698fef50..527e6285b 100644--- a/python/helpers/skills_import.py+++ b/python/helpers/skills_import.py@@ -172,8 +172,8 @@ def _resolve_conflict(dest: Path, policy: ConflictPolicy) -> Tuple[Path, bool]:def get_project_skills_folder(project_name: str) -> Path:"""Get the skills folder path for a project."""- from python.helpers.projects import get_project_meta_folder- return Path(get_project_meta_folder(project_name, PROJECT_SKILLS_DIR))+ from python.helpers.projects import get_project_meta+ return Path(get_project_meta(project_name, PROJECT_SKILLS_DIR))def get_agent_profile_skills_folder(profile_name: str) -> Path:@@ -181,8 +181,8 @@ def get_agent_profile_skills_folder(profile_name: str) -> Path:def get_project_agent_profile_skills_folder(project_name: str, profile_name: str) -> Path:- from python.helpers.projects import get_project_meta_folder- return Path(get_project_meta_folder(project_name, "agents", profile_name, "skills"))+ from python.helpers.projects import get_project_meta+ return Path(get_project_meta(project_name, "agents", profile_name, "skills"))def resolve_skills_destination_root(diff --git a/python/helpers/subagents.py b/python/helpers/subagents.pyindex 1a0326643..36b71f70a 100644--- a/python/helpers/subagents.py+++ b/python/helpers/subagents.py@@ -64,7 +64,7 @@ def get_agents_dict(merged: dict[str, SubAgentListItem] = dict(default_agents)# merge with plugin agents- for plugin_dir in plugins.get_plugin_paths("agents"):+ for plugin_dir in plugins.get_enabled_plugin_paths(None, "agents"):plugin_agents = _get_agents_list_from_dir(plugin_dir, origin="plugin")merged = _merge_agent_dicts(merged, plugin_agents)@@ -75,7 +75,7 @@ def get_agents_dict(if project_name:from python.helpers import projects- project_agents_dir = projects.get_project_meta_folder(project_name, "agents")+ project_agents_dir = projects.get_project_meta(project_name, "agents")project_agents = _get_agents_list_from_dir(project_agents_dir, origin="project")merged = _merge_agent_dicts(merged, project_agents)@@ -120,7 +120,8 @@ def load_agent_data(name: str, project_name: str | None = None) -> SubAgent:merged = default_agent# merge with plugin agents- for plugin_dir in plugins.get_plugin_paths("agents"):+ # TODO review this+ for plugin_dir in plugins.get_enabled_plugin_paths(None, "agents"):plugin_agent = _load_agent_data_from_dir(plugin_dir, name, origin="plugin")merged = _merge_agent(merged, plugin_agent)@@ -131,7 +132,7 @@ def load_agent_data(name: str, project_name: str | None = None) -> SubAgent:if project_name:from python.helpers import projects- project_agents_dir = projects.get_project_meta_folder(project_name, "agents")+ project_agents_dir = projects.get_project_meta(project_name, "agents")project_agent = _load_agent_data_from_dir(project_agents_dir, name, origin="project")@@ -242,7 +243,7 @@ def _merge_agent_list_items(def get_agents_roots() -> list[str]:from python.helpers import plugins- plugin_agents = plugins.get_plugin_paths("agents")+ plugin_agents = plugins.get_enabled_plugin_paths(None, "agents")project_agents = files.find_existing_paths_by_pattern("usr/projects/*/.a0proj/agents")paths = [files.get_abs_path(DEFAULT_AGENTS_DIR),@@ -328,7 +329,7 @@ def get_paths(include_project: bool = True,include_user: bool = True,include_default: bool = True,- include_plugins: bool = False,+ include_plugins: bool = True,default_root: str = "",) -> list[str]:"""Returns list of file paths for the given agent and subpaths, searched in order of priority:@@ -345,7 +346,7 @@ def get_paths(if project_name and profile_name:# project/agents/<profile>/...- project_agent_dir = projects.get_project_meta_folder(+ project_agent_dir = projects.get_project_meta(project_name, "agents", profile_name)if files.exists(files.get_abs_path(project_agent_dir, *check_subpaths)):@@ -353,7 +354,7 @@ def get_paths(if project_name:# project/.a0proj/...- path = projects.get_project_meta_folder(project_name, *subpaths)+ path = projects.get_project_meta(project_name, *subpaths)if (not must_exist_completely) or files.exists(path):paths.append(path)@@ -365,11 +366,12 @@ def get_paths(paths.append(path)# plugin agents/<profile>/...- from python.helpers import plugins- for plugin_dir in plugins.get_plugin_paths("agents"):- path = files.get_abs_path(plugin_dir, profile_name, *subpaths)- if (not must_exist_completely) or files.exists(files.get_abs_path(plugin_dir, profile_name, *check_subpaths)):- paths.append(path)+ if include_plugins:+ from python.helpers import plugins+ for plugin_dir in plugins.get_enabled_plugin_paths(agent, "agents", profile_name):+ path = files.get_abs_path(plugin_dir, *subpaths)+ if (not must_exist_completely) or files.exists(files.get_abs_path(plugin_dir, *check_subpaths)):+ paths.append(path)# agents/<profile>/...path = files.get_abs_path(DEFAULT_AGENTS_DIR, profile_name, *subpaths)@@ -386,7 +388,7 @@ def get_paths(# plugins/*/subpaths...from python.helpers import plugins- for plugin in plugins.list_plugins():+ for plugin in plugins.get_enhanced_plugins_list():path = files.get_abs_path(str(plugin.path), *subpaths)if (not must_exist_completely) or files.exists(path):if path not in paths:diff --git a/run_ui.py b/run_ui.pyindex 1f702bd26..c4f01020a 100644--- a/run_ui.py+++ b/run_ui.py@@ -8,8 +8,10 @@ from functools import wrapsimport threadingimport asyncio+from pathlib import Pathimport urllib.requestimport urllib.error+from regex.regex import Fimport uvicornfrom flask import Flask, request, Response, session, redirect, url_for, render_template_stringfrom werkzeug.wrappers.response import Response as BaseResponse@@ -240,7 +242,16 @@ async def serve_index():# Serve plugin assets@webapp.route("/plugins/<plugin_name>/<path:asset_path>", methods=["GET"])@requires_auth+async def serve_builtin_plugin_asset(plugin_name, asset_path):+ return await _serve_plugin_asset(plugin_name, asset_path)+[email protected]("/usr/plugins/<plugin_name>/<path:asset_path>", methods=["GET"])+@requires_authasync def serve_plugin_asset(plugin_name, asset_path):+ return await _serve_plugin_asset(plugin_name, asset_path)+++async def _serve_plugin_asset(plugin_name, asset_path):"""Serve static assets from plugin directories.Resolves using the plugin system (with overrides).@@ -257,10 +268,11 @@ async def serve_plugin_asset(plugin_name, asset_path):try:# Construct path using plugin rootasset_file = files.get_abs_path(plugin_dir, asset_path)- plugin_root = plugin_dir+ webui_dir = files.get_abs_path(plugin_dir, "webui")+ webui_extensions_dir = files.get_abs_path(plugin_dir, "extensions/webui")- # Security: ensure the resolved path is within the plugin directory- if not files.is_in_dir(str(asset_file), str(plugin_root)):+ # Security: ensure the resolved path is within the plugin webui directory+ if not files.is_in_dir(str(asset_file), str(webui_dir)) and not files.is_in_dir(str(asset_file), str(webui_extensions_dir)):return Response("Access denied", 403)if not files.is_file(asset_file):@@ -499,8 +511,8 @@ def run():# Load API handlers from plugins (prefixed with /plugins/{plugin_id}/)from python.helpers import plugins- for plugin in plugins.list_plugins():- api_path = plugin.path / "api"+ for plugin in plugins.get_enhanced_plugins_list():+ api_path = Path(plugin.path) / "api"if not api_path.exists() or not api_path.is_dir():continuediff --git a/webui/components/plugins/list/plugin-list.html b/webui/components/plugins/list/plugin-list.htmlnew file mode 100644index 000000000..6e9109d8f--- /dev/null+++ b/webui/components/plugins/list/plugin-list.html@@ -0,0 +1,309 @@+<html>+<head>+ <title>Plugins</title>+ <script type="module">+ import { store } from "/components/plugins/list/pluginListStore.js";+ </script>+</head>++<body>+ <div x-data>+ <template x-if="$store.pluginListStore">+ <div x-init="$store.pluginListStore.loadPluginList && $store.pluginListStore.loadPluginList({ builtin: false, custom: true, search: '' })">++ <ul class="nav nav-tabs" id="plugin-list-tabs" role="tablist">+ <li class="nav-item" role="presentation">+ <button class="nav-link active" id="plugins-custom-tab" data-bs-toggle="tab"+ data-bs-target="#plugins-custom" type="button" role="tab"+ aria-controls="plugins-custom" aria-selected="true"+ @click="$store.pluginListStore.loadPluginList && $store.pluginListStore.loadPluginList({ builtin: false, custom: true, search: '' })">+ Custom+ </button>+ </li>+ <li class="nav-item" role="presentation">+ <button class="nav-link" id="plugins-builtin-tab" data-bs-toggle="tab"+ data-bs-target="#plugins-builtin" type="button" role="tab"+ aria-controls="plugins-builtin" aria-selected="false"+ @click="$store.pluginListStore.loadPluginList && $store.pluginListStore.loadPluginList({ builtin: true, custom: false, search: '' })">+ Builtin+ </button>+ </li>+ </ul>++ <div class="tab-content" id="plugin-list-tabs-content">+ <div class="tab-pane fade show active" id="plugins-custom" role="tabpanel"+ aria-labelledby="plugins-custom-tab">+ <div>+ <div class="plugins-toolbar">+ <div class="plugins-toolbar-actions">+ <button type="button" class="button confirm" title="Refresh"+ @click="$store.pluginListStore.loadPluginList && $store.pluginListStore.loadPluginList({ builtin: false, custom: true, search: '' })"+ :disabled="$store.pluginListStore.loading">+ <span class="icon material-symbols-outlined">refresh</span> Refresh+ </button>+ </div>+ </div>++ <div x-show="$store.pluginListStore.loading" class="loading">+ <span>Loading plugins...</span>+ </div>++ <div class="plugins-list">+ <template x-for="plugin in ($store.pluginListStore.plugins || [])" :key="plugin.path || plugin.name">+ <div class="plugin-card">+ <div class="plugin-header">+ <div class="plugin-heading">+ <div class="plugin-title" x-text="plugin.name || '(unnamed plugin)'"></div>+ <code class="plugin-path" x-text="plugin.path"></code>+ </div>+ <div class="plugin-actions">+ <template x-if="plugin.has_main_screen">+ <button type="button" class="button" title="Open"+ @click="$store.pluginListStore.openPlugin && $store.pluginListStore.openPlugin(plugin)">+ <span class="icon material-symbols-outlined">assistant_on_hub</span> Open+ </button>+ </template>+ <template x-if="plugin.has_config_screen">+ <button type="button" class="button" title="Config"+ @click="$store.pluginListStore.openPluginConfig && $store.pluginListStore.openPluginConfig(plugin)">+ <span class="icon material-symbols-outlined">settings</span> Config+ </button>+ </template>+ <button type="button" class="button" title="Info"+ @click="$store.pluginListStore.openPluginInfo && $store.pluginListStore.openPluginInfo(plugin)">+ <span class="icon material-symbols-outlined">info</span> Info+ </button>+ <button type="button" class="button cancel icon-button" title="Delete"+ @click="$confirmClick($event, () => $store.pluginListStore.deletePlugin && $store.pluginListStore.deletePlugin(plugin))">+ <span class="icon material-symbols-outlined">delete</span>+ </button>+ </div>+ </div>+ <div class="plugin-description" x-text="plugin.description || 'No description provided.'"></div>+ </div>+ </template>+ </div>+ </div>+ </div>++ <div class="tab-pane fade" id="plugins-builtin" role="tabpanel" aria-labelledby="plugins-builtin-tab">+ <div>+ <div class="plugins-toolbar">+ <div class="plugins-toolbar-actions">+ <button type="button" class="button confirm" title="Refresh"+ @click="$store.pluginListStore.loadPluginList && $store.pluginListStore.loadPluginList({ builtin: true, custom: false, search: '' })"+ :disabled="$store.pluginListStore.loading">+ <span class="icon material-symbols-outlined">refresh</span> Refresh+ </button>+ </div>+ </div>++ <div x-show="$store.pluginListStore.loading" class="loading">+ <span>Loading plugins...</span>+ </div>++ <div class="plugins-list">+ <template x-for="plugin in ($store.pluginListStore.plugins || [])" :key="plugin.path || plugin.name">+ <div class="plugin-card">+ <div class="plugin-header">+ <div class="plugin-heading">+ <div class="plugin-title" x-text="plugin.name || '(unnamed plugin)'"></div>+ <code class="plugin-path" x-text="plugin.path"></code>+ </div>+ <div class="plugin-actions">+ <template x-if="plugin.has_main_screen">+ <button type="button" class="button" title="Open"+ @click="$store.pluginListStore.openPlugin && $store.pluginListStore.openPlugin(plugin)">+ <span class="icon material-symbols-outlined">assistant_on_hub</span> Open+ </button>+ </template>+ <template x-if="plugin.has_config_screen">+ <button type="button" class="button" title="Config"+ @click="$store.pluginListStore.openPluginConfig && $store.pluginListStore.openPluginConfig(plugin)">+ <span class="icon material-symbols-outlined">settings</span> Config+ </button>+ </template>+ <button type="button" class="button" title="Info"+ @click="$store.pluginListStore.openPluginInfo && $store.pluginListStore.openPluginInfo(plugin)">+ <span class="icon material-symbols-outlined">info</span> Info+ </button>+ <button type="button" class="button cancel icon-button" title="Delete"+ @click="$confirmClick($event, () => $store.pluginListStore.deletePlugin && $store.pluginListStore.deletePlugin(plugin))">+ <span class="icon material-symbols-outlined">delete</span>+ </button>+ </div>+ </div>+ <div class="plugin-description" x-text="plugin.description || 'No description provided.'"></div>+ </div>+ </template>+ </div>+ </div>+ </div>+ </div>++ </div>+ </template>+ </div>++ <style>+ .nav {+ display: flex;+ padding-left: 0;+ margin: 0.75rem 0 0 0;+ list-style: none;+ border-bottom: 1px solid var(--color-border);+ gap: 0.25rem;+ }++ .nav-link {+ border: 1px solid transparent;+ border-top-left-radius: 4px;+ border-top-right-radius: 4px;+ padding: 0.4rem 0.7rem;+ background: transparent;+ color: var(--color-text-secondary);+ cursor: pointer;+ }++ .nav-link.active {+ color: var(--color-text-primary);+ border-color: var(--color-border);+ border-bottom-color: transparent;+ background: var(--color-bg-primary);+ }++ .tab-content {+ padding-top: 0.75rem;+ }++ .tab-pane {+ display: none;+ }++ .tab-pane.active {+ display: block;+ }++ .plugins-toolbar {+ display: flex;+ align-items: center;+ gap: 0.75rem;+ flex-wrap: wrap;+ margin-top: 0.25rem;+ margin-bottom: 0.75rem;+ }++ .plugins-toolbar-actions {+ margin-left: auto;+ flex: 0 0 auto;+ }++ .plugins-list {+ margin-top: 0.25rem;+ }++ .plugin-card {+ border: 1px solid var(--color-border);+ border-radius: 4px;+ padding: 0.75rem;+ margin-top: 0.75rem;+ background: var(--color-bg-primary);+ }++ .plugin-header {+ display: flex;+ align-items: flex-start;+ justify-content: space-between;+ gap: 1rem;+ flex-wrap: nowrap;+ min-width: 0;+ }++ .plugin-heading {+ display: flex;+ flex-direction: column;+ min-width: 0;+ flex: 1 1 auto;+ }++ .plugin-title {+ font-weight: 600;+ font-size: 1rem;+ min-width: 0;+ flex: 1 1 auto;+ }++ .plugin-actions {+ display: flex;+ align-items: center;+ gap: 0.5rem;+ padding-bottom: var(--spacing-sm);+ flex-wrap: nowrap;+ min-width: 0;+ flex: 0 0 auto;+ max-width: 100%;+ justify-content: flex-end;+ }++ @media (max-width: 640px) {+ .plugin-header {+ flex-direction: column;+ align-items: stretch;+ }++ .plugin-heading {+ width: 100%;+ flex: 0 0 auto;+ }++ .plugin-actions {+ width: 100%;+ justify-content: flex-start;+ padding-bottom: 0;+ flex-wrap: wrap;+ }++ .plugin-path {+ white-space: normal;+ word-break: break-word;+ }+ }++ .plugin-actions .button {+ padding: 0.25rem 0.5rem;+ font-size: 0.85rem;+ line-height: 1.1;+ }++ .plugin-actions .button .icon {+ font-size: 1.1rem;+ }++ .plugin-description {+ margin-top: 0.35rem;+ color: var(--color-text-secondary);+ font-size: var(--font-size-small);+ }++ .plugin-path {+ margin-top: 0.35rem;+ font-size: 0.85rem;+ color: var(--color-text-muted);+ min-width: 0;+ max-width: 100%;+ white-space: pre-wrap;+ word-break: break-word;+ overflow-wrap: anywhere;+ }++ .loading {+ width: 100%;+ text-align: center;+ margin-top: 0.75rem;+ margin-bottom: 0.75rem;+ color: var(--color-secondary);+ }+ </style>+</body>++</html>diff --git a/webui/components/plugins/list/pluginListStore.js b/webui/components/plugins/list/pluginListStore.jsnew file mode 100644index 000000000..4cfba8747--- /dev/null+++ b/webui/components/plugins/list/pluginListStore.js@@ -0,0 +1,43 @@+import { createStore } from "/js/AlpineStore.js";+import * as api from "/js/api.js";+import {+ store as notificationStore,+ defaultPriority,+} from "/components/notifications/notification-store.js";++// define the model object holding data and functions+const model = {+ loading: false,+ plugins: [],++ async loadPluginList(filter) {+ this.loading = true;+ this.plugins = [];+ try {+ const response = await api.callJsonApi("plugins_list", { filter });+ this.plugins = response.plugins;+ } catch (e) {+ showErrorNotification(e, "Failed to load plugins list");+ } finally {+ this.loading = false;+ }+ },+};++function showErrorNotification(error, heading) {+ const text = error.message || error.text || JSON.stringify(error);+ notificationStore.frontendError(+ text,+ heading,+ 3,+ "pluginsList",+ defaultPriority,+ true,+ );+}++// convert it to alpine store+const store = createStore("pluginListStore", model);++// export for use in other files+export { store };diff --git a/webui/components/sidebar/top-section/quick-actions.html b/webui/components/sidebar/top-section/quick-actions.htmlindex d083d3e54..988e977e1 100644--- a/webui/components/sidebar/top-section/quick-actions.html+++ b/webui/components/sidebar/top-section/quick-actions.html@@ -20,8 +20,8 @@</button><!-- Scheduler -->- <button class="config-button" id="scheduler" @click="openModal('modals/scheduler/scheduler-modal.html')" title="Scheduler">- <span class="material-symbols-outlined">schedule</span>+ <button class="config-button" id="plugins" @click="openModal('components/plugins/list/plugin-list.html')" title="Plugins">+ <span class="material-symbols-outlined">extension</span></button><!-- Settings -->@@ -56,7 +56,7 @@<span>Projects</span></button>- <button class="dropdown-item" @click="openModal('modals/scheduler/scheduler-modal.html'); dropdownOpen = false">+ <button class="dropdown-item" @click="openModal('components/scheduler/scheduler-modal.html'); dropdownOpen = false"><span class="material-symbols-outlined">schedule</span><span>Scheduler</span></button>diff --git a/webui/js/extensions.js b/webui/js/extensions.jsindex 9a4a5c859..9f75e2db0 100644--- a/webui/js/extensions.js+++ b/webui/js/extensions.js@@ -1,8 +1,7 @@import * as api from "./api.js";/**- * @typedef {Object} WebuiExtension- * @property {string} path+ * @typedef {string} WebuiExtension*/@@ -62,9 +61,9 @@ export async function loadJsExtensions(extensionPoint) {});/** @type {JsExtensionImport[]} */const imports = await Promise.all(- response.extensions.map(async extension => ({- path: extension.path,- module: await import(normalizePath(extension.path))+ response.extensions.map(async (path) => ({+ path,+ module: await import(normalizePath(path))})));jsExtensionsCache.set(extensionPoint, imports);@@ -134,7 +133,7 @@ export async function importHtmlExtensions(extensionPoint, targetElement) {});let combinedHTML = "";for (const extension of response.extensions) {- const path = normalizePath(extension.path);+ const path = normalizePath(extension);combinedHTML += `<x-component path="${path}"></x-component>`;}htmlExtensionsCache.set(extensionPoint, combinedHTML);