§
    ‰eîiz!  ã                  óp   — d Z ddlmZ ddlZddlZddlZddlmZmZ ddl	m
Z
 	 	 ddd„Z	 	 ddd„Zddd„ZdS )uá  Oneshot (-z) mode: send a prompt, get the final content block, exit.

Bypasses cli.py entirely.  No banner, no spinner, no session_id line,
no stderr chatter.  Just the agent's final text to stdout.

Toolsets = whatever the user has configured for "cli" in `hermes tools`.
Rules / memory / AGENTS.md / preloaded skills = same as a normal chat turn.
Approvals = auto-bypassed (HERMES_YOLO_MODE=1 is set for the call).
Working directory = the user's CWD (AGENTS.md etc. resolve from there as usual).

Model / provider selection mirrors `hermes chat`:
    - Both optional. If omitted, use the user's configured default.
    - If both given, pair them exactly as given.
    - If only --model given, auto-detect the provider that serves it.
    - If only --provider given, error out (ambiguous â€” caller must pick a model).

Env var fallbacks (used when the corresponding arg is not passed):
    - HERMES_INFERENCE_MODEL
    - HERMES_INFERENCE_PROVIDER  (already read by resolve_runtime_provider)
é    )ÚannotationsN)Úredirect_stderrÚredirect_stdout)ÚOptionalÚpromptÚstrÚmodelúOptional[str]ÚproviderÚreturnÚintc                óš  — t          j        t           j        ¦  «         t          j        dd¦  «                             ¦   «         }|r9|pd                     ¦   «         s#|s!t          j                             d¦  «         dS dt          j	        d<   dt          j	        d<   t          j
        }t          t          j        d¦  «        }	 t          |¦  «        5  t          |¦  «        5  t          | ||¬	¦  «        }d
d
d
¦  «         n# 1 swxY w Y   d
d
d
¦  «         n# 1 swxY w Y   	 |                     ¦   «          n:# t"          $ r Y n.w xY w# 	 |                     ¦   «          w # t"          $ r Y w w xY wxY w|rS|                     |¦  «         |                     d¦  «        s|                     d¦  «         |                     ¦   «          dS )aù  Execute a single prompt and print only the final content block.

    Args:
        prompt: The user message to send.
        model: Optional model override. Falls back to HERMES_INFERENCE_MODEL
            env var, then config.yaml's model.default / model.model.
        provider: Optional provider override. Falls back to
            HERMES_INFERENCE_PROVIDER env var, then config.yaml's model.provider,
            then "auto".

    Returns the exit code.  Caller should sys.exit() with the return.
    ÚHERMES_INFERENCE_MODELÚ z†hermes -z: --provider requires --model (or HERMES_INFERENCE_MODEL). Pass both explicitly, or neither to use your configured defaults.
é   Ú1ÚHERMES_YOLO_MODEÚHERMES_ACCEPT_HOOKSÚw)r	   r   NÚ
r   )ÚloggingÚdisableÚCRITICALÚosÚgetenvÚstripÚsysÚstderrÚwriteÚenvironÚstdoutÚopenÚdevnullr   r   Ú
_run_agentÚcloseÚ	ExceptionÚendswithÚflush)r   r	   r   Úenv_model_earlyÚreal_stdoutr#   Úresponses          ú4/home/div/.hermes/hermes-agent/hermes_cli/oneshot.pyÚrun_oneshotr-      s…  € õ, „O•GÔ$Ñ%Ô%Ð%õ ”iÐ 8¸"Ñ=Ô=×CÒCÑEÔE€OØð ˜%˜+ 2×,Ò,Ñ.Ô.ð °/ð ÝŒ
×ÒðRñ	
ô 	
ð 	
ð ˆqð &)…B„JÐ!Ñ"Ø(+…B„JÐ$Ñ%õ ”*€KÝ•2”:˜sÑ#Ô#€GðÝ˜WÑ%Ô%ð 	Jð 	J¥°wÑ'?Ô'?ð 	Jð 	JÝ! &°ÀÐIÑIÔIˆHð	Jð 	Jð 	Jñ 	Jô 	Jð 	Jð 	Jð 	Jð 	Jð 	Jð 	Jøøøð 	Jð 	Jð 	Jð 	Jð 	Jð 	Jð 	Jñ 	Jô 	Jð 	Jð 	Jð 	Jð 	Jð 	Jð 	Jøøøð 	Jð 	Jð 	Jð 	Jð	Ø�MŠM‰OŒOˆOˆOøÝð 	ð 	ð 	ØˆDð	øøøøð	Ø�MŠM‰OŒOˆOˆOøÝð 	ð 	ð 	ØˆDð	øøøøøøð ð Ø×Ò˜(Ñ#Ô#Ð#Ø× Ò  Ñ&Ô&ð 	$Ø×Ò˜dÑ#Ô#Ð#Ø×ÒÑÔÐØˆ1sŠ   ÃE ÃDÃ%DÃ8DÄD	ÄDÄD	ÄDÄE ÄDÄE Ä"DÄ#E Ä'D< Ä<
E	ÅE	ÅE3ÅE#Å"E3Å#
E0Å-E3Å/E0Å0E3c                óò  — ddl m} ddlm} ddlm} ddlm} ddlm	}  |¦   «         }| 
                    d¦  «        pi }	t          |	t          ¦  «        r|	}
