
    3jf                        d Z ddlmZ ddlZddlmZmZ ddlmZ ddl	m
Z
mZ dZ ed      Z ed	      Z ed
      ZdZdZ ed       G d d             ZddZddZdddZddd	 	 	 	 	 ddZddZddZy)u|  anu_v3.artifact_root_resolver — canonical ANU workspace root resolver.

task-2553+46 (구현목표 C). Standalone, read-only, pure stdlib.

Problem (회장 §2.2 / diagnosis report_items.2): the +39 fallback / dead-man
collector first looked at the *autoset / current cwd* (`/home/jay/.cokacdir/
workspace/autoset`, which has NO `memory/events`) and concluded the artifact
was missing — but the real CANONICAL workspace root
`/home/jay/workspace/memory/events` actually contained the +39
result/collector-result.

This module hard-codes the canonical ANU workspace root as executable code
(CLAUDE.md §1: "모든 코드는 `/home/jay/workspace/` 하위에 작성") and gives
collectors a *single* place to resolve the events / reports / schedule_history
lookup roots, so that an artifact-missing verdict is NEVER reached on an
autoset-cwd false negative without first re-checking the canonical root
(§3.C, regression 10/11/12).

NO-CRON / Layer A (9-R.1): this module performs ZERO write, ZERO cron
register/remove, ZERO dispatch, ZERO merge. It only resolves paths and
stat/exists-checks files. It never executes ``cokacdir``/``subprocess``.
    )annotationsN)	dataclassfield)Path)ListOptionalz"anu_v3.artifact_root_resolution.v1z/home/jay/workspacez%/home/jay/.cokacdir/workspace/autosetz$/home/jay/.cokacdir/schedule_historyzmemory/eventszmemory/reportsT)frozenc                      e Zd ZU dZded<   ded<   ded<   ded<   ded<   ded<   d	ed
<   d	ed<   dZd	ed<    ee      Zded<   ddZ	y)ResolvedRootszDUnified, canonical-first lookup roots for collector artifact checks.strschemacanonical_rootautoset_cwd_root
events_dirreports_dirschedule_history_dirboolcanonical_root_presentevents_dir_presentFautoset_events_dir_present)default_factoryz	List[str]search_orderc                    | j                   | j                  | j                  | j                  | j                  | j
                  | j                  | j                  | j                  t        | j                        d
S )N
r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   listr   )selfs    4/home/jay/workspace/anu_v3/artifact_root_resolver.pyto_jsonzResolvedRoots.to_jsonC   sg    kk"11 $ 5 5//++$($=$=&*&A&A"&"9"9*.*I*I !2!23
 	
    N)returndict)
__name__
__module____qualname____doc____annotations__r   r   r   r   r    r   r   r   r   1   sT    NKO   (-,#D9L)9
r   r   c                B    	 | j                         S # t        $ r Y yw xY w)NF)is_dirOSError)ps    r   _exists_dirr,   R   s%    xxz s    	c                     t         S )u>   The single source of truth for the ANU workspace root (§3.C).)CANONICAL_ANU_WORKSPACE_ROOTr'   r   r   r   r   Y   s    ''r   c                N   | t        |       nt        j                         }	 |j                         t        j                         k(  xs' t	        |      j                  t	        t                    S # t        $ r* t	        |      j                  t	        t                    cY S w xY w)u   True iff the (current) cwd is the artifact-poor autoset workspace.

    Used to assert that an autoset cwd alone must NEVER yield RESULT_MISSING
    (regression 11) — the canonical root has to be consulted first.
    )r   cwdresolveAUTOSET_CWD_ROOTr   
startswithr*   )r0   cs     r   is_autoset_cwdr5   ^   s     _S	$((*A8yy{.6688 
CF<M<M !=
 	
  81v  %5!6778s   AA1 10B$#B$)autoset_cwdr   c                v   t         }| t        |       nt        }|t        |      nt        }|t        z  }|t
        z  }t        t        t        |      t        |      t        |      t        |      t        |      t        |      t        |      t        |t        z        t        |      t        |      g
      S )u   Resolve the canonical-first lookup roots.

    The canonical root is always searched FIRST; the autoset cwd is recorded
    for provenance only and is NEVER used to decide artifact-missing on its
    own (§3.C / regression 10/11). Read-only.
    r   )
r.   r   r2   DEFAULT_SCHEDULE_HISTORY_DIR_EVENTS_SUBDIR_REPORTS_SUBDIRr   RESOLVER_SCHEMAr   r,   )r6   r   crootarootsh_dirr   r   s          r   resolve_rootsr?   m   s     )E(4[:J 

  + 	!") 
 'J/)K5zUz?$ [*51&z2#.u~/E#F%j#e*- r   c                     t         t        z  S N)r.   r9   r'   r   r   canonical_events_dirrB      s    '.88r   c                     t         t        z  S rA   )r.   r:   r'   r   r   canonical_reports_dirrD      s    '/99r   )r+   r   r    r   )r    r   rA   )r0   Optional[os.PathLike]r    r   )r6   rE   r   rE   r    r   )r%   
__future__r   osdataclassesr   r   pathlibr   typingr   r   r;   r.   r2   r8   r9   r:   r   r,   r   r5   r?   rB   rD   r'   r   r   <module>rK      s   , # 	 (  !6
  $$9:  ?@   $$JK  " $
 
 
@(
8" *.26"&" 0" 	"J9:r   