migrate.py 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. """``hermes migrate`` subcommand parser."""
  2. from __future__ import annotations
  3. def build_migrate_parser(subparsers) -> None:
  4. """Attach the ``migrate`` subcommand to ``subparsers``."""
  5. from hermes_cli.migrate import cmd_migrate, cmd_migrate_xai
  6. migrate_parser = subparsers.add_parser(
  7. "migrate", help="Move over from another agent, or migrate retired models and deprecated settings",
  8. description="With no type: find another agent's setup on this computer (OpenClaw, Claude Code, "
  9. "Codex CLI, Cursor, Grok Bot, OpenBot) and offer to import it. Name an agent to import from it; "
  10. "xai and relay rewrite deprecated settings in the active config.yaml.")
  11. migrate_subparsers = migrate_parser.add_subparsers(dest="migrate_type")
  12. migrate_xai = migrate_subparsers.add_parser(
  13. "xai", help="Migrate xAI models scheduled for retirement on May 15, 2026",
  14. description="Scan config.yaml for references to xAI models retiring on "
  15. "May 15, 2026 and, with --apply, rewrite them in-place to the "
  16. "official replacements per the xAI migration guide. The original "
  17. "config.yaml is backed up before any rewrite.")
  18. migrate_xai.add_argument(
  19. "--apply", action="store_true",
  20. help="Rewrite config.yaml in-place (default: dry-run, no writes)")
  21. migrate_xai.add_argument(
  22. "--no-backup", action="store_true",
  23. help="Skip the timestamped backup of config.yaml when applying")
  24. migrate_xai.set_defaults(func=cmd_migrate_xai)
  25. migrate_relay = migrate_subparsers.add_parser(
  26. "relay", help="Convert legacy HERMES_NEMO_RELAY_ATIF_*/ATOF_* exporter vars into relay-plugins.toml",
  27. description="The NeMo Relay cutover stopped reading the legacy exporter variables. Generate "
  28. "<hermes home>/relay-plugins.toml from them, point HERMES_NEMO_RELAY_PLUGINS_TOML at it, "
  29. "and comment the legacy lines out. `hermes update` runs this for every profile automatically.")
  30. migrate_relay.add_argument(
  31. "--all-profiles", action="store_true",
  32. help="Migrate the default home and every named profile (what `hermes update` does)")
  33. migrate_relay.add_argument(
  34. "--no-validate", action="store_true",
  35. help="Skip activating the generated file through Relay's validator before writing it")
  36. migrate_relay.set_defaults(func=_cmd_migrate_relay)
  37. _add_agent_import_parsers(migrate_subparsers)
  38. migrate_parser.set_defaults(func=cmd_migrate)
  39. def _add_agent_import_parsers(migrate_subparsers) -> None:
  40. """``hermes migrate <agent>``: one per importer setup offers; runs the agent-importers plugin's
  41. ``hermes import-agent <agent>`` (installing the plugin first when it is missing)."""
  42. from hermes_cli.migrate import cmd_migrate_agent
  43. from hermes_cli.setup_agent_import import IMPORT_SOURCES
  44. for source in IMPORT_SOURCES:
  45. sub = migrate_subparsers.add_parser(
  46. source.name, help=f"Import your {source.label} setup into Hermes",
  47. description=f"Import your {source.label} setup into the active profile through the "
  48. "agent-importers plugin (installed from the plugin catalog when missing). Always "
  49. "previews first and asks before changing anything.")
  50. sub.add_argument("--source", help="Where the agent's setup (or, for Grok Bot, its export file) is")
  51. sub.add_argument("--dry-run", action="store_true", help="Preview only")
  52. sub.add_argument("--overwrite", action="store_true", help="Replace existing items on name conflicts")
  53. sub.add_argument("-y", "--yes", action="store_true", help="Skip the confirmation prompt")
  54. if source.name == "openclaw":
  55. sub.add_argument("--migrate-secrets", action="store_true",
  56. help="Also import OpenClaw's allowlisted API keys and bot tokens")
  57. if source.name in ("grok-bot", "openbot"):
  58. sub.add_argument("--activate-routines", action="store_true",
  59. help="Create the imported cron jobs running instead of paused")
  60. sub.add_argument("--bot", action="append", metavar="NAME",
  61. help="Only this Bot or agent, by name (repeatable)")
  62. sub.set_defaults(func=cmd_migrate_agent, migrate_agent=source.name)
  63. def _cmd_migrate_relay(args) -> None:
  64. from hermes_cli.relay_plugin_migrate import cmd_migrate_relay
  65. cmd_migrate_relay(args)