
    #jW                       d Z ddlmZ ddlZddlZddlmZ  ee      j                         j                  Z
 ee
      ej                  vr"ej                  j                  d ee
             ddlmZ 	 ej                  j                  d ee
dz  dz  dz               dd	lmZ dd
lmZ ddZddZedk(  r e        yy# e$ r dZdZY !w xY w)u  dispatch.py — 호환 shim (task-2388 Phase ε).

dispatch.py 4336줄이 dispatch/ 패키지 6 모듈로 분리되었다.
이 파일은 외부 호출자 호환을 위한 얇은 shim:
- `python3 dispatch.py --team ... --task-file ...` 스크립트 실행 진입점
- `import dispatch`는 패키지(dispatch/__init__.py)를 우선 로드하므로 영향 없음

분리 모듈:
- dispatch/_state.py: 상수 + optional imports + logger
- dispatch/task_id.py: task-2380 4-layer fix
- dispatch/retry.py: task-2387 status 가드
- dispatch/prompt.py: task-2386 슬림 prompt
- dispatch/audit.py: bot_pool + allowed_resources + capability + affected_files + warnings + team
- dispatch/core.py: dispatch + cancel + main + composite + PRD
    )annotationsN)Path)mainscriptsharnessv36)write_handoff_marker)_verify_bot_spawnc                    t         yt        j                  j                  dt	        t
        dz  dz              }	 t        || f||d|S # t        $ r Y yw xY w)u   §5.2 dispatch inner instrumentation: failure handoff marker 박제 (비차단).

    bot_collision→BLOCKED · dispatch_false_ok/capability_null/cron_registration_
    failure→INFRA_DEFECT · task_md_missing→PERMISSION_FAIL.
    N FAILURE_CALLBACK_2712_EVENTS_DIRmemoryevents)failure_kind
events_dir)_fcb_write_handoffosenvirongetstr
_REPO_ROOT	Exception)terminal_stater   task_idkwr   s        </home/jay/workspace/.worktrees/task-2729+10-dev6/dispatch.py_dispatch_emit_handoffr   .   sr     !*J!H,-J!^
2>!
%'
 	
  s   A 	AAc                    d} t        t        j                        D ]  \  }}|dv r6|dz   t        t        j                        k  rt        j                  |dz      } @|j	                  d      sR|dz   t        t        j                        k  srt        t        j                  |dz            j                  }  	 t                y# t        $ r t        dd|         w xY w)	u   main() 을 fail-closed 로 감싼다: dispatch 단계 crash 시 INFRA_DEFECT
    handoff marker 박제 후 원래 예외 re-raise (exit_code 보존).unknown)z	--task-idz--task   z--task-fileINFRA_DEFECTdispatch_runtime_crash)r   N)
	enumeratesysargvlen
startswithr   stemr   BaseExceptionr   )_task_idias      r   _main_with_failure_guardr,   C   s     H#((# 21''AECM,AxxAH\\-(QUS]-BCHHQUO,11H	2
 4h	
 		s   :
C C__main__)r   )returnNone)__doc__
__future__r   r   r#   pathlibr   __file__resolveparentr   r   pathinsertdispatch.corer   failure_callback_dispatcherr	   r   terminal_state_classifierr
   ImportErrorr   r,   __name__     r   <module>r?      s     # 	 
  (^##%,,
z?#(("HHOOAs:' HHOOAs:	1I=EFG <*$ z Y  s   47C 	CC