Both WeCom platforms (AI Bot `wecom`, self-built-app `wecom_callback`) move to NousResearch/hermes-labs-plugins `wecom/`. Two LEFT_CORE rows (one per platform, one shared plugin, installed once) whose platform_in_use predicates replicate core's enable gates per mode. Stacked on the DingTalk removal (#159638): the platform lists both PRs edit are resolved once here. Folded from the earlier branch (one commit per step, in order): 331094ca15a3 Teknium test(gateway): a named profile's port-binder is served only on a default listener, live reconcile too The live reconcile builds a named profile's platforms through the same prepare step as startup, so the "not served" refusal holds there as well: a LINE secondary with neither api_server nor webhook on the default stays unstarted and names the remedy instead of reading as connected. The two LINE named-profile reconcile tests now give the default a webhook listener, so their LINE is served at /p/b/ as in a real setup; their assertions are unchanged. bedc93176b93 Teknium fix(left-core): off-platforms derive from the LEFT_CORE rows; left-core routes name the install Same hunk as the QQ Bot (#159640) and Feishu (#159651) PRs, so merge order cannot leave a stale entry. - A row whose tools lived in its own hermes-<platform> bundle only (Yuanbao) sets own_platform_only; _derive_off_platforms fills off_platforms with every platform core knows plus every platform a LEFT_CORE row moved out. The hand list _YUANBAO_OFF_PLATFORMS (which this PR had extended with wecom/wecom_callback) is gone. The WeCom rows carry no toolsets (hermes-wecom and hermes-wecom-callback bundled core tools only), so they need no off-platforms. - Webhook routes: is_known_platform accepts any platform a LEFT_CORE row moved out, so a saved wecom or wecom_callback route stays loaded before a secondary profile's plugin registers; without the plugin the send fails naming the install. - Cron: a deliver route naming a left-core platform whose plugin is not loaded reports the install command (delivery error and preflight). tests/cron/test_cron_left_core_platform_route.py runs for wecom and wecom_callback. 05d04a49ccc3 Teknium refactor(wecom): drop the one-install-per-home copy; the installer-race PR carries it generically 296e4a152f99 Teknium fix(gateway): a secondary port-binder with no default listener is not served, not "connected" Under multiplex a secondary profile's port-binding adapter (WeCom callback, LINE, SMS, Teams, ...) binds nothing: its app is published for /p/<profile>/ on the default profile's api_server or webhook listener. With neither running on the default, connect() still returned True and the runner logged "✓ wecom_callback connected (profile: b)" while nothing listened anywhere. - Runner: such an adapter is not started; it is stamped `<profile>:<platform>` disabled with error_code multiplex_no_shared_listener and a WARNING naming the remedy. - Migration preflight: a secondary whose own gateway serves a port-binder today is refused when the default enables neither listener (it would be served nowhere after the fold); a secondary with no gateway gets the same text as a notice. - bind_listener publishes the port it actually bound (`listener_base`); the dashboard topology reads that instead of resolving a plugin platform's listen_port in the profile's plugin registry, so a parked or cold profile's callback port is reported and no deferred loader runs. 26cde0b03cdc Teknium refactor(wecom): WeCom moves to the Hermes Labs wecom plugin, opt-in WeCom is now a Hermes Labs plugin (NousResearch/hermes-labs-plugins), not an official default one. Only homes that used WeCom get it installed, once; a new home installs nothing. - Both LEFT_CORE rows (bot and callback) carry the labs notice, like Yuanbao and DingTalk, merged with the plugins.disabled 'wecom' sentence. - Docs pages say "moved to the wecom Hermes Labs plugin" with the labs warning (en + zh-Hans); no default-install wording is left. - The one-automatic-install-per-plugin seam between default_plugins and the left-core migration stays: it is general (any plugin that is both a catalog default and a LEFT_CORE row) and now has its tests in test_default_plugins with a stand-in plugin instead of the wecom-named ones. 9c82896ffee9 Teknium fix(wecom): migration preflight and dashboard read plugin capabilities in the owning profile - platform_serves_profile_prefix(value, home) reads the adapter class in the owning profile's plugin scope, like platform_binds_port: a port-binding plugin only a secondary installed is a URL-change notice, not a blocker. - A parked profile's plugins are never discovered for either check, nor for the dashboard's port readout (read-only probe). deb0661c69ea Teknium fix(wecom): review findings on the core removal - One automatic install per plugin across both installers: left-core `_pending` skips a plugin `_default_plugins_installed` records, and default_plugins skips one `_left_core_installed` records, so a removed WeCom stays removed whichever ran first. - `listen_port` is read in the owning profile's plugin scope: a multiplexed secondary (shared-listener routing), migration preflight (per profile home) and the dashboard topology (discovers that home's plugins; preflight never does, a parked profile's plugins must not run here). - `hermes-wecom-callback` keeps resolving: a `hermes-<a-b>` bundle falls back to platform `a_b`, and toolset validation accepts it. - StandaloneSendPolicy.media_via_adapter moves after reply_file_over so positional callers keep their meaning. - cron home-target priority keeps wecom (the plugin platform keeps it). - `_BUNDLED_ENV_SIBLINGS` removed with its readers' prefix branch. c3ec8edb3cc4 Teknium refactor(wecom): WeCom leaves core for the official wecom plugin Both WeCom platforms (AI Bot `wecom`, self-built-app `wecom_callback`) move to NousResearch/hermes-official-plugins `wecom/`, installed by default on every home (catalog `default: true`). Existing users get it automatically: two LEFT_CORE rows (one per platform, one shared plugin, installed once) whose platform_in_use predicates replicate core's enable gates per mode. Generic seams added for the plugin, never a name check left in core: - PlatformEntry.listen_port: a plugin platform that binds a host port (platform_binds_port, multiplex shared listener, migration blockers, dashboard topology). Replaces the wecom_callback rows. - StandaloneSendPolicy.media_via_adapter: send_message media through the live adapter route. Replaces the _CHUNKED_ROUTES["wecom"] row. - cron: a registered plugin platform without a cron env var (home channel from config.yaml only) is a valid delivery target. Replaces the wecom_callback row. Child-env strip set unchanged: _ADAPTER_SECRET_ENV also carries the left-core platform rows' secret_env.
181 lines
8.5 KiB
Python
181 lines
8.5 KiB
Python
"""Validation for the ``platform_toolsets`` config section."""
|
|
|
|
import ast
|
|
from functools import cache
|
|
from typing import Callable, List, Optional
|
|
|
|
from hermes_cli.platforms import PLATFORMS
|
|
from hermes_cli.toolset_scope import toolset_allowed_for_platform
|
|
|
|
_NO_TOOLS = "the agent will have no tools on this platform. Run `hermes tools` to reconfigure."
|
|
|
|
|
|
def parse_platform_toolsets_value(value: object) -> Optional[list[str]]:
|
|
"""The toolset list a saved ``platform_toolsets.<platform>`` value encodes, or None.
|
|
|
|
Older ``hermes config set`` builds stored a bare ``[...]`` argument as a plain string, so an
|
|
explicit selection like ``'["browser", "terminal"]'`` parses as str, not list (#115866).
|
|
Every reader and writer of the section goes through this one parser so the runtime,
|
|
``hermes doctor`` and ``hermes plugins enable`` agree on what the user configured. Any other
|
|
shape (null, scalar, unparseable string) is None: the caller decides how to report it.
|
|
"""
|
|
if isinstance(value, list):
|
|
return value
|
|
if isinstance(value, str) and value.strip().startswith("["):
|
|
try:
|
|
parsed = ast.literal_eval(value.strip())
|
|
except (ValueError, SyntaxError):
|
|
return None
|
|
if isinstance(parsed, list):
|
|
return [str(item) for item in parsed]
|
|
return None
|
|
|
|
|
|
def _platform_default_toolset(platform: object) -> str:
|
|
info = PLATFORMS.get(platform)
|
|
return info.default_toolset if info is not None else f"hermes-{platform}"
|
|
|
|
|
|
@cache
|
|
def _bundled_platform_names() -> frozenset:
|
|
from hermes_cli.config import _platform_manifest_paths
|
|
|
|
return frozenset(name for name, path, _kind, _st in _platform_manifest_paths(source="bundled") if path)
|
|
|
|
|
|
def is_known_platform_bundle(platform: object, name: str) -> bool:
|
|
"""True when ``name`` is the ``hermes-<platform>`` bundle of a platform Hermes knows: builtin, shipped
|
|
under ``plugins/platforms``, a platform that left core for a catalog plugin, or one a loaded plugin
|
|
registered. Installs seeded from cli-config.yaml.example carry such rows for platforms nobody set up
|
|
(teams, google_chat, homeassistant), inert until the plugin loads. A misspelt platform key naming its
|
|
own bundle (``telegarm: [hermes-telegarm]``) is not known, so it is still reported."""
|
|
if name != _platform_default_toolset(platform):
|
|
return False
|
|
key = str(platform)
|
|
if key in PLATFORMS or key in _bundled_platform_names():
|
|
return True
|
|
from hermes_cli.left_core_migration import LEFT_CORE
|
|
|
|
if any(feature.platform == key for feature in LEFT_CORE):
|
|
return True
|
|
from gateway.platform_registry import platform_registry
|
|
|
|
return platform_registry.is_registered(key)
|
|
|
|
|
|
def _platform_default_is_valid(
|
|
platform: object, default_toolset: str, is_valid_toolset: Callable[[str], bool],
|
|
is_allowed_for_platform: Callable[[str, str], bool]) -> bool:
|
|
if is_valid_toolset(default_toolset) and is_allowed_for_platform(default_toolset, str(platform)):
|
|
return True
|
|
# Dynamic plugin platforms are resolved by toolsets.resolve_toolset() even though their synthesized
|
|
# hermes-<platform> name is not in TOOLSETS.
|
|
try:
|
|
from gateway.platform_registry import platform_registry
|
|
|
|
return platform_registry.is_registered(platform)
|
|
except Exception:
|
|
return False
|
|
|
|
|
|
def saved_toolset_resolver(config: dict) -> Callable[[str], bool]:
|
|
"""``is_valid_toolset`` for a saved ``platform_toolsets`` list, mirroring what
|
|
``tools_config._get_platform_tools`` lets through: registered toolsets, any configured MCP server by
|
|
its ``mcp-<server>`` toolset name or bare alias (neither is registered before MCP discovery; a
|
|
disabled server is inactive, not a typo), ``hermes-<platform>`` plugin-platform bundles and the
|
|
``no_mcp`` sentinel. The manifest scan and the plugin lookup (which may run plugin discovery)
|
|
happen only for a name the cheaper checks cannot place."""
|
|
from functools import cache
|
|
|
|
from toolsets import validate_toolset
|
|
|
|
mcp_servers = config.get("mcp_servers")
|
|
servers = {str(name) for name in mcp_servers} if isinstance(mcp_servers, dict) else set()
|
|
known = servers | {f"mcp-{name}" for name in servers} | {"no_mcp"}
|
|
|
|
@cache
|
|
def platform_bundles() -> frozenset:
|
|
from hermes_cli.config import _platform_plugin_manifests
|
|
|
|
return frozenset(f"hermes-{name}" for name, _manifest in _platform_plugin_manifests())
|
|
|
|
@cache
|
|
def plugin_names() -> frozenset:
|
|
from hermes_cli.plugins import get_plugin_toolset_keys_nowait, get_portable_mcp_server_names_nowait
|
|
|
|
portable = get_portable_mcp_server_names_nowait()
|
|
return frozenset(get_plugin_toolset_keys_nowait() | portable | {f"mcp-{name}" for name in portable})
|
|
|
|
def registered_platform_bundle(name: str) -> bool:
|
|
# A plugin may register a platform under a name other than its manifest dir
|
|
# (``wecom_callback`` from ``wecom/``): its ``hermes-<platform>`` bundle resolves too.
|
|
from toolsets import _plugin_platform_bundle
|
|
return name.startswith("hermes-") and bool(_plugin_platform_bundle(name))
|
|
|
|
return lambda name: (validate_toolset(name) or name in known
|
|
or name in platform_bundles() or name in plugin_names()
|
|
or registered_platform_bundle(name))
|
|
|
|
|
|
def validate_platform_toolsets(
|
|
platform_toolsets: object, is_valid_toolset: Callable[[str], bool],
|
|
is_allowed_for_platform: Callable[[str, str], bool] = toolset_allowed_for_platform,
|
|
) -> list[str]:
|
|
"""Return human-readable warnings for a ``platform_toolsets`` mapping.
|
|
Reports: a toolset name ``is_valid_toolset`` rejects (suggesting ``hermes-<platform>`` when that
|
|
would have been valid); a non-empty mapping resolving to zero valid toolsets (agent would start with
|
|
no tools); a platform with no valid toolsets, checked per-platform because the global net is
|
|
suppressed once any platform is valid; and non-list platform values, which fall back to the platform
|
|
default. ``is_valid_toolset`` is injected so this does no registry imports or I/O."""
|
|
warnings: list[str] = []
|
|
if not isinstance(platform_toolsets, dict) or not platform_toolsets:
|
|
return warnings
|
|
|
|
valid_count = 0
|
|
for platform, raw in platform_toolsets.items():
|
|
default = _platform_default_toolset(platform)
|
|
default_valid = _platform_default_is_valid(platform, default, is_valid_toolset, is_allowed_for_platform)
|
|
platform_valid_count = 0
|
|
toolsets = parse_platform_toolsets_value(raw)
|
|
if toolsets is None:
|
|
if default_valid:
|
|
valid_count += 1
|
|
platform_valid_count += 1
|
|
fallback_detail = f"falling back to '{default}'" if default_valid else f"falling back to unknown default '{default}'"
|
|
if raw is None:
|
|
value_detail = "a null toolset value"
|
|
elif isinstance(raw, str):
|
|
value_detail = f"invalid toolset value '{raw}'"
|
|
else:
|
|
value_detail = f"invalid {type(raw).__name__} toolset value"
|
|
warnings.append(
|
|
f"platform '{platform}' has {value_detail} — "
|
|
f"{fallback_detail}. Run `hermes tools` to configure explicitly.")
|
|
if platform_valid_count == 0:
|
|
warnings.append(f"platform '{platform}' has no valid toolsets configured — {_NO_TOOLS}")
|
|
continue
|
|
|
|
for name in toolsets:
|
|
if not isinstance(name, str) or not name:
|
|
continue
|
|
if not is_valid_toolset(name) and not is_known_platform_bundle(platform, name):
|
|
hint = f" — did you mean '{default}'?" if default_valid else ""
|
|
warnings.append(f"platform '{platform}' references unknown toolset '{name}'{hint}")
|
|
elif is_allowed_for_platform(name, str(platform)):
|
|
valid_count += 1
|
|
platform_valid_count += 1
|
|
else:
|
|
warnings.append(
|
|
f"platform '{platform}' references toolset '{name}' which is not available on this platform"
|
|
)
|
|
|
|
if platform_valid_count == 0:
|
|
reason = "is configured with an empty toolset list" if not toolsets else "has no valid toolsets configured"
|
|
warnings.append(f"platform '{platform}' {reason} — {_NO_TOOLS}")
|
|
|
|
if valid_count == 0:
|
|
warnings.append(
|
|
"platform_toolsets resolves to zero valid toolsets — the agent will "
|
|
"have no tools. Run `hermes tools` to reconfigure.")
|
|
return warnings
|