
    pj5                        d Z ddlmZ ddlmZ ddlmZmZmZm	Z	 dZ
dddd	d
dZ edh      ZddZ	 	 	 	 	 	 	 	 ddZdd	 	 	 	 	 	 	 ddZddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddd dZdZ	 	 	 	 	 	 d!dZy)"u  레인2 재설계 — 구조물 seed 순수 T2I + seed 기반 항공뷰 맵 (2026-07-15).

사용자 지시(설계 v2 레인2 대체): 복잡 구조물은 seed 실사를 먼저 T2I 로
확정 → 그 seed 를 참조로 항공뷰 맵 생성 → 이후는 레인1(마커 맵) 파이프
(geometry/PIL 합성/스케치/leakage 는 outdoor_marker_map 재사용).
여기는 두 생성 계약의 결정론 프롬프트 조립만 담당한다.
    )annotations)Path)AnyDictMappingSequencestructure_seedz1.202607151600z2.202607151900z3.202607152200z4.202607161253z5.202607221100)12345r   c                @    | t         vrt        d|        t         |    S )Nu"   structure_seed 팩 버전 없음: )SEED_PACK_VERSION_MAP
ValueErrorversions    a/Users/manta/Documents/Projects/TheRoad-I1/backend/app/modules/pipeline/outdoor_structure_seed.pyresolve_seed_pack_versionr   1   s)    ++=gYGHH ))    c                   | j                  d      xs g D cg c]N  }t        |t              r<|j                  d      dk7  r(|j                  d      xs |j                  d      xs dP }}|rt        d|dd	        | j                  d
      xs dj	                         g}g }| j                  d      xs g D ]  }t        |t              s|j                  d      xs dj	                         }|j                  d      xs dj	                         }|s]|j                  |rd| d| nd|        |j                  d|         dj                  d |D              }	dj                  |      }
| j                  d      xs g D cg c]X  }t        |t              rF|j                  d      xs dj	                         r#|j                  d      xs dj	                         Z }}dj                  |      }g }g }|xs i j                  d      xs g D ]  }t        |t              s|j                  |j                  d            xs i }|j                  d      xs dj	                         }|s^|j                  dd       d| }|j                  d      du r|j                  |       |j                  d      du s|j                  |        |	|
dj                  |      dj                  |      |dS c c}w c c}w )u  seed 생성 입력 파생 (Stage D — Codex 배선 조건 ⑥).

    structure_desc SOT = outdoor_place_spec 의 persistent_site **검증
    서술**(layout_narration_en + items name/placement) — raw entity_merge
    서술 금지(미검증 transient 가 seed 에 고착되는 것 차단).
    excluded_transient_en = spec excluded_transient_elements 를 negative
    contract 로 전달. interior_note_en = 같은 building 그룹 실내 loc
    서술(규모 SOT — 육안 라운드1 계약). exterior_note_en = 같은 그룹
    실외 loc 서술(외관 look evidence — E2E 6회차 승인: 위상은 여전히
    spec 단독 SOT, 서술 속 transient 는 EXCLUDED negative 가 방어).
    itemstemporal_scopepersistent_sitecodename_en?uW   outdoor_place_spec items 에 persistent_site 아닌 항목 — seed 입력 SOT 위반: N   layout_narration_en placement_enz- z: 
c              3  &   K   | ]	  }|s|  y wN ).0xs     r   	<genexpr>z%derive_seed_inputs.<locals>.<genexpr>a   s     5%Q1q%s   excluded_transient_elementsz; membersloc_iddescriptionname	is_indoorTFz / )structure_descstructure_names_eninterior_note_enexterior_note_enexcluded_transient_en)get
isinstancedictr   stripappendjoin)specbuilding_grouplocations_by_iditbadlines	name_onlyr-   	placementr/   r0   r'   excludedr3   interior_linesexterior_linesmemlocdesclines                       r   derive_seed_inputsrI   7   s   , ((7#)r))Bb$FF#$(99 
	3266),	3	3)   ''*2Awi1
 	
 hh,-3::<=EIhhw%2%"d#y!'R..0VVN+1r88:	LLY2dV2i[1 "4&k+r$[) & YY5%55N 9- 78>B>>AaAEE)$4$:#A#A#C 
y		R&&(>  
 !IIh/NN$")))4::#t$!!#''("34:&,"335''&"%&b/77;4'!!$'WW[!U*!!$' ;  )0!JJ~6!JJ~6!6 q@s   AL ALr%   )excludec                H   | xs i j                  d      xs g D ch c]G  }t        |t              r5|j                  d      du r"|j                  d      r|j                  d      I c}t        |      t	        fd|xs i j                         D              S c c}w )u  같은 building 그룹 실내 멤버(is_indoor=True) loc 의 씬 목록.

    v9 room_inventory 배선(Codex v8b ③ 실측 결손): seed 저작 입력이
    야외 씬(lane scene_indices)뿐이라 실내 씬(안방·자기방 증거)이
    미전달 — 방 전수를 원리적으로 열거 못했다. scene→loc 매핑 SOT=
    scene_director 의 scene 별 primary_location (코드 자동 구축 관례).
    exclude=이미 공급되는 야외 씬(중복 제외). 결정론 정렬.
    r*   r.   Tr+   c              3  X   K   | ]!  \  }}t        |t              r|v r|vr| # y wr$   )r5   int)r&   sirF   rB   interior_locss      r   r(   z1collect_interior_scene_indices.<locals>.<genexpr>   s6      ;wr3b#3-#7h 	;s   '*)r4   r5   r6   setsortedr   )r;   scene_primary_locrJ   mrB   rO   s       @@r   collect_interior_scene_indicesrT      s      !&B++I6<"<<Aa155#5#=EE(O 	
