update and cleanup repo
This commit is contained in:
+4
-14
@@ -4,6 +4,8 @@ import os
|
||||
from importlib import import_module
|
||||
from typing import Any, Callable, Dict, Sequence
|
||||
|
||||
from SYS.cmdlet_spec import collect_registered_cmdlet_names
|
||||
|
||||
CmdletFn = Callable[[Any, Sequence[str], Dict[str, Any]], int]
|
||||
|
||||
|
||||
@@ -12,20 +14,8 @@ def _register_cmdlet_object(cmdlet_obj, registry: Dict[str, CmdletFn]) -> None:
|
||||
if not callable(run_fn):
|
||||
return
|
||||
|
||||
if hasattr(cmdlet_obj, "name") and cmdlet_obj.name:
|
||||
registry[cmdlet_obj.name.replace("_", "-").lower()] = run_fn
|
||||
|
||||
# Cmdlet uses 'alias' (List[str]). Some older objects may use 'aliases'.
|
||||
aliases: list[str] = []
|
||||
if hasattr(cmdlet_obj, "alias") and getattr(cmdlet_obj, "alias"):
|
||||
aliases.extend(getattr(cmdlet_obj, "alias") or [])
|
||||
if hasattr(cmdlet_obj, "aliases") and getattr(cmdlet_obj, "aliases"):
|
||||
aliases.extend(getattr(cmdlet_obj, "aliases") or [])
|
||||
|
||||
for alias in aliases:
|
||||
if not alias:
|
||||
continue
|
||||
registry[alias.replace("_", "-").lower()] = run_fn
|
||||
for registered_name in collect_registered_cmdlet_names(cmdlet_obj):
|
||||
registry[registered_name] = run_fn
|
||||
|
||||
|
||||
def _iter_legacy_native_module_names() -> list[str]:
|
||||
|
||||
@@ -34,8 +34,6 @@ def _provider_config_map(config: dict) -> dict[str, Any]:
|
||||
return {}
|
||||
|
||||
provider_cfg = config.get("plugin")
|
||||
if not isinstance(provider_cfg, dict):
|
||||
provider_cfg = config.get("provider")
|
||||
return provider_cfg if isinstance(provider_cfg, dict) else {}
|
||||
|
||||
|
||||
@@ -100,34 +98,14 @@ def _resolve_startup_instance_text(
|
||||
return ", ".join(_extract_configured_instance_names(configured_entry))
|
||||
|
||||
|
||||
def has_store_subtype(cfg: dict, subtype: str) -> bool:
|
||||
store_cfg = cfg.get("store")
|
||||
if not isinstance(store_cfg, dict):
|
||||
return False
|
||||
bucket = store_cfg.get(subtype)
|
||||
if not isinstance(bucket, dict):
|
||||
return False
|
||||
return any(isinstance(value, dict) and bool(value) for value in bucket.values())
|
||||
|
||||
|
||||
def has_provider(cfg: dict, name: str) -> bool:
|
||||
provider_cfg = cfg.get("plugin")
|
||||
if not isinstance(provider_cfg, dict):
|
||||
provider_cfg = cfg.get("provider")
|
||||
if not isinstance(provider_cfg, dict):
|
||||
return False
|
||||
block = provider_cfg.get(str(name).strip().lower())
|
||||
return isinstance(block, dict) and bool(block)
|
||||
|
||||
|
||||
def has_tool(cfg: dict, name: str) -> bool:
|
||||
tool_cfg = cfg.get("tool")
|
||||
if not isinstance(tool_cfg, dict):
|
||||
return False
|
||||
block = tool_cfg.get(str(name).strip().lower())
|
||||
return isinstance(block, dict) and bool(block)
|
||||
|
||||
|
||||
def ping_url(url: str, timeout: float = 3.0) -> tuple[bool, str]:
|
||||
try:
|
||||
from API.HTTP import HTTPClient
|
||||
|
||||
+8
-38
@@ -14,10 +14,8 @@ from SYS.database import LOG_DB_PATH, db
|
||||
from SYS.logger import log
|
||||
from SYS.plugin_config import (
|
||||
build_default_plugin_config,
|
||||
build_default_tool_config,
|
||||
get_configurable_plugin_types,
|
||||
get_configurable_store_types,
|
||||
get_configurable_tool_types,
|
||||
)
|
||||
from SYS import pipeline as ctx
|
||||
from SYS.result_table import Table
|
||||
@@ -32,19 +30,15 @@ from cmdnat._parsing import (
|
||||
|
||||
_PREFERENCES_BROWSE_PATH = "__preferences__"
|
||||
_PLUGINS_BROWSE_PATH = "__plugins__"
|
||||
_PLUGIN_CATEGORY_KEYS = ("plugin", "provider", "tool")
|
||||
_PLUGIN_CATEGORY_KEYS = ("plugin",)
|
||||
_CREATE_INSTANCE_FLAG = "-create-instance"
|
||||
_KNOWN_SECTION_LABELS = {
|
||||
"plugin": "Plugins",
|
||||
"provider": "Plugins",
|
||||
"tool": "Plugins",
|
||||
}
|
||||
_KNOWN_SECTION_DESCRIPTIONS = {
|
||||
_PREFERENCES_BROWSE_PATH: "Global preferences and simple values",
|
||||
_PLUGINS_BROWSE_PATH: "All configured plugins and plugin instances",
|
||||
"provider": "Plugin configuration",
|
||||
"plugin": "Plugin configuration",
|
||||
"tool": "Plugin configuration",
|
||||
}
|
||||
_SENSITIVE_CONFIG_KEYS = {
|
||||
"access_key",
|
||||
@@ -300,19 +294,6 @@ def _get_configurable_plugin_names() -> List[str]:
|
||||
]
|
||||
except Exception:
|
||||
return []
|
||||
|
||||
|
||||
def _get_configurable_tool_names() -> List[str]:
|
||||
try:
|
||||
return [
|
||||
str(name).strip().lower()
|
||||
for name in (get_configurable_tool_types() or [])
|
||||
if str(name).strip()
|
||||
]
|
||||
except Exception:
|
||||
return []
|
||||
|
||||
|
||||
def _get_multi_instance_plugin_names() -> set[str]:
|
||||
try:
|
||||
return {
|
||||
@@ -336,7 +317,7 @@ def _is_multi_instance_plugin_root_path(browse_path: Optional[str]) -> bool:
|
||||
parts = _split_config_path(browse_path)
|
||||
return (
|
||||
len(parts) == 2
|
||||
and parts[0] in {"plugin", "provider"}
|
||||
and parts[0] == "plugin"
|
||||
and _is_multi_instance_plugin_name(parts[1])
|
||||
)
|
||||
|
||||
@@ -397,10 +378,6 @@ def _build_synthetic_plugin_branch(category: str, name: str) -> Optional[Dict[st
|
||||
if not normalized_name:
|
||||
return None
|
||||
|
||||
if normalized_category == "tool":
|
||||
branch = build_default_tool_config(normalized_name)
|
||||
return dict(branch) if isinstance(branch, dict) else None
|
||||
|
||||
branch = build_default_plugin_config(normalized_name)
|
||||
if not isinstance(branch, dict):
|
||||
return None
|
||||
@@ -441,10 +418,7 @@ def _resolve_plugin_branch(
|
||||
if not normalized_name:
|
||||
return None
|
||||
|
||||
if normalized_category == "tool":
|
||||
if normalized_name not in _get_configurable_tool_names():
|
||||
return None
|
||||
elif normalized_name not in _get_configurable_plugin_names():
|
||||
if normalized_name not in _get_configurable_plugin_names():
|
||||
return None
|
||||
|
||||
synthetic = _build_synthetic_plugin_branch(normalized_category, normalized_name)
|
||||
@@ -557,7 +531,7 @@ def _resolve_config_branch(
|
||||
if resolved is None:
|
||||
return None
|
||||
_, current, _ = resolved
|
||||
if parts[0] in {"plugin", "provider"} and _is_multi_instance_plugin_name(parts[1]):
|
||||
if parts[0] == "plugin" and _is_multi_instance_plugin_name(parts[1]):
|
||||
current = _normalize_multi_instance_branch(parts[1], current)
|
||||
for part in parts[2:]:
|
||||
if not isinstance(current, dict):
|
||||
@@ -620,7 +594,7 @@ def _create_or_get_plugin_instance(
|
||||
instance_name: str,
|
||||
) -> tuple[str, bool]:
|
||||
parts = _split_config_path(instance_target)
|
||||
if len(parts) != 2 or parts[0] not in {"plugin", "provider"}:
|
||||
if len(parts) != 2 or parts[0] != "plugin":
|
||||
raise ValueError(f"Unsupported instance target '{instance_target}'")
|
||||
|
||||
category, plugin_name = parts
|
||||
@@ -663,7 +637,7 @@ def _resolve_update_key(config_data: Dict[str, Any], selection_key: str) -> str:
|
||||
parts = _split_config_path(selection_key)
|
||||
if (
|
||||
len(parts) >= 4
|
||||
and parts[0] in {"plugin", "provider"}
|
||||
and parts[0] == "plugin"
|
||||
and parts[2].lower() == "default"
|
||||
and _is_multi_instance_plugin_name(parts[1])
|
||||
):
|
||||
@@ -797,7 +771,7 @@ def _build_config_header_lines(browse_path: Optional[str]) -> List[str]:
|
||||
parts = _split_config_path(text)
|
||||
if (
|
||||
len(parts) == 3
|
||||
and parts[0] in {"plugin", "provider"}
|
||||
and parts[0] == "plugin"
|
||||
and _is_multi_instance_plugin_name(parts[1])
|
||||
):
|
||||
return [
|
||||
@@ -951,17 +925,13 @@ def _resolve_direct_browse_path(
|
||||
lowered = text.lower()
|
||||
if lowered in {"preferences", "prefs"}:
|
||||
return _PREFERENCES_BROWSE_PATH
|
||||
if lowered in {"plugins", "plugin", "providers", "provider", "tools", "tool"}:
|
||||
if lowered in {"plugins", "plugin"}:
|
||||
return _PLUGINS_BROWSE_PATH
|
||||
|
||||
plugin_branch = _resolve_plugin_branch(config_data, "plugin", lowered)
|
||||
if plugin_branch is not None:
|
||||
return f"plugin.{plugin_branch[0]}"
|
||||
|
||||
tool_branch = _resolve_plugin_branch(config_data, "tool", lowered)
|
||||
if tool_branch is not None:
|
||||
return f"tool.{tool_branch[0]}"
|
||||
|
||||
branch = _resolve_config_branch(config_data, text)
|
||||
if isinstance(branch, dict):
|
||||
return text
|
||||
|
||||
+7
-21
@@ -4,7 +4,7 @@ from typing import Any, Dict, Sequence, List, Optional, Tuple
|
||||
import shlex
|
||||
import sys
|
||||
|
||||
from SYS.cmdlet_spec import Cmdlet, CmdletArg, parse_cmdlet_args
|
||||
from SYS.cmdlet_spec import Cmdlet, CmdletArg, collect_registered_cmdlet_names, parse_cmdlet_args
|
||||
from cmdlet import REGISTRY as CMDLET_REGISTRY, ensure_cmdlet_modules_loaded
|
||||
from SYS.logger import log
|
||||
from SYS.result_table import Table
|
||||
@@ -53,26 +53,12 @@ def _normalize_cmdlet_key(name: Optional[str]) -> str:
|
||||
|
||||
|
||||
def _cmdlet_aliases(cmdlet_obj: Cmdlet) -> List[str]:
|
||||
aliases: List[str] = []
|
||||
for attr in ("alias", "aliases"):
|
||||
raw_aliases = getattr(cmdlet_obj, attr, None)
|
||||
if isinstance(raw_aliases, (list, tuple, set)):
|
||||
candidates = raw_aliases
|
||||
else:
|
||||
candidates = (raw_aliases,)
|
||||
for alias in candidates or ():
|
||||
text = str(alias or "").strip()
|
||||
if text:
|
||||
aliases.append(text)
|
||||
seen: set[str] = set()
|
||||
deduped: List[str] = []
|
||||
for alias in aliases:
|
||||
key = alias.lower()
|
||||
if key in seen:
|
||||
continue
|
||||
seen.add(key)
|
||||
deduped.append(alias)
|
||||
return deduped
|
||||
canonical_name = _normalize_cmdlet_key(getattr(cmdlet_obj, "name", None))
|
||||
return [
|
||||
registered_name
|
||||
for registered_name in collect_registered_cmdlet_names(cmdlet_obj)
|
||||
if registered_name != canonical_name
|
||||
]
|
||||
|
||||
|
||||
def _cmdlet_arg_to_dict(arg: CmdletArg) -> Dict[str, Any]:
|
||||
|
||||
Reference in New Issue
Block a user