refactor(cli): dedupe the 3x --oneshot dispatch block and chat-arg defaults into helpers

_run_oneshot_from_args replaces three identical confirm+run_and_exit blocks
(main, fast chat, Termux fast cli); _default_to_chat reuses the existing
_set_chat_arg_defaults instead of a second attr table. Also restores the
'bare hermes profile' note as _profile_status's docstring.
This commit is contained in:
Teknium
2026-09-02 11:58:59 -07:00
parent ed8aa5e3e4
commit 64f301dfc0
2 changed files with 23 additions and 43 deletions
+22 -43
View File
@@ -11815,6 +11815,7 @@ def _guard_noninteractive_user_config(args) -> None:
def _set_chat_arg_defaults(args) -> None:
"""Fill the chat-parser attrs cmd_chat reads when chat was not parsed."""
for attr, default in [
("query", None),
("model", None),
@@ -11829,6 +11830,22 @@ def _set_chat_arg_defaults(args) -> None:
setattr(args, attr, default)
def _run_oneshot_from_args(args) -> None:
"""Top-level --oneshot / -z: single-shot mode, stdout = final response only.
Bypasses cli.py entirely; _run_and_exit_oneshot never returns.
"""
_confirm_startup_expensive_model_override(args)
_run_and_exit_oneshot(
args.oneshot,
model=getattr(args, "model", None),
provider=getattr(args, "provider", None),
toolsets=getattr(args, "toolsets", None),
skills=getattr(args, "skills", None),
usage_file=getattr(args, "usage_file", None),
)
def _try_fast_serve_launch() -> bool:
"""Dispatch an unambiguous built-in ``serve`` without the full CLI tree.
@@ -11927,15 +11944,7 @@ def _try_fast_chat_launch() -> bool:
_prepare_agent_startup(args)
if getattr(args, "oneshot", None):
_confirm_startup_expensive_model_override(args)
_run_and_exit_oneshot(
args.oneshot,
model=getattr(args, "model", None),
provider=getattr(args, "provider", None),
toolsets=getattr(args, "toolsets", None),
skills=getattr(args, "skills", None),
usage_file=getattr(args, "usage_file", None),
)
_run_oneshot_from_args(args)
if (args.resume or args.continue_last) and args.command is None:
args.command = "chat"
@@ -11985,15 +11994,7 @@ def _try_termux_fast_cli_launch() -> bool:
if getattr(args, "oneshot", None):
_prepare_agent_startup(args)
_confirm_startup_expensive_model_override(args)
_run_and_exit_oneshot(
args.oneshot,
model=getattr(args, "model", None),
provider=getattr(args, "provider", None),
toolsets=getattr(args, "toolsets", None),
skills=getattr(args, "skills", None),
usage_file=getattr(args, "usage_file", None),
)
_run_oneshot_from_args(args)
if (args.resume or args.continue_last) and args.command is None:
args.command = "chat"
@@ -12577,22 +12578,10 @@ def _parse_cli_args(parser, subparsers, argv):
def _default_to_chat(args) -> None:
"""No subcommand given: run chat, filling the chat-parser attrs it expects."""
# Top-level --resume / --continue is a shortcut to chat.
"""No subcommand given: run chat (top-level --resume/--continue is a chat shortcut)."""
if args.resume or args.continue_last:
args.command = "chat"
for attr, default in [
("query", None),
("model", None),
("provider", None),
("toolsets", None),
("verbose", None),
("resume", None),
("continue_last", None),
("worktree", False),
]:
if not hasattr(args, attr):
setattr(args, attr, default)
_set_chat_arg_defaults(args)
cmd_chat(args)
@@ -12704,18 +12693,8 @@ def main():
# trigger consent prompts for hooks the user is still inspecting.
_prepare_agent_startup(args)
# Handle top-level --oneshot / -z: single-shot mode, stdout = final
# response only, nothing else. Bypasses cli.py entirely.
if getattr(args, "oneshot", None):
_confirm_startup_expensive_model_override(args)
_run_and_exit_oneshot(
args.oneshot,
model=getattr(args, "model", None),
provider=getattr(args, "provider", None),
toolsets=getattr(args, "toolsets", None),
skills=getattr(args, "skills", None),
usage_file=getattr(args, "usage_file", None),
)
_run_oneshot_from_args(args)
# No subcommand (optionally with top-level --resume / --continue) → chat.
if args.command is None:
+1
View File
@@ -82,6 +82,7 @@ def _render_distribution_plan(plan) -> None:
def _profile_status(args):
"""Bare ``hermes profile`` — show current profile status."""
from hermes_constants import display_hermes_home
from hermes_cli.profiles import (
get_active_profile_name,