+
    iHàjß'  ã                  óä   € R t ^ RIHt ^ RIt^ RIt^ RIHt ^ RIHtH	t	H
t
Ht ^ RIHt ]P                  ! R4      t] ! R R4      4       tR	 R
 ltR R ltR R lt^tR R ltR R ltR R ltR# )a¬  Text-response stop gates for the conversation turn loop.

When the model stops with a text answer, four gates may instead append the answer as an
interim row plus a user-role nudge and continue the turn: late language-server verdicts on this
turn's edits (a durable row, see ``_late_lsp_verdicts``), verify-on-stop (#65919),
the ``pre_verify`` plugin hook after code edits, and the kanban worker terminal-tool guard.
Each keeps the candidate answer as a budget-exhaustion fallback
(``pending_verification_response``) and clears ``final_response`` so the finalizer can tell
this gate from error exits (#61631). Nothing here imports ``agent.conversation_loop`` at
module level (cycle).
)ÚannotationsN)Ú	dataclass)ÚAnyÚDictÚListÚOptional)Úappend_messagezagent.conversation_loopc                  óD   € ] tR t^t$ RtR]R&   R]R&   R]R&   R]R&   RtR	# )
ÚStopGateVerdictu‘   ``continue_turn`` True â†’ a nudge was appended; re-enter the turn loop with
``final_response=None`` and the pending-verification fields updated.ÚboolÚcontinue_turnr   Úfinal_responseÚpending_verification_responseÚ'pending_verification_response_previewed© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__Ú__static_attributes__r   ó    Ú:/home/ubuntu/.hermes/hermes-agent/agent/turn_stop_gates.pyr
   r
      s"   ‡ ñLð ÓØÓØ#&Ó&Ø-0×0r   r
   c               ó   € V ^8„  d   QhRR/# ©é   ÚreturnúOptional[str]r   )Úformats   "r   Ú__annotate__r    $   s   € ÷ ñ  Mñ r   c           	     óî   €  ^ RI HpHp V! 4       '       d5   V! \        V RR4      \        V R\	        4       4      \        V R^ 4      R7      #  R#   \
         d    \        P                  RRR	7        R# i ; i)
é    )Úbuild_verify_on_stop_nudgeÚverify_on_stop_enabledÚ
session_idNÚ_turn_file_mutation_pathsÚ_verification_stop_nudges)r%   Úchanged_pathsÚattemptsz#verification stop-loop check failedT©Úexc_info)Úagent.verification_stopr#   r$   ÚgetattrÚsetÚ	ExceptionÚloggerÚdebug)Úagentr#   r$   s   &  r   Ú_verify_on_stop_nudger3   $   s~   € ðK÷	
ñ "×#Ò#Ù-Ü" 5¨,¸Ó=Ü% eÐ-HÌ#Ë%ÓPÜ  Ð(CÀQÓGôð ð $ñ øô ô KÜ�‰Ð:ÀTˆÕJÙðKús   ‚A —3A Á"A4Á3A4c               ó    € V ^8„  d   QhRRRR/# )r   ÚattemptÚintr   r   r   )r   s   "r   r    r    5   s   € ÷ ñ °cð ¸mñ r   c           
     ó0  € \        \        V R\        4       4      ;'       g    . 4      p ^ RIHp ^ RIHp ^ RIHp V'       dª   V! R4      '       dœ   W$! 4       8  d‘   \        V RR4      pVf4   ^ RI	H
