The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(cli): the /cron overview and list lines live in hermes_cli/cli_cron_lines.py
Teknium71ddbb59ac62
diff --git a/gateway/session_tui_reads.py b/gateway/session_tui_reads.pyindex 6ec271e4f66..be1b243e3c1 100644--- a/gateway/session_tui_reads.py+++ b/gateway/session_tui_reads.py@@ -112,7 +112,7 @@ def _context(authority, ref, live, policy, agent, arg) -> str:def _cron(authority, ref, live, policy, agent, arg) -> str:"""The classic CLI's ``/cron`` / ``/cron list`` text (main's TUI ran it in the slash worker)."""- from hermes_cli.cli_commands_mixin import cron_list_lines, cron_overview_lines+ from hermes_cli.cli_cron_lines import cron_list_lines, cron_overview_linesmode = _cron_read(arg)lines = cron_overview_lines() if mode == 'overview' else cron_list_lines(include_disabled=mode == 'list-all')return '\n'.join(lines).strip('\n')diff --git a/hermes_cli/cli_commands_mixin.py b/hermes_cli/cli_commands_mixin.pyindex ed72f3a2c39..bf273c46da0 100644--- a/hermes_cli/cli_commands_mixin.py+++ b/hermes_cli/cli_commands_mixin.py@@ -184,60 +184,6 @@ def _cron_api(**kwargs) -> dict:return json.loads(cronjob_tool(**kwargs))-def cron_overview_lines() -> list[str]:- """Bare ``/cron``: the command card, then the current jobs. Plain text (the shared gateway serves- the same lines to a TUI session, gateway/session_tui_reads.py)."""- out = ["", "+" + "-" * 68 + "+", "|" + _t("cron.overview_title").center(68) + "|",- "+" + "-" * 68 + "+", "", f" {_t('cron.overview_commands')}",- *_lines(_t("cron.overview_usage"), pad=" "), ""]- result = _cron_api(action="list")- jobs = result.get("jobs", []) if result.get("success") else []- if not jobs:- return [*out, f" {_t('cron.no_jobs_hint')}", ""]- from hermes_cli.cron import _next_run_row- out += [f" {_t('cron.current_jobs')}", " " + "-" * 63]- for job in jobs:- out.append(f" {job['job_id'][:12]:<12} | {job['schedule']:<15} | {job.get('repeat', '?'):<8}")- if job.get("skills"):- out.append(f" {_t('cron.skills', skills=', '.join(job['skills']))}")- out.append(f" {job.get('prompt_preview', '')}")- if job.get("next_run_at"):- # A stamp parked past the scheduler grace must not read as upcoming (#114309).- label, value = _next_run_row(job)- out.append(f" {_t('cron.next_short') if label == 'Next run' else label}: {value}")- out.append("")- return [*out, ""]---def cron_list_lines(*, include_disabled: bool = False) -> list[str]:- """``/cron list [--all]``."""- result = _cron_api(action="list", include_disabled=include_disabled)- jobs = result.get("jobs", []) if result.get("success") else []- if not jobs:- return [_t("cron.no_jobs")]- from hermes_cli.cron import _next_run_row- out = ["", _t("cron.list_header"), "-" * 80]- for job in jobs:- out += [f" {_t('cron.id', job_id=job['job_id'])}", f" {_t('cron.name', name=job['name'])}",- f" {_t('cron.state', state=job.get('state', '?'))}",- f" {_t('cron.schedule_repeat', schedule=job['schedule'], repeat=job.get('repeat', '?'))}",- " {}: {}".format(*_next_run_row(job)) if job.get("next_run_at") else f" {_t('cron.next_run_na')}"]- if job.get("skills"):- out.append(f" {_t('cron.skills', skills=', '.join(job['skills']))}")- out.append(f" {_t('cron.prompt', prompt=job.get('prompt_preview', ''))}")- if job.get("last_run_at"):- status = job.get("last_status") or "?"- # delivery_failed: the run succeeded but delivery didn't — the reason lives- # in last_delivery_error (last_error is None).- if status == "delivery_failed" and job.get("last_delivery_error"):- status = _t("cron.status_delivery_failed", error=job["last_delivery_error"])- elif status == "error" and job.get("last_error"):- status = _t("cron.status_error", error=job["last_error"])- out.append(f" {_t('cron.last_run', when=job['last_run_at'], status=status)}")- out.append("")- return out--def _normalize_skills(values) -> list:"""Strip, drop empties, and dedupe (order-preserving)."""normalized = []@@ -1432,9 +1378,11 @@ class CLICommandsMixin(CLICommandsSessionToolsMixin):getattr(self, handler)(subcommand, opts)def _cron_overview(self) -> None:+ from hermes_cli.cli_cron_lines import cron_overview_lines_pr(*cron_overview_lines())def _cron_list(self, subcommand: str, opts: dict) -> None:+ from hermes_cli.cli_cron_lines import cron_list_lines_pr(*cron_list_lines(include_disabled=opts["all"]))def _cron_add(self, subcommand: str, opts: dict) -> None:diff --git a/hermes_cli/cli_cron_lines.py b/hermes_cli/cli_cron_lines.pynew file mode 100644index 00000000000..eb2a46211f6--- /dev/null+++ b/hermes_cli/cli_cron_lines.py@@ -0,0 +1,68 @@+"""The classic CLI's `/cron` overview and list as plain lines.++Shared by the classic CLI (`CLICommandsMixin._cron_overview` / `_cron_list`) and the shared gateway, which serves the+same lines to a TUI session (gateway/session_tui_reads.py).+"""+from __future__ import annotations++from hermes_cli.cli_commands_session_tools import _lines, _t+++def _cron(**kwargs) -> dict:+ # Looked up on the mixin module at call time so tests that patch `cli_commands_mixin._cron_api` still apply.+ from hermes_cli import cli_commands_mixin+ return cli_commands_mixin._cron_api(**kwargs)+++def cron_overview_lines() -> list[str]:+ """Bare ``/cron``: the command card, then the current jobs. Plain text (the shared gateway serves+ the same lines to a TUI session, gateway/session_tui_reads.py)."""+ out = ["", "+" + "-" * 68 + "+", "|" + _t("cron.overview_title").center(68) + "|",+ "+" + "-" * 68 + "+", "", f" {_t('cron.overview_commands')}",+ *_lines(_t("cron.overview_usage"), pad=" "), ""]+ result = _cron(action="list")+ jobs = result.get("jobs", []) if result.get("success") else []+ if not jobs:+ return [*out, f" {_t('cron.no_jobs_hint')}", ""]+ from hermes_cli.cron import _next_run_row+ out += [f" {_t('cron.current_jobs')}", " " + "-" * 63]+ for job in jobs:+ out.append(f" {job['job_id'][:12]:<12} | {job['schedule']:<15} | {job.get('repeat', '?'):<8}")+ if job.get("skills"):+ out.append(f" {_t('cron.skills', skills=', '.join(job['skills']))}")+ out.append(f" {job.get('prompt_preview', '')}")+ if job.get("next_run_at"):+ # A stamp parked past the scheduler grace must not read as upcoming (#114309).+ label, value = _next_run_row(job)+ out.append(f" {_t('cron.next_short') if label == 'Next run' else label}: {value}")+ out.append("")+ return [*out, ""]+++def cron_list_lines(*, include_disabled: bool = False) -> list[str]:+ """``/cron list [--all]``."""+ result = _cron(action="list", include_disabled=include_disabled)+ jobs = result.get("jobs", []) if result.get("success") else []+ if not jobs:+ return [_t("cron.no_jobs")]+ from hermes_cli.cron import _next_run_row+ out = ["", _t("cron.list_header"), "-" * 80]+ for job in jobs:+ out += [f" {_t('cron.id', job_id=job['job_id'])}", f" {_t('cron.name', name=job['name'])}",+ f" {_t('cron.state', state=job.get('state', '?'))}",+ f" {_t('cron.schedule_repeat', schedule=job['schedule'], repeat=job.get('repeat', '?'))}",+ " {}: {}".format(*_next_run_row(job)) if job.get("next_run_at") else f" {_t('cron.next_run_na')}"]+ if job.get("skills"):+ out.append(f" {_t('cron.skills', skills=', '.join(job['skills']))}")+ out.append(f" {_t('cron.prompt', prompt=job.get('prompt_preview', ''))}")+ if job.get("last_run_at"):+ status = job.get("last_status") or "?"+ # delivery_failed: the run succeeded but delivery didn't — the reason lives+ # in last_delivery_error (last_error is None).+ if status == "delivery_failed" and job.get("last_delivery_error"):+ status = _t("cron.status_delivery_failed", error=job["last_delivery_error"])+ elif status == "error" and job.get("last_error"):+ status = _t("cron.status_error", error=job["last_error"])+ out.append(f" {_t('cron.last_run', when=job['last_run_at'], status=status)}")+ out.append("")+ return out