
    3j-                       U d Z ddlmZ ddlmZmZ ddlmZmZm	Z	m
Z
 dZded<   dZded	<   e G d
 d             Ze G d d             Ze G d d             Ze G d d             ZdZded<   	 d	 	 	 	 	 ddZddZddZddZddZy) uj  anu_v3.goal_loop_planner — Track3 goal-driven loop generalization (minimal).

Authority: task-2553+17.md §1 / §2 / §4 (Track3) + §12 9-R.7.

The chair supplies only ``goal + boundary + policy_profile``; this module
binds them to a track and generates the standard ANU loop plan::

    lint -> refine(9-R) -> re-lint -> impl -> audit -> adjudication
         -> callback -> next

and resolves next_action / HOLD condition / final-packet schema.

9-R.7 split rule (non-self-referential / no bootstrap paradox):
  If any of the Track2 mandatory-11 features would be made unimplementable
  or contaminated by a Track3 generalization, that **generalization
  sub-feature only** is split out as a follow-up candidate (all 11 Track2
  features preserved, no silent drop). If even after splitting a Track2
  mandatory feature is unavoidably damaged -> HOLD_FOR_CHAIR.

NOTE (9-R.7 / §10): the construction of this very batch is ANU **manual**
coordination — the not-yet-built coordinator never manages its own
build/adjudication. This planner is for *future* batches; the task-2553
series here is fixture/verification data only.
    )annotations)	dataclassfield)DictListSequenceTuple)lint	refine_9rre_lintimplauditadjudicationcallbacknextzTuple[str, ...]LOOP_STAGES)batch_id_generationcallback_4tuple_registrydependency_matrixexpected_files_overlapforbidden_write_overlapshared_artifact_contaminationfinal_authority_packetduplicate_pending_classifiertrack_loop_state_13batch_next_actionconsolidated_final_summaryTRACK2_MANDATORY_11c                  P    e Zd ZU ded<   dZded<   dZded<   dZded	<   d
Zded<   y)PolicyProfilestrname   intretry_ceilingTboolauto_micro_fixhold_on_high_or_criticalzanu_v3.track_final_packet.v1final_packet_schemaN)__name__
__module____qualname____annotations__r%   r'   r(   r)        //home/jay/workspace/anu_v3/goal_loop_planner.pyr    r    ;   s1    
IM3ND%)d)==r/   r    c                  h    e Zd ZU dZded<   ded<    ee      Zded<    ed       Zd	ed
<   ddZ	y)GoalRequestz6Chair-supplied: goal + boundary + policy_profile only.r!   goal_idgoal_statementdefault_factory	List[str]boundaryc                     t        d      S )Ndefault)r    r.   r/   r0   <lambda>zGoalRequest.<lambda>L   s    i 8 r/   r    policy_profilec                2    t        || | j                        S )N)track_idgoalr<   )TrackGoalBindingr<   )selfr>   s     r0   
bind_trackzGoalRequest.bind_trackO   s    ..
 	
r/   N)r>   r!   returnz'TrackGoalBinding')
r*   r+   r,   __doc__r-   r   listr8   r<   rB   r.   r/   r0   r2   r2   D   s8    @L5Hi5$)8%NM 
r/   r2   c                  ,    e Zd ZU ded<   ded<   ded<   y)r@   r!   r>   r2   r?   r    r<   N)r*   r+   r,   r-   r.   r/   r0   r@   r@   W   s    M
!!r/   r@   c                  |    e Zd ZU ded<   ded<   ded<   ded<   ded<   ded	<    ee
      Zded<   dZded<   ddZy)LoopPlanr!   r>   r3   r7   stagesr$   r%   hold_conditionsr)   r5   split_followupsPLANNEDstatusc           	         | j                   | j                  t        | j                        | j                  t        | j
                        | j                  t        | j                        | j                  dS )N)r>   r3   rI   r%   rJ   r)   rK   rM   )	r>   r3   rE   rI   r%   rJ   r)   rK   rM   )rA   s    r0   to_dictzLoopPlan.to_dicti   s[    ||4;;'!//#D$8$89#'#;#;#D$8$89kk	
 		
r/   N)rC   zDict[str, object])	r*   r+   r,   r-   r   rE   rK   rM   rO   r.   r/   r0   rH   rH   ^   sB    ML!&t!<OY<FC

r/   rH   )frozen_anchor_change_requiredgithub_write_requiredtrack1_domain_touch_required!codex_unresolved_high_or_criticalanu_codex_repeated_conflictgoal_unreachable'track3_irreducible_fundamental_conflict	critical7DEFAULT_HOLD_CONDITIONSc           	         | j                   }t        | j                  | j                  j                  t        t              |j                  t        t              |j                        }|D cg c]  }|j                  d      s| }}|D cg c]  }|j                  d      r| }}|D cg c]  }|t        vs| }}|rt        d|       |rd|_        g |_        |S |rd|_        t        |      |_        |S c c}w c c}w c c}w )a  Generate the loop plan for a goal-bound track and apply 9-R.7.

    ``track2_conflicts`` lists Track2 mandatory feature keys that this
    generalization conflicts with. Each conflicting key is split into a
    follow-up (Track2 feature preserved). If the list is non-empty AND
    contains a feature that cannot be preserved by splitting (signalled by
    the sentinel ``"<irreducible>"`` prefix) -> HOLD_FOR_CHAIR.
    )r>   r3   rI   r%   rJ   r)   z<irreducible>zunknown Track2 feature keys: HOLD_FOR_CHAIRFOLLOW_UP_SPLIT)r<   rH   r>   r?   r3   rE   r   r%   rX   r)   
startswithr   
ValueErrorrM   rK   sorted)bindingtrack2_conflictsppplancirreducible
splittableunknowns           r0   generate_loop_planrg      s    
		B!!$$K &&4522D /P!,,2O1PKP#1<<+HJ  *=!=G  8	BCC&! K 
'%j1K Qs$   .DDD&D0D>Dc                    | j                   dk(  ry|| j                  vrt        d|      | j                  j                  |      }|dz   t	        | j                        k  r| j                  |dz      S y)z6Resolve the next loop stage (or terminal next-action).rZ   zunknown stage    LOOP_COMPLETE)rM   rI   r]   indexlen)rb   current_stageidxs      r0   resolve_next_actionro      sp    {{&&DKK'>-):;<<
++

M
*C
QwT[[!!{{37##r/   c                P    | j                   D ]  }|j                  |      s|c S  y)z7Return the first triggered HOLD condition, else "NONE".NONE)rJ   get)rb   signalsconds      r0   resolve_hold_conditionru      s-    $$ ;;tK r/   c                    | j                   S )N)r)   )rb   s    r0   resolve_final_packet_schemarw      s    ###r/   c                J    | D ]  }|j                   D ]  }|t        vs  y   y)zZero silent drop guarantee: no plan may HOLD without recording it,
    and split follow-ups must reference only known Track2 keys.FT)rK   r   )planspfs      r0   track2_mandatory_preservedr|      s9      "" 	A++	 r/   N)r.   )r_   r@   r`   zSequence[str]rC   rH   )rb   rH   rm   r!   rC   r!   )rb   rH   rs   zDict[str, bool]rC   r!   )rb   rH   rC   r!   )ry   zSequence[LoopPlan]rC   r&   )rD   
__future__r   dataclassesr   r   typingr   r   r   r	   r   r-   r   r    r2   r@   rH   rX   rg   ro   ru   rw   r|   r.   r/   r0   <module>r      s   2 # ( . .	 _ 	( _  > > > 
 
 
$ " " " 
 
 
0	,  	 ')$$#$ $N	$r/   