The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(hermes_cli): debug._capture_dump via contextlib; container_boot argv probe as one loop
Tekniuma4daa0b78041
diff --git a/hermes_cli/container_boot.py b/hermes_cli/container_boot.pyindex 9348aae6434..038ff5bf888 100644--- a/hermes_cli/container_boot.py+++ b/hermes_cli/container_boot.py@@ -179,26 +179,22 @@ def _read_container_argv() -> tuple[str, ...]:``s6-svscan`` and the real command lives on another PID, so after the PID 1 fast path wescan ``/proc/*/cmdline`` for a process whose argv contains ``main-wrapper.sh``."""- try:- argv = _cmdline_argv(Path("/proc/1/cmdline"))+ def _cmdlines():+ yield Path("/proc/1/cmdline")+ try:+ for entry in Path("/proc").iterdir():+ if entry.name.isdigit():+ yield entry / "cmdline"+ except OSError:+ return++ for cmdline in _cmdlines():+ try:+ argv = _cmdline_argv(cmdline)+ except OSError:+ continueif any("main-wrapper.sh" in part for part in argv):return argv- except OSError:- pass-- try:- for entry in Path("/proc").iterdir():- if not entry.name.isdigit():- continue- try:- argv = _cmdline_argv(entry / "cmdline")- except OSError:- continue- if any("main-wrapper.sh" in part for part in argv):- return argv- except OSError:- pass-return ()diff --git a/hermes_cli/debug.py b/hermes_cli/debug.pyindex 64447bfbcb1..420eb225dcb 100644--- a/hermes_cli/debug.py+++ b/hermes_cli/debug.py@@ -1,5 +1,6 @@"""``hermes debug`` debug tools for Hermes Agent."""+import contextlibimport datetimeimport gzipimport io@@ -11,6 +12,7 @@ import timeimport urllib.requestfrom dataclasses import dataclassfrom pathlib import Path+from types import SimpleNamespacefrom typing import Optionalfrom hermes_constants import get_hermes_home@@ -396,19 +398,9 @@ def _capture_default_log_snapshots(def _capture_dump() -> str:"""Run ``hermes dump`` and return its stdout as a string."""from hermes_cli.dump import run_dump-- class _FakeArgs:- show_keys = False-- old_stdout = sys.stdout- sys.stdout = capture = io.StringIO()- try:- run_dump(_FakeArgs())- except SystemExit:- pass- finally:- sys.stdout = old_stdout-+ capture = io.StringIO()+ with contextlib.redirect_stdout(capture), contextlib.suppress(SystemExit):+ run_dump(SimpleNamespace(show_keys=False))return capture.getvalue()@@ -448,9 +440,8 @@ def collect_debug_report(buf.write("\n")for name in _REPORT_LOGS:- buf.write(f"\n--- {name}.log (last {_tail_budget(name, log_lines)} lines) ---\n")- buf.write(log_snapshots[name].tail_text)- buf.write("\n")+ buf.write(f"\n--- {name}.log (last {_tail_budget(name, log_lines)} lines) ---\n"+ f"{log_snapshots[name].tail_text}\n")return buf.getvalue()