debug.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. """``hermes debug`` subcommand parser."""
  2. from __future__ import annotations
  3. import argparse
  4. from typing import Callable
  5. def build_debug_parser(subparsers, *, cmd_debug: Callable) -> None:
  6. """Attach the ``debug`` subcommand to ``subparsers``."""
  7. debug_parser = subparsers.add_parser(
  8. "debug", help="Debug tools — upload logs and system info for support",
  9. description="Debug utilities for Hermes Agent. Use 'hermes debug share' to "
  10. "upload a debug report (system info + recent logs) to a paste "
  11. "service and get a shareable URL.",
  12. formatter_class=argparse.RawDescriptionHelpFormatter,
  13. epilog="""\
  14. Examples:
  15. hermes debug share Upload debug report (asks for confirmation)
  16. hermes debug share --yes Skip confirmation (for scripts/CI)
  17. hermes debug share --lines 500 Include more log lines
  18. hermes debug share --expire 30 Keep dpaste.com fallback pastes for 30 days
  19. hermes debug share --local Print report locally (no upload)
  20. hermes debug share --no-redact Disable upload-time secret redaction
  21. hermes debug share --nous Upload to Nous-internal storage (private)
  22. hermes debug delete <url> Delete a previously uploaded paste
  23. """)
  24. debug_sub = debug_parser.add_subparsers(dest="debug_command")
  25. share_parser = debug_sub.add_parser(
  26. "share", help="Upload debug report to a paste service and print a shareable URL")
  27. share_parser.add_argument(
  28. "--lines", type=int, default=200,
  29. help="Number of log lines to include per log file (default: 200)")
  30. share_parser.add_argument(
  31. "--expire", type=int, default=1,
  32. help="dpaste.com fallback retention in days (minimum 1; default: 1). "
  33. "paste.rs pastes are always deleted after 6 hours, but if the "
  34. "upload falls back to dpaste.com the pastes live for this many "
  35. "days and cannot be deleted.")
  36. share_parser.add_argument(
  37. "--local", action="store_true", help="Print the report locally instead of uploading")
  38. share_parser.add_argument(
  39. "-y", "--yes", action="store_true",
  40. help="Skip the confirmation prompt and upload immediately. Required "
  41. "in non-interactive contexts (scripts/CI); without it, and with "
  42. "no TTY on stdin, the command refuses rather than upload silently.")
  43. share_parser.add_argument(
  44. "--no-redact", action="store_true",
  45. help="Disable upload-time secret redaction (default: redact). Logs "
  46. "are normally run through agent.redact.redact_sensitive_text "
  47. "with force=True before upload so credentials are not leaked "
  48. "into the public paste service.")
  49. share_parser.add_argument(
  50. "--nous", action="store_true",
  51. help="Upload the debug bundle to Nous-internal storage (AWS S3) instead "
  52. "of a public paste service. The bundle is private — viewable only "
  53. "by Nous staff (and allowlisted Discord mods) via a Google-login-"
  54. "gated viewer — and auto-deletes after 14 days. Still force-redacts "
  55. "secrets unless --no-redact is also passed.")
  56. delete_parser = debug_sub.add_parser(
  57. "delete", help="Delete a paste uploaded by 'hermes debug share'")
  58. delete_parser.add_argument(
  59. "urls", nargs="*", default=[],
  60. help="One or more paste URLs to delete (e.g. https://paste.rs/abc123)")
  61. debug_parser.set_defaults(func=cmd_debug)