p \        T! \        V R	R
4      ;'       g    R
R7      4      pWpn        T! \        V RR4      ;'       g    R
\        V R	R
4      ;'       g    R
\        V RR
4      ;'       g    R
WrWR7      # R#   \         d    \        P                  RRR7        R# i ; i)zwAfter code edits a registered ``pre_verify`` hook may keep the agent going one
more turn; no default continuation cost.r&   )Úmax_verify_nudges)Úhas_hook)Úget_pre_verify_continue_messageÚ
pre_verifyÚ_resolved_is_codingN)Úis_coding_contextÚplatformÚ )r>   r%   Úmodel)r%   r>   r@   Úcodingr5   r   r(   zpre_verify hook check failedTr*   )Úsortedr-   r.   Úagent.verify_hooksr8   Úhermes_cli.lifecycler9   Úhermes_cli.pluginsr:   Úagent.coding_contextr=   r   r<   r/   r0   r1   )	r2   r   r5   Ú_editedr8   r9   r:   rA   r=   s	   &&&      r   Ú_pre_verify_nudgerH   5   s  € ô ”W˜UÐ$?ÄÃÓG×MÐMÈ2ÓN€GðDÝ8Ý1ÝFç‘x ×-Ò-°'Ð<MÓ<OÔ2Oä˜UÐ$9¸4Ó@ˆFØŠ~ÝBÜÑ/¼ÀÈ
ÐTVÓ9W×9]Ð9]Ð[]Ô^Ó_�Ø,2Ô)Ù2Ü" 5¨,¸Ó=×CÐCÀÜ  ¨
°BÓ7×=Ð=¸2Ü˜e W¨bÓ1×7Ð7°RÀØ-ô	ð ñ øô ô DÜ�‰Ð3¸dˆÕCÙðDús5   ªC/ ÁC/ Á<C/ Â'C/ Â7C/ ÃC/ Ã#	C/ Ã/"DÄDc               ó   € V ^8„  d   QhRR/# r   r   )r   s   "r   r    r    P   s   € ÷ ñ ¨=ñ r   c                óŒ   €  ^ RI Hp V! V\        V R^ 4      R7      #   \         d    \        P                  RRR7        R# i ; i)zÏWorkers must end with a terminal board tool (kanban_complete / kanban_block /
kanban_request_review / kanban_request_changes); a narrated stop is recorded
as protocol_violation, so nudge once or twice first.)Úbuild_kanban_stop_nudgeÚ_kanban_stop_nudges)Úmessagesr)   zkanban stop-loop check failedTr*   N)Úagent.kanban_stoprK   r-   r/   r0   r1   )r2   rM   rK   s   && r   Ú_kanban_stop_nudgerO   P   sK   € ðÝ=á&Ø¬°Ð7LÈaÓ(Pô
ð 	
øô ô Ü�‰Ð4¸tˆÔDÚðús   ‚ �"AÁAc               ó   € V ^8„  d   QhRR/# r   r   )r   s   "r   r    r    b   s   € ÷ ñ  ñ r   c                ó(  € \        V R^ 4      p\        V\        4      '       d   V\        8¼  d   R#  ^ RIHp V! V 4      pT'       g   R# RP                  R T 4       4      pR	T,           #   \         d    \        P                  RRR7        R# i ; i)
a  Language-server verdicts on this turn's edits that no tool result carried yet (the edit was the
last tool call; a one-shot run has no next turn to carry them): waits briefly for checks still
running (``agent.lsp.deferred.settle_for_agent``) and returns them as a message for the model.Ú_lsp_turn_end_notesN)Úsettle_for_agentzlate LSP verdict check failedTr*   z

c              3  ó*   "  € T F	  w  rVx € K  	  R # 5i)Nr   )Ú.0Ú_pathÚtexts   &  r   Ú	<genexpr>Ú%_late_lsp_verdicts.<locals>.<genexpr>r   s   é € Ð5©u¡ •t«uùs   ‚z´[System note: the language server reported problems in files you edited this turn, after those tool results had returned. Fix them if they are real, then give your final answer.]

)
r-   Ú
isinstancer6   Ú_MAX_LSP_TURN_END_NOTESÚagent.lsp.deferredrS   r/   r0   r1   Újoin)r2   ÚissuedrS   ÚnotesÚbodys   &    r   Ú_late_lsp_verdictsra   b   s‘   € ô �UÐ1°1Ó5€FÜ�fœc×"Ò" fÔ0GÔ&GÙðÝ7á  Ó'ˆ÷ ÙØ�;‰;Ñ5©uÓ5Ó5€Dðlàõð øô ô Ü�‰Ð4¸tˆÔDÚðús   ²A+ Á+"BÂBc               ó    € V ^8„  d   QhRRRR/# )r   Úflush_fail_msgÚstrr   ÚNoner   )r   s   "r   r    r    x   s   € ÷ 4ñ 4Ð]`ð 4Ðeiñ 4r   c                ó´   € V P                  V4       \        W!4        V P                  W#4       R#   \         d    \        P                  TRR7        R# i ; i)z~Real content: persist and emit as interim so the user sees the attempted answer;
only the nudge is flagged synthetic (#65919).Tr*   N)Ú_emit_interim_assistant_messager   Ú_flush_messages_to_session_dbr/   r0   r1   )r2   Ú	final_msgrM   Úconversation_historyrc   s   &&&&&r   Ú_append_interim_answerrk   x   sL   € ð 
×)Ñ)¨)Ô4Ü�8Ô'ð4Ø×+Ñ+¨HÖKøÜô 4Ü�‰�^¨dˆ×3ð4ús   ž1 ±"AÁAc               ó8   € V ^8„  d   QhRRRRRRRRRRR	RR
RRR/# )r   r2   r   ri   zdict[str, Any]r   rM   zlist[dict[str, Any]]rj   r   r   r   r
   r   )r   s   "r   r    r    ƒ   sZ   € ÷ Yñ YØðYØ)ðYØ>AðYØMaðYàðYà>AðYð .1ðYð ñ	Yr   c          	     ój  a aa€ R V VV3R llp\        S 4      pV'       d�   \        S R^ 4      ^,           S n        RVR&   \        S VSVR4       \	        SRRR	V/4       SS n        \        P                  R