h<M 7|H ,299;  s   ABr    r   )r1   r2   world_anchor
place_textr3   prompt_versionc                J   ddl m} | xs dj                         st        d      t	        |      }d| d |t
        d|      j                         d	|  g}	|t        v r,|	j                   |t
        d
|      j                                |xs dj                         r2|	j                   |t
        d|      j                         d| z          |xs dj                         r2|	j                   |t
        d|      j                         d| z          |xs dj                         r|	j                  d|        |xs dj                         r|	j                  d|z          |	j                   |t
        d|      j                                dj                  |	      S )u  구조물 seed 순수 T2I 프롬프트 — 참조 이미지 없는 생성.

    structure_desc = persistent_site 검증 서술(derive_seed_inputs SOT),
    interior_note_en = 같은 building 실내 loc 서술(규모 SOT, 없으면
    SCALE 절 자체를 생략 — dangling 금지, Stage C H2 교훈).
    exterior_note_en = 같은 building 실외 loc 외관 서술(look evidence,
    v4 — 빈 문자열=절 생략. 위상 권위는 THE STRUCTURE, transient 는
    EXCLUDED 절이 우선한다는 계약이 팩 exterior_clause 에 명시됨).
    excluded_transient_en = spec 이 transient 로 판정한 요소의 negative
    contract (빈 문자열=절 생략, 기존 조립 byte-identical).
    r   load_promptr    u:   structure_desc 결손 — seed 생성 대상 서술 필수zA photographic plate.	seed_headr   zTHE STRUCTURE: human_scale_clauseexterior_clausez
EXTERIOR NOTES: scale_clausez
INTERIOR: zTHE LOCATION: uZ   EXCLUDED — TRANSIENT ELEMENTS (confirmed not part of the permanent site; never depict): 	no_people

)	app.modules.prompt_loaderrZ   r7   r   r   SEED_PACK_MODULE_HUMAN_SCALE_PACKSr8   r9   )
r/   r1   r2   rU   rV   r3   rW   rZ   resolvedpartss
             r   build_structure_seed_promptrg      s   * 6 b'')UVV(8H
|nA.$k8DJJL
.)*E
 ++ 	 "6eg	

 	B%%' 	(*; (**/%'"#3"456	

 	B%%'(. (**/%'-./0	

 	b!~j\23#**,.0EF	
 
LL$k8DJJL ;;ur   r   )rW   c                    ddl m} t        |       }dj                   |t        d|      j                          |t        d|      j                         g      S )u  (DEPRECATED — 육안 라운드3, 2026-07-15) seed→실사 탑다운 항공뷰.

    사용자 판정: 실사 항공사진은 레인1 canon 맵과 매체가 다름 — 레인2
    맵도 outdoor_place_canon map_prompt(2D SITE PLAN 재투영, 참조=seed)를
    재사용한다(v4 canary 실증, outdoor_structure_seed_step 배선). 신규
    소비 금지 — 모듈 삭제 금지 규칙에 따라 이력용으로만 보존.
    r   rY   ra   aerial_headr   r`   )rb   rZ   r   r9   rc   r7   )rW   rZ   re   s      r   build_aerial_map_promptrj      sT     6(8H;;$m$	&&+eg$k8DJJL  r   uZ  

SITE LOOK REFERENCE: the attached photograph shows this exact place — the confirmed look of its structure and surroundings. Keep the structure's massing, storey count, materials, wear and the character of the surroundings consistent with that photograph while composing the viewpoint this plate needs. Do not copy its camera angle or framing.c                ,   i }|xs g D ]  }t        |xs i j                  d      xs d      }| xs i j                  |      xs i }|j                  d      dk7  rTt        |j                  d      xs d      }|rt        |      j                         s|xs i j                  d      xs g D ]^  }|xs i j                  d      du st        |xs i j                  d	      xs |xs i j                  d
      xs d      }|sW||d||<   ` 
 |S )uG  loc_id → {group_id, path} — 야외(is_indoor False) loc 에 그 그룹의
    확정 seed 실사를 플레이트 공간·룩 참조로 매핑.

    status!='ok'/경로 결손/파일 부재 그룹은 제외(호출측 fail-safe — 기존
    경로 유지). 순수 함수 — 스텝 게이트(flag)는 호출측 소유.
    group_idr    statusokseed_png_pathr*   r.   Fr+   location_id)rl   path)strr4   r   is_file)	seed_groupsbuilding_groupsoutggidentryprS   rF   s	            r   build_seed_plate_refsr{     s    &(C""17--
+1r2"'',299X$&		/*0b1Q)'ry)/R/AR}}[)U2
 W"MM(+ :R}}]3:79; ,/;CH 0 #& Jr   N)r   rr   returnrr   )r:   r6   r;   r6   r<   r6   r|   r6   )r;   Mapping[str, Any]rR   zMapping[int, Any]rJ   zSequence[int]r|   list)r/   rr   r1   rr   r2   rr   rU   rr   rV   rr   r3   rr   rW   rr   r|   rr   )rW   rr   r|   rr   )rt   r}   ru   zSequence[Mapping[str, Any]]r|   zDict[str, Dict[str, str]])__doc__
__future__r   pathlibr   typingr   r   r   r   rc   r   	frozensetrd   r   rI   rT   rg   rj   SEED_SITE_GUIDANCEr{   r%   r   r   <module>r      sX   #  / /#  
 
 
 
 
7 > u% *R
R R 	R
 
Rr  	% ) 	
 
> !#AA A 	A
 A A A A 	AH 69 . "0 r   