n,|	 
                    d¦  «        p|	 
                    d¦  «        pd	}
t          j        d
d	¦  «                             ¦   «         }|pd	                     ¦   «         p|p|
}|pd	                     ¦   «         pd}|€Í|s|rÉ|pd	                     ¦   «         p|}|r¯d	}t          |	t           ¦  «        rHt          |	 
                    d¦  «        pd	¦  «                             ¦   «                              ¦   «         }|p:t          j        dd	¦  «                             ¦   «                              ¦   «         pd} |||¦  «        }|r|\  }} |||pd¬¦  «        }t%           ||d¦  «        ¦  «        } || 
                    d¦  «        | 
                    d¦  «        | 
                    d¦  «        | 
                    d¦  «        ||dd| 
                    d¦  «        t&          ¬¦
  «
        }d|_        d|_        d|_        |                     | ¦  «        pd	S )zƒBuild an AIAgent exactly like a normal CLI chat turn would, then
    run a single conversation.  Returns the final response string.r   )Úload_config)Údetect_provider_for_model)Úresolve_runtime_provider)Ú_get_platform_tools)ÚAIAgentr	   Údefaultr   r   Nr   ÚHERMES_INFERENCE_PROVIDERÚauto)Ú	requestedÚtarget_modelÚcliÚapi_keyÚbase_urlÚapi_modeTÚcredential_pool)
r:   r;   r   r<   r	   Úenabled_toolsetsÚ
quiet_modeÚplatformr=   Úclarify_callback)Úhermes_cli.configr/   Úhermes_cli.modelsr0   Úhermes_cli.runtime_providerr1   Úhermes_cli.tools_configr2   Ú	run_agentr3   ÚgetÚ
isinstancer   r   r   r   ÚdictÚlowerÚsortedÚ_oneshot_clarify_callbackÚsuppress_status_outputÚstream_delta_callbackÚtool_gen_callbackÚchat)r   r	   r   r/   r0   r1   r2   r3   ÚcfgÚ	model_cfgÚ	cfg_modelÚ	env_modelÚeffective_modelÚeffective_providerÚexplicit_modelÚcfg_providerÚcurrent_providerÚdetectedÚruntimeÚtoolsets_listÚagents                        r,   r$   r$   _   sæ  € ð .Ð-Ð-Ð-Ð-Ð-Ø;Ð;Ð;Ð;Ð;Ð;ØDÐDÐDÐDÐDÐDØ;Ð;Ð;Ð;Ð;Ð;Ø!Ð!Ð!Ð!Ð!Ð!à
ˆ+‰-Œ-€Cð —’˜Ñ Ô Ð& B€IÝ�)�SÑ!Ô!ð MØˆ	ˆ	à—M’M )Ñ,Ô,ÐL°	·²¸gÑ0FÔ0FÐLÈ"ˆ	å”	Ð2°BÑ7Ô7×=Ò=Ñ?Ô?€IØ�{ ×)Ò)Ñ+Ô+ÐE¨yÐE¸I€Oð #˜. b×/Ò/Ñ1Ô1Ð9°TÐØÐ! uÐ!°	Ð!ð  ˜+ 2×,Ò,Ñ.Ô.Ð;°)ˆØð 	?ØˆLÝ˜)¥TÑ*Ô*ð TÝ" 9§=¢=°Ñ#<Ô#<Ð#BÀÑCÔC×IÒIÑKÔK×QÒQÑSÔS�àð Ý”9Ð8¸"Ñ=Ô=×CÒCÑEÔE×KÒKÑMÔMðàð ð
 1Ð0°ÐAQÑRÔRˆHØð ?Ø6>Ñ3Ð" Oà&Ð&Ø$Ø$Ð,¨ðñ ô €Gõ Ð.Ð.¨s°EÑ:Ô:Ñ;Ô;€MàˆGØ—’˜IÑ&Ô&Ø—’˜ZÑ(Ô(Ø—’˜ZÑ(Ô(Ø—’˜ZÑ(Ô(ØØ&ØØØŸšÐ$5Ñ6Ô6õ 3ð+ñ ô €Eð4 $(€EÔ Ø"&€EÔØ"€EÔà�:Š:�fÑÔÐ# Ð#ó    Úquestionc                ó   — |rd|› d�S 	 dS )uy   Clarify is disabled in oneshot mode â€” tell the agent to pick a
    default and proceed instead of stalling or erroring.z<[oneshot mode: no user available. Pick the best option from z' using your own judgment and continue.]z\[oneshot mode: no user available. Make the most reasonable assumption you can and continue.]© )r_   Úchoicess     r,   rL   rL   ¿   s;   € ð ð 
ð@Øð@ð @ð @ð	
ð
	,ðð r^   )NN)r   r   r	   r
   r   r
   r   r   )r   r   r	   r
   r   r
   r   r   )N)r_   r   r   r   )Ú__doc__Ú
__future__r   r   r   r   Ú
contextlibr   r   Útypingr   r-   r$   rL   ra   r^   r,   ú<module>rg      sÔ   ððð ð* #Ð "Ð "Ð "Ð "Ð "à €€€Ø 	€	€	€	Ø 
€
€
€
Ø 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ø Ð Ð Ð Ð Ð ð
  Ø"ð=ð =ð =ð =ð =ðD  Ø"ð]$ð ]$ð ]$ð ]$ð ]$ð@ð ð ð ð ð ð r^   