
    vj                    N   d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 dZ
dZd	Zd
Z ej                  dej                        Z ej                  dej                        Z ej                  dej                        Zde	z   Ze G d d             ZddZdd	 	 	 	 	 ddZddZy)u  dispatch.spec_template_validator — mandatory normal-callback clause gate.

task-2553+32 (§4.1 / §4.3 / §6.1 / §6.2 / §6.11).

Validates that an executor task spec / generated dispatch prompt carries the
MANDATORY executor normal completion callback clause, and provides an
idempotent injector so a generated dispatch prompt auto-includes it.

Standalone, zero-mutation: imports/edits ZERO tracked module (dispatch/__init__
.py untouched, §8). Pure stdlib.

NO-CRON note (9-R.1): this module performs ZERO cron register/remove. It only
inspects/normalizes spec text. The clause it enforces describes the EXECUTOR
firing its own completion callback — a designed lifecycle signal, not a
registry/checkpoint ad-hoc cron, and not a +32 cron-remove.
    )annotationsN)	dataclass)List)NO_CRON_CORRECTED_DEFINITIONz#dispatch.spec_template_validator.v1PASSFAILHOLD_FOR_CHAIRut   (normal\s+completion\s+callback|정상\s*완료\s*콜백|completion\s+callback\s+cron|normal\s+collector\s+callback)u*   (mandatory|필수|반드시|MUST|required)u0   (발사|발화|fire|register|등록|send|발송)u  [EXECUTOR COMPLETION CALLBACK — MANDATORY] 작업 완료 직후(정상 종료 직전) executor 는 ANU 에 normal completion callback cron 을 반드시 발사해야 한다. 이는 mandatory lifecycle signal 이며 NO-CRON 으로 생략 불가. callback 4-tuple = {task_id, dispatch_cron_id, normal_collector_cron_id(필수), fallback_callback_cron_id}. normal collector 성공 시 fallback cancel-on-success. c                  4    e Zd ZU ded<   ded<   edd       Zy)SpecValidationResultstrverdictz	List[str]reasonsc                (    | j                   t        k(  S )N)r   r   )selfs    #dispatch/spec_template_validator.pyokzSpecValidationResult.okA   s    ||t##    N)returnbool)__name__
__module____qualname____annotations__propertyr    r   r   r   r   <   s    L$ $r   r   c                    | syt        t        j                  |             }t        t        j                  |             }t        t        j                  |             }|xr |xr |S )u>   True iff the spec/prompt carries the mandatory clause (§6.1).F)r   _CALLBACK_INTENTsearch
_MANDATORY
_FIRE_VERB)	spec_text
has_intenthas_mandatoryhas_fires       r   spec_has_normal_callback_clauser%   F   sX    &--i89J**956MJ%%i01H4-4H4r   T)spec_location_knownc                   |st        t        dg      S t        |       rt        t        g       S t        t        dg      S )u   §4.3 / §6.1 / §6.2 — gate an executor spec/prompt.

    * clause present                 -> PASS
    * clause missing                 -> FAIL
    * spec template location unknown -> HOLD_FOR_CHAIR (§9 trigger)
    u[   dispatch/spec template location unresolvable — cannot codify clause (§9 HOLD_FOR_CHAIR).u   executor normal completion callback clause MISSING — every executor spec/prompt MUST require the executor to fire its normal completion callback (§4.3/§6.2). NO-CRON does not exempt this (§6.3/§6.5).)r   HOLDr%   r   r   )r!   r&   s     r   validate_specr)   P   sR     #6
 	
 'y1#D"--)	
 r   c                r    | rt        |       r| S | r| j                  d      rdnd}| xs d | dt         dS )u  §4.1 / §6.11 — idempotently ensure the clause is in a dispatch prompt.

    Returns the prompt unchanged if the clause is already present, else
    appends the canonical MANDATORY_CALLBACK_CLAUSE. Pure string transform,
    no side effects, no cron.
    
 )r%   endswithMANDATORY_CALLBACK_CLAUSE)promptseps     r   !inject_completion_callback_clauser1   n   sE     1&9vt4"4Cl^C5#<"=R@@r   )r!   r   r   r   )r!   r   r&   r   r   r   )r/   r   r   r   )__doc__
__future__r   redataclassesr   typingr   %dispatch.executor_completion_contractr   VALIDATOR_SCHEMAr   r   r(   compile
IGNORECASEr   r   r    r.   r   r%   r)   r1   r   r   r   <module>r;      s     # 	 !  9  2::CMM 
 RZZ12==
 RZZ7
? ##  $ $ $5 48,0<
Ar   