Files
hermes-agent/plugins/google_meet/node/cli.py
Teknium 2776813df3 compat(plugins): temporary import-path shims for external plugins — ONE commit, revert on schedule
The Sep 2026 decomposition (PR #102117) makes internal import paths a non-API: names now live in
the focused modules that define them. This commit is the ONLY thing keeping the old paths alive,
so external plugins have time to update. It is deliberately a single, unsquashed commit:

    git revert <this sha>

removes every shim, stub and manifest at once on the announced date. Nothing in-tree may depend on
these pointers: scripts/check_compat_pointers.py (wired into lint.yml) fails CI if it does.

What it adds (see COMPAT_MANIFEST.md, compat_manifest.json):
- 332 facade modules get one delimited `PLUGIN-COMPAT` block appended at the end of the file
- 1,172 moved names resolved lazily via a module `__getattr__` (PEP 562) — never a top-level import,
  so no import cycles; facades that already had `__getattr__` get a chained one
- 592 third-party/stdlib names the old modules used to expose, with their original import statements
- 266 public definitions that had been deleted as unused, restored byte-for-byte from the pre-decomposition
  tree (+40 private helpers and 16 imports pulled in only because a restored definition needs them)
- 3 deleted modules recreated as re-export stubs (gateway/startup_watchdog, hermes_cli/observability/
  relay_runtime, tools/environments/modal_utils)
- private names (`_x`) get no pointer: they were never API (3,792 skipped)

Verified: all 335 touched modules import under a fresh HERMES_HOME and every manifest name resolves;
the lint reports zero in-tree uses; ruff clean; targeted suites unchanged.
2026-09-03 17:13:22 -07:00

111 lines
4.1 KiB
Python

"""`hermes meet node ...` subcommand tree, wired under the ``hermes meet`` parser."""
from __future__ import annotations
import argparse
import asyncio
import json
import sys
from plugins.google_meet.node.client import NodeClient
from plugins.google_meet.node.registry import NodeRegistry
from plugins.google_meet.node.server import NodeServer
def register_cli(subparser: argparse.ArgumentParser) -> None:
"""Add ``run / list / approve / remove / status / ping`` subparsers to the ``node`` parser."""
sp = subparser.add_subparsers(dest="node_cmd", required=True)
run = sp.add_parser("run", help="Start a node server on this machine.")
run.add_argument("--host", default="0.0.0.0")
run.add_argument("--port", type=int, default=18789)
run.add_argument("--display-name", default="hermes-meet-node")
sp.add_parser("list", help="List approved remote nodes.")
app = sp.add_parser("approve", help="Register a remote node on the gateway.")
for arg in ("name", "url", "token"):
app.add_argument(arg)
for name, help_ in (("remove", "Forget a registered node."), ("status", "Ping a registered node."),
("ping", "Alias for status.")):
sp.add_parser(name, help=help_).add_argument("name")
for p in sp.choices.values():
p.set_defaults(func=node_command)
def _cmd_run(args: argparse.Namespace, reg: NodeRegistry) -> int:
server = NodeServer(host=args.host, port=args.port, display_name=args.display_name)
token = server.ensure_token()
print(f"[meet-node] display_name={server.display_name}\n"
f"[meet-node] listening on ws://{args.host}:{args.port}\n"
f"[meet-node] token (copy to gateway): {token}\n[meet-node] approve with:\n"
f" hermes meet node approve <name> ws://<host>:{args.port} {token}")
try:
asyncio.run(server.serve())
except KeyboardInterrupt:
pass
except RuntimeError as exc:
print(f"[meet-node] error: {exc}", file=sys.stderr)
return 2
return 0
def _cmd_list(args: argparse.Namespace, reg: NodeRegistry) -> int:
nodes = reg.list_all()
if not nodes:
print("no nodes registered")
for n in nodes:
print(f"{n['name']}\t{n['url']}\ttoken={n['token'][:6]}…")
return 0
def _cmd_approve(args: argparse.Namespace, reg: NodeRegistry) -> int:
reg.add(args.name, args.url, args.token)
print(f"approved node {args.name!r} at {args.url}")
return 0
def _cmd_remove(args: argparse.Namespace, reg: NodeRegistry) -> int:
ok = reg.remove(args.name)
print(f"removed {args.name!r}" if ok else f"no such node: {args.name!r}")
return 0 if ok else 1
def _cmd_ping(args: argparse.Namespace, reg: NodeRegistry) -> int:
entry = reg.get(args.name)
if entry is None:
print(f"no such node: {args.name!r}", file=sys.stderr)
return 1
try:
result = NodeClient(entry["url"], entry["token"]).ping()
except Exception as exc: # noqa: BLE001 — surface any connection error
print(json.dumps({"ok": False, "error": str(exc)}))
return 1
print(json.dumps({"ok": True, "node": args.name, **result}))
return 0
_COMMANDS = {
"run": _cmd_run,
"list": _cmd_list,
"approve": _cmd_approve,
"remove": _cmd_remove,
"status": _cmd_ping,
"ping": _cmd_ping}
def node_command(args: argparse.Namespace) -> int:
"""Dispatch for ``hermes meet node ...``; returns a process exit code."""
cmd = getattr(args, "node_cmd", None)
handler = _COMMANDS.get(cmd or "")
if handler is None:
print(f"unknown node command: {cmd!r}", file=sys.stderr)
return 2
# ``run`` never touches the registry; constructing it is side-effect free.
return handler(args, NodeRegistry())
# ---- BEGIN PLUGIN-COMPAT (revert-scheduled; see COMPAT_MANIFEST.md) ----
# Names external plugins imported from this module before the Sep 2026 decomposition.
# Internal code MUST NOT use these (scripts/check_compat_pointers.py fails CI if it does).
# The whole block is removed by reverting the commit that added it.
from typing import Any # noqa: F401,E402
# ---- END PLUGIN-COMPAT ----