
    IjF+                        d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZmZmZ  G d	 d
ee      Z ed       G d d             Zdded	 	 	 	 	 	 	 	 	 	 	 ddZy)u  5-enum status 판정기.

회장 verbatim 필수 구현 9.status_enum_separation_5:
  - SPAWN_VERIFIED                          (worktree + executor process
                                             + first response NOT-refusal 3 신호)
  - SPAWN_PENDING                           (fire 후 짧은 시간 · 부분 신호만)
  - SPAWN_VISIBILITY_GAP                    (일부 source 부재 + 다른 source 있음)
  - CALLBACK_RECOVERED_AFTER_VISIBILITY_GAP (ANU 초기 ABSENT 후
                                             result/report/done 또는 callback envelope
                                             도착 · 2 source 이상 교차)
  - TRUE_SILENT_DROP                        (전 source 부재 + 30분 경과
                                             + ANCHOR-3 예외 0)

ANCHOR-2: self-attestation 단독 금지 · 최소 2 source 교차.
ANCHOR-4: worktree 한쪽 missing 만으로 silent drop 단정 금지.
ANCHOR-5: CALLBACK_RECOVERED_AFTER_VISIBILITY_GAP 분리 명시 (task-2657 WARN 1 재발 방지).
    )annotations)	dataclassfield)Enum)Optional   )SourceSnapshot)HARD_TIMEOUT_SECONDSTimeoutDecisionevaluate_timeout_gatec                       e Zd ZdZdZdZdZdZy)SpawnVisibilityStatusSPAWN_VERIFIEDSPAWN_PENDINGSPAWN_VISIBILITY_GAP'CALLBACK_RECOVERED_AFTER_VISIBILITY_GAPTRUE_SILENT_DROPN)__name__
__module____qualname__r   r   r   r   r        5utils/anu_spawn_visibility_guard/status_classifier.pyr   r   !   s    %N#M1.W+)r   r   T)frozenc                      e Zd ZU ded<   ded<   ded<   ded<   ded	<   d
ed<   dZded<   dZded<    ee      Zded<   y)StatusDecisionr   statusstrreasonztuple[str, ...]positive_sourcescallback_evidence_sourcesintcrossed_sources_countr   timeoutFboolinitial_anu_absent_observedNOptional[bool]first_response_not_refusal)default_factorynotes)	r   r   r   __annotations__r&   r(   r   tupler*   r   r   r   r   r   )   sJ    !!K%%..(--155"59E?9r   r   FN)r&   r(   hard_timeout_secondsc               8   t        | ||      }| j                         }| j                         }g }| j                  xs | j                  }	|j
                  r7|s5|s3t        t        j                  d|dd| d||d|||t        |      	      S t        |      dk\  ro|s| j                  sat        t        j                  d	d
j                  |      z   dz   | j                  sdndz   |rdndz   ||t        |      |||t        |      	      S |	xr | j                  xr |du }
|
rOt        t        j                  d| j                   d| j                   d||t        |      |||t        |      	      S |	rS| j                  rG|E|j                  d       t        t        j                  d||t        |      |||t        |      	      S t!        | j"                  t$              xr* | j"                  j'                         j)                         dv }|j
                  s|s|r|s||dz  k  rSt        t        j*                  d|rd| j"                  nd|dd|dz   dz   ||t        |      |||t        |      	      S t        t        j,                  ddt        |       dz   ||t        |      |||t        |      	      S |j                  d       t        t        j,                  d t        |       d!t        |       d"||t        |      |||t        |      	      S )#u  5-enum 분류 수행.

    Parameters
    ----------
    sources: SourceSnapshot
    elapsed_since_fire_seconds: dispatch fire 이후 경과 초.
    initial_anu_absent_observed: ANU 가 사전에 spawn ABSENT 로 측정한 적이
        있는가? True 일 때 callback recovery 라벨로 승격 가능.
    first_response_not_refusal: SPAWN_VERIFIED 3 신호 중 'first response
        NOT-refusal' 신호. 모르면 None.
    hard_timeout_seconds: TRUE_SILENT_DROP hard timeout (default 30분).
    )elapsed_secondsr-   u   전 source 부재 + elapsed z.0fu   s ≥ hard_timeout u   s + ANCHOR-3 예외 0r   )	r   r   r    r!   r#   r$   r&   r(   r*      u'   callback evidence ≥ 2 source 교차 (z, )u    · executor process 부재 u    · initial ANU ABSENT 관측Tu!   3 신호 충족: worktree(legacy=z, cokacdir=z1) + executor process + first_response NOT-refusaluT   first_response_not_refusal unspecified · worktree+process 만으로 verified 분류ut   worktree 가시 + executor process 양성 (first_response_not_refusal 미관측 — 2 신호 교차 기준 verified)>   firedpendingrunningstartedin_progressg      ?u+   fire 후 짧은 시간 + 부분 신호 — zschedule_history_last_status=zelapsed zs < hard_timeout/2 (zs)u,   일부 source 부재 + 다른 source 양성 (u    positive · timeout 미경과)u>   fallback GAP · ANCHOR-2 self-attestation 단독 인정 금지u   교차 검증 미달 (positive=z, callback_evidence=u3   ) — GAP 으로 라벨링 후 추가 관측 권고)r   r    r!   legacy_worktree_presentcokacdir_worktree_presentsilent_drop_eligibler   r   r   r,   lenexecutor_process_presentr   joinr   append
isinstanceschedule_history_last_statusr   striplowerr   r   )sourceselapsed_since_fire_secondsr&   r(   r-   r$   	positivescallback_evidencer*   worktree_visiblethree_signalschedule_pendings               r   classify_spawn_visibilityrK   6   s   ( $21G ((*I99;E 	''L7+L+L  	$$!(995c: ;  455JL '&7"#(C'A,
 	
* 	!#'33 (PP9DIIFW<XX[^^ #;; 2	 3 4
 '&7"%&7"8(C'A,+
 	
4 	 	/,,	/&$. 
 (773223 4#==> ?BB
 '&7"%i.(C'A,
 	
, 	,,&.kl(77] '&7"%i.(C'A,
 	
& 	777= 	E00668>>@DE  ((I ),@3,FF!,::A , 88\8\7_`'(B3'G H--AQ-F,GrK	 "+*;&))n,G+EEl# * (==>c)n%%DEF '&7"%i.(C'A,
 	
$ 
LLQR$99-Y0@ A!!$%6!7 8 9<< #"3!)n$?#=El r   )rD   r	   rE   floatr&   r%   r(   r'   r-   r"   returnr   )__doc__
__future__r   dataclassesr   r   enumr   typingr   source_collectorr	   timeout_gater
   r   r   r   r   r   rK   r   r   r   <module>rU      s   $ # (   , *C * $	: 	: 	:  ).15 4VV !&V "&	V
 !/V V Vr   