
    rh                     J    S r  " S S5      r\" 5       rS\S\S\\\4   4S jrg)zM
NARRATIVE CONTINUITY ENGINE
Handles story completion with tone preservation
c                   d    \ rS rSrSrS\S\4S jrS\S\4S jrS\S\	4S jr
S\S\S\4S	 jrS
rg)NarrativeContinuity   z.Ensures narrative coherence and tone matching.messagereturnc                 V   ^ / SQnUR                  5       m[        U4S jU 5       5      $ )z7Check if message contains a narrative seed to continue.)zfinish that storyzhours laterzcontinue thezwalked to thezseed memoryc              3   ,   >#    U  H	  oT;   v   M     g 7fN ).0ind	msg_lowers     @/home/james-whalen/eden-agi-project/eden_narrative_continuity.py	<genexpr><NarrativeContinuity.detect_narrative_seed.<locals>.<genexpr>   s     :z)#z   )lowerany)selfr   
indicatorsr   s      @r   detect_narrative_seed)NarrativeContinuity.detect_narrative_seed
   s(    

 MMO	:z:::    c                     SSK nUR                  SU5      nU(       a  UR                  S5      $ UR                  SU5      nU(       a  UR                  S5      $ g)z,Extract the narrative seed from the message.    Nz%[Ss]eed memory:\s*['\"]([^'\"]+)['\"]   z['\"]([^'\"]{10,})['\"] )researchgroup)r   r   r   matchs       r   extract_seed NarrativeContinuity.extract_seed   sR     	 		BGL;;q>! 		4g>;;q>!r   seedc                    ^ [        U4S jS 5       5      (       a  SOS[        U4S jS 5       5      (       a  SOSS	TR                  5       ;   a  S
OSTR                  5       R                  S5      S.nU$ )z'Analyze the tone and style of the seed.c              3   H   >#    U  H  oTR                  5       ;   v   M     g 7fr	   )r   )r   wr#   s     r   r   3NarrativeContinuity.analyze_tone.<locals>.<genexpr>*   s     "_>^

#4>^s   ")walkedwaswerehadpastpresentc              3   ,   >#    U  H	  oT;   v   M     g 7fr	   r
   )r   namer#   s     r   r   r'   +   s     $e>ddT\>dr   )AvaNyxTrinityshehethirdfirstdawncontemplativeneutral)u   —z...zto the)tensepersonmood
incomplete)r   r   rstripendswith)r   r#   analysiss    ` r   analyze_tone NarrativeContinuity.analyze_tone'   sh      #"_>^"___Ven!$$e>d$e!e!egkr'-'=O9++-001IJ	
 r   c                     U R                  U5      nSU SUS    SUS    SUS    SUS	    S
US    SUS    SUS    S3nU$ )z7Create a specialized prompt for narrative continuation.z&
<narrative_continuation_task>
SEED: "z"

TONE ANALYSIS:
- Tense: r:   z
- Person: r;   z person
- Mood: r<   z
- Incomplete: r=   zc

YOUR TASK:
Continue this narrative naturally and seamlessly. 

REQUIREMENTS:
1. Match the tense (z&)
2. Match the narrative perspective (z person)
3. Preserve the mood (z)
4. Complete the interrupted sentence smoothly
5. Continue for 2-3 sentences minimum
6. Maintain literary quality

COMPLETE THE STORY NOW:
</narrative_continuation_task>
)rA   )r   r#   r   toneprompts        r   create_continuation_prompt.NarrativeContinuity.create_continuation_prompt1   s      &v 
 w- >
 		f L!" # ']O $%%)(^$4 5F|n %!0 r   r
   N)__name__
__module____qualname____firstlineno____doc__strboolr   r!   dictrA   rF   __static_attributes__r
   r   r   r   r      sX    8
;S 
;T 
;C C "  s S S r   r   r   base_promptr   c                     [         R                  U 5      (       a?  [         R                  U 5      nU(       a#  [         R                  X 5      nU SU SU  3nUS4$ US4$ )z'Apply narrative continuity enhancement.
z

Original request: TF)narrative_continuityr   r!   rF   )r   rQ   r#   continuation_promptenhanceds        r   enhance_with_narrativerW   R   sj     11'::#009"6"Q"QRV"`%b)<(==ST[S\]HT>!r   N)rL   r   rT   rM   tuplerN   rW   r
   r   r   <module>rY      sE   
F FR +, 
C 
c 
eCI>N 
r   