S P                  4       \        RRSS P                  S;'       g    R4      R7      # \        S 4      p	V	'       dY   \        S R^ 4      ^,           S n        RVR&   \        S VSVR4       V! V	R4      p
\        P                  RS P                  4       V
# \        S R^ 4      p\        S SV4      pV'       dN   V^,           S n        RVR&   \        S VSVR4       V! VR4      p
\        P                  RS P                  4       V
# \        S S4      pV'       d‹   \        S R^ 4      ^,           S n        RVR&   RVR&   \	        SV4       V! VR4      p
\        P!                  RS P                  \"        P$                  P'                  RR4      4       S P)                  R4       V
# \        RSVVR7      # )u  Run verify-on-stop â†’ pre_verify hook â†’ kanban stop guard, in that order. Nudges
are user-role rows appended only after the assistant answer row, so role alternation
holds. Hook lookups are imported lazily from their origin modules (tests patch them
there).c               ó$   € V ^8„  d   QhRRRRRR/# )r   Únudgerd   Úflagr   r
   r   )r   s   "r   r    Ú&apply_stop_gates.<locals>.__annotate__�   s!   € ÷ 
ñ 
˜ð 
 Cð 
¨Oñ 
r   c           	     ó„   <€ \        SRRRWR/4       SSn        \        RRSSP                  S;'       g    R4      R7      # )zBAppend the synthetic nudge row and hand the turn back to the loop.ÚroleÚuserÚcontentTNr?   ©r   r   r   r   )r   Ú_session_messagesr
   Ú_interim_content_was_streamed)ro   rp   r2   r   rM   s   &&€€€r   Ú	_continueÚ#apply_stop_gates.<locals>._continue�   sR   ø€ ä�x &¨&°)¸UÈ$Ð!OÔPØ"*ˆÔô Ø¨tØ*8ð 5:×4WÑ4WØ×$Ð$ "ó5ô
ð 	
r   rR   Úverification_requiredÚfinish_reasonzlate-LSP interim flush failedrs   rt   ru   z8late LSP verdicts delivered before the final answer (%d)TNr?   rv   r'   z#verify-on-stop interim flush failedÚ_verification_stop_syntheticz0verification stop-loop nudge issued (attempt %d)Ú_pre_verify_nudgesÚverify_hook_continuezpre_verify interim flush failedÚ_pre_verify_syntheticz$pre_verify nudge issued (attempt %d)rL   Úkanban_terminal_requiredÚ_kanban_stop_syntheticz2kanban stop-loop nudge issued (attempt %d) task=%sÚHERMES_KANBAN_TASKu‹   âš ï¸� Kanban worker tried to exit without a terminal board call (kanban_complete/kanban_request_review/kanban_block) â€” nudging to finishF)ra   r-   rR   rk   r   rw   r0   r1   r
   rx   r3   r'   rH   r~   rO   rL   ÚinfoÚosÚenvironÚgetÚ_emit_diagnostic_status)r2   ri   r   rM   rj   r   r   ry   Ú	_lsp_noteÚ_verify_nudgeÚverdictÚ_attemptÚ_verify_nudge2Ú_kanban_nudges   f&dd$$$       r   Úapply_stop_gatesr�   ƒ   sH  ú€ ÷
ò 
ô" # 5Ó)€IßÜ$+¨EÐ3HÈ!Ó$LÈqÕ$PˆÔ!Ø%<ˆ	�/Ñ"ÜØ�9˜hÐ(<Ð>]ô	
ô 	�x &¨&°)¸YÐ!GÔHØ"*ˆÔÜ�‰ÐOÐQV×QjÑQjÔkÜØ¨tØ*8Ø49×4WÑ4WÐXf×XlÐXlÐjlÓ4mô
ð 	
ô *¨%Ó0€MßÜ*1°%Ð9TÐVWÓ*XÐ[\Õ*\ˆÔ'Ø%<ˆ	�/Ñ"ÜØ�9˜hÐ(<Ð>cô	
ñ ˜MÐ+IÓJˆä�‰ÐGÈ×IhÑIhÔiØˆä�uÐ2°AÓ6€HÜ& u¨n¸hÓG€NßØ#+¨a¥<ˆÔ Ø%;ˆ	�/Ñ"ÜØ�9˜hÐ(<Ð>_ô	
ñ ˜NÐ,CÓDˆÜ�‰Ð;¸U×=UÑ=UÔVØˆä& u¨hÓ7€MßÜ$+¨EÐ3HÈ!Ó$LÈqÕ$PˆÔ!Ø%?ˆ	�/Ñ"Ø.2ˆ	Ð*Ñ+Ü�x Ô+Ù˜MÐ+CÓDˆÜ�‰Ø@Ø×%Ñ%Ü�J‰J�N‰NÐ/°Ó4ô	
ð
 	×%Ñ%ðYô	
ð ˆÜØ¨NØ&CØ0Wôð r   )r   Ú
__future__r   Úloggingr…   Údataclassesr   Útypingr   r   r   r   Úagent.message_metadatar   Ú	getLoggerr0   r
   r3   rH   rO   r[   ra   rk   r�   r   r   r   Ú<module>r–      sr   ðñ
õ #ã Û 	Ý !ß ,Ó ,å 1à	×	Ò	Ð4Ó	5€ð ÷1ð 1ó ð1õõ"õ6ð Ð õõ,4÷Yr   