Skip to content

The agent that grows with you

fix(cli): keep GatewayChatView.run under its complexity cap; BOM-tolerant parity reads

Teknium7640528eae16
diff --git a/hermes_cli/gateway_chat_view.py b/hermes_cli/gateway_chat_view.py
index 2608d6f896d..c0bd7f690a7 100644
--- a/hermes_cli/gateway_chat_view.py
+++ b/hermes_cli/gateway_chat_view.py
@@ -342,6 +342,13 @@ class GatewayChatView:
logger.debug("settled result for %s unavailable: %s", admission, exc)
return {}
+ def _print_exit_ids(self):
+ """The finite run's durable id on stderr (automation wrappers parse it; it names the
+ physical row a compaction may have advanced) and, for `chat -q`, main's resume block."""
+ print(f"\nsession_id: {self.session_id}", file=sys.stderr, flush=True)
+ if self.resume_footer:
+ print(resume_footer(self.session_id), flush=True)
+
def _write_usage_file(self, result, outcome):
"""``-z --usage-file``: the same JSON ledger the in-process one-shot wrote."""
from hermes_cli.oneshot import _write_usage_file
@@ -406,9 +413,7 @@ class GatewayChatView:
# Same stderr exit contract as the legacy -Q path: automation wrappers read the
# durable id from this line, and it names the physical row (a compaction may have
# advanced it past the row printed at start).
- print(f"\nsession_id: {self.session_id}", file=sys.stderr, flush=True)
- if self.resume_footer:
- print(resume_footer(self.session_id), flush=True)
+ self._print_exit_ids()
return exit_code
from prompt_toolkit import PromptSession
from prompt_toolkit.patch_stdout import patch_stdout
diff --git a/scripts/gen_gateway_command_parity.py b/scripts/gen_gateway_command_parity.py
index 3ccc64f0833..710a96404a5 100755
--- a/scripts/gen_gateway_command_parity.py
+++ b/scripts/gen_gateway_command_parity.py
@@ -94,7 +94,7 @@ def _ink_commands():
"""``{name_or_alias: (canonical_ink_name, block_text)}`` from the static Ink tables."""
table = {}
for path in sorted((ROOT / "ui-tui" / "src" / "app" / "slash" / "commands").glob("*.ts")):
- text = path.read_text(encoding="utf-8")
+ text = path.read_text(encoding="utf-8-sig")
for block in re.split(r"\n \{\n", text)[1:]:
block = block.split("\n },", 1)[0]
match = re.search(r"^ name: '([\w-]+)'", block, re.MULTILINE)
@@ -132,7 +132,7 @@ def _rpc_cell(methods, served):
def _desktop_specs():
- text = (ROOT / "apps" / "desktop" / "src" / "lib" / "desktop-slash-commands.ts").read_text(encoding="utf-8")
+ text = (ROOT / "apps" / "desktop" / "src" / "lib" / "desktop-slash-commands.ts").read_text(encoding="utf-8-sig")
body = text.split("const DESKTOP_COMMAND_SPECS", 1)[1].split("\n]\n", 1)[0]
specs = {}
for chunk in re.split(r"\n \{", body)[1:]:
@@ -213,7 +213,7 @@ def render() -> str:
def check(out: Path = OUT) -> int:
- committed = out.read_text(encoding="utf-8") if out.exists() else ""
+ committed = out.read_text(encoding="utf-8-sig") if out.exists() else ""
if committed == render():
return 0
print(f"{out.relative_to(ROOT)} is stale; run scripts/gen_gateway_command_parity.py", file=sys.stderr)