/ core / attention / __pycache__ / unified.cpython-314.pyc
unified.cpython-314.pyc
  1  +
  2  ?3gin3��P�Rt^RIHtHt^RIHt^RIHtHtHtH	t	^RI
  3  Ht^RIH
t
HtHt^RIHtHtHt^RIHtHtHtHtHt^RIHtHtHt^R	IHtH t H!t!]!R
  4  R44t"!RR
4t#]PH3RRllt%]&R8Xd�]'!R4]'!R4]'!R4]%!RRR7t(]'!R4](PS4t*]'!R]*R,24]'!R]*R,24]'!R]*R,24]'!R4](PW4t,]'!],4]'!R4R #R #)!aw
  5  Unified Attention System
  6  
  7  Wires together all attention subsystems:
  8  - AttentionTracker: tracks where attention lands
  9  - CrossSessionTracker: tracks attention across concurrent sessions
 10  - AhaDetector: detects when attention crystallizes into insight
 11  - SessionMembrane: controls context flow between sessions
 12  
 13  "Attention is all you need" - this module is the integration point.
 14  )�	dataclass�field)�datetime)�Optional�List�Dict�Tuple)�Path)�AttentionTracker�AttentionEvent�create_attention_system)�CrossSessionTracker�SessionStreamWatcher�create_cross_session_system)�AhaDetector�
 15  AhaManager�AhaSurfacingConfig�AhaSurfaceTarget�create_aha_system)�SessionMembrane�PermeabilityLevel�create_membrane_system)�AttentionCompactor�DailyNoteCompactor�create_compaction_systemc�Xa�]tRt^toRt]PtRtRt	Rt
 16  RtV3RltRt
VtR#)�UnifiedAttentionConfigz/Configuration for the unified attention system.Tg333333�?Fc�n<�V^8�dQh/S[;R&S[;R&S[;R&S[;R&S[;R&S[;R&S[;R&#)��sessions_dir�daily_notes_dir�permeability�enable_aha_detection�enable_compaction�aha_min_confidence�aha_audio_enabled)�strr�bool�float)�format�
__classdict__s"��9/Users/rcerf/repos/Sovereign_OS/core/attention/unified.py�__annotate__�#UnifiedAttentionConfig.__annotate__s`���������	�
 17  $�B���%�
��"���#���#���N)�__name__�
 18  __module__�__qualname__�__firstlineno__�__doc__r�
 19  ATTRACTORSr!r"r#r$r%�__annotate_func__�__static_attributes__�__classdictcell__�r*s@r+rrs4����9�'8�&B�&B�L�!%��"�� #��#���r.rc��a�]tRt^%toRtV3RlRltV3RlRltRV3RlRlltV3R	lR
 20  ltV3RlRlt	V3R
lRlt
 21  RV3RlRlltV3RlRltV3RlRlt
RtVtR#)�UnifiedAttentionSystemac
 22  The unified attention system that wires everything together.
 23  
 24  This is the single entry point for the attention architecture.
 25  All subsystems are connected and events flow between them.
 26  
 27  Usage:
 28      system = UnifiedAttentionSystem(UnifiedAttentionConfig(
 29          sessions_dir="/path/to/sessions/",
 30          daily_notes_dir="/path/to/daily/"
 31      ))
 32  
 33      # Process incoming attention events
 34      system.record_attention(event)
 35  
 36      # Get unified state
 37      state = system.get_state()
 38  
 39      # Check for aha moments
 40      ahas = system.get_recent_ahas()
 41  
 42      # Run compaction
 43      system.compact_daily_note("2026-01-13.md")
 44  c� <�V^8�dQhRS[/#)r�config)r)r)r*s"�r+r,�#UnifiedAttentionSystem.__annotate__?s��� � �5� r.c��Wn\4wVnVn\	VP
 45  R7wVnVnVP'd0\VPVPR7wVnVn
MRVnRVn
\VP
 46  VPR7VnVP"'d\%4wVnVnMRVnRVnVP+4R#))r)�daily_note_path�
audio_enabledN)rr!)r=r�attention_tracker�daily_integrationrr�cross_session_tracker�session_watcherr"rr r%�aha_detector�aha_managerrr!�membraner#r�	compactor�daily_compactor�_wire_subsystems)�selfr=s&&r+�__init__�UnifiedAttentionSystem.__init__?s�����:Q�9R�6���� 6�;V��,�,�<
 47  �8��"�D�$8��&�&�&�2C� &� 6� 6�$�6�6�3�/�D��t�/�
 48  !%�D��#�D��.��,�,��,�,�
 49  ��
�
 50  �#�#�#�3K�3M�0�D�N�D�0�!�D�N�#'�D� �	
���r.c�<�V^8�dQhRR/#)r�returnNr/)r)r*s"�r+r,r>`s���
F�
F�$�
Fr.c�xa�SP'd'RV3RllpSPPV4R#R#)z3Connect the subsystems so events flow between them.c�R�V^8�dQhR\R\\,R\/#)r�topic�session_ids�	intensity)r&rr()r)s"r+r,�=UnifiedAttentionSystem._wire_subsystems.<locals>.__annotate__es%��
�
�c�
��S�	�
�e�
r.c�D<�SPPVVVR7R#)z1When sessions converge on a topic, check for aha.)rSrT�combined_intensityN)rF�detect_from_cross_session)rSrTrUrLs&&&�r+�on_convergence�?UnifiedAttentionSystem._wire_subsystems.<locals>.on_convergencees%����!�!�;�;�� +�'0�<�r.N)rFrDrZ)rLrZsf r+rK�'UnifiedAttentionSystem._wire_subsystems`s6�������
�
�
�&�&�5�5�n�E�r.Nc�*<�V^8�dQhRS[RS[RR/#)r�event�
 51  session_idrPN)rr&)r)r*s"�r+r,r>rs)���������
 52  �	r.c�X�VPPV4V'd�VP.p\VR4'd>VP'd,VPVPP
R.44VPPVVPVR7R#R#)a?
 53  Record an attention event.
 54  
 55  This feeds the event to all relevant subsystems:
 56  - Attention tracker (trajectory computation)
 57  - Cross-session tracker (if session_id provided)
 58  - Resonance check for aha detection
 59  
 60  Args:
 61      event: The attention event to record
 62      session_id: Optional session ID for cross-session tracking
 63  �metadata�topics)r_�	atom_uuidrbN)
 64  rB�record�target_type�hasattrra�extend�getrD�record_activity�	target_id)rLr^r_rbs&&& r+�record_attention�'UnifiedAttentionSystem.record_attentionrs���$	
���%�%�e�,���'�'�(�F��u�j�)�)�e�n�n�n��
�
�e�n�n�0�0��2�>�?��&�&�6�6�%��/�/��
7�
�
r.c
 65  �F<�V^8�dQhRS[RS[RS[RS[S[,RR/#)r�concept�resonance_before�resonance_after�related_conceptsrPN)r&r(r)r)r*s"�r+r,r>�sA������� ���	�
 66  �s�)��
 67  �
r.c�l�VP'd"VPPVVVVR7R#R#)zm
 68  Check if a resonance change indicates an aha moment.
 69  
 70  Call this when resonance scores change significantly.
 71  )rnrorprqN)rF�detect_from_resonance_spike)rLrnrorprqs&&&&&r+�check_for_resonance_aha�.UnifiedAttentionSystem.check_for_resonance_aha�s:���������9�9��!1� /�!1�	
:�
�r.c� <�V^8�dQhRS[/#�rrP�r)r)r*s"�r+r,r>�s���
 72  �
 73  ��
 74  r.c	��VPP4pVPP4Pp.pV'dVP
 75  P
V4pR\V4R\V4R\VPP4P4RVPP4P/#)z�
 76  Process updates from all session streams.
 77  
 78  This is the main loop method - call periodically to:
 79  1. Scan for new sessions
 80  2. Read new content from session files
 81  3. Detect cross-pollination
 82  4. Trigger aha detection
 83  
 84  Returns:
 85      Dict with processing stats
 86  �cross_events�membrane_signals�active_sessions�cross_session_attractors)
 87  rE�process_updatesrD�	get_state�
focus_sessionrH�get_signals_for_session�len�sessionsr})rLrzr�r{s&   r+�process_session_updates�.UnifiedAttentionSystem.process_session_updates�s����+�+�;�;�=���2�2�<�<�>�L�L�
����#�}�}�D�D�]�S��
�C��-���$4� 5��s�4�#=�#=�#G�#G�#I�#R�#R�S�&��(B�(B�(L�(L�(N�(g�(g�	
 88  �	
 89  r.c� <�V^8�dQhRS[/#rwrx)r)r*s"�r+r,r>�s���.�.�4�.r.c��VPP4pVPP4pRRVPRVP'dVPP
 90  M^RVPR,Uu.uFq3PNK	upR\VP4/RR\VP4R	VPR
 91  \VP4RVP/RR
VPPP //pVP"'d�VP"P%RR7pR\V4R\VP"P'44RVR,Uu.uF:pRVP(P RVP*R,RVP
 92  /NK<	up/VR&V#uupiuupi)z�
 93  Get the unified attention state across all subsystems.
 94  
 95  Returns a combined view of:
 96  - Current attention focus and trajectory
 97  - Cross-session state
 98  - Recent aha candidates
 99  - Membrane permeability status
100  �	attention�
current_focus�trajectory_confidence�active_wells:N�N�unresolved_count�
cross_sessionr|r��context_switches�
101  attractorsrHr!��?��min_confidence�
102  candidates�	validated�recent:N�N�type�summary:N�2N�
103  confidence�aha)rBrrDr��
104  trajectoryr��
gravity_wellsrSr��
105  unresolvedr�r��switch_historyr}r=r!�valuerF�get_recent_candidates�get_validated_ahas�aha_typer�)rL�attention_state�cross_state�w�state�recent_ahas�as&      r+r� UnifiedAttentionSystem.get_state�s����0�0�:�:�<���0�0�:�:�<��
���!>�!>�'�Ra�Rl�Rl�Rl��)C�)C�)N�)N�rs��/�2O�2O�PR�2S� T�2S�Q���2S� T�"�C��(B�(B�$C�	�
�!�3�{�';�';�#<���!:�!:�"�C��(B�(B�$C��k�B�B�	�
����� 8� 8� >� >��
106  ��$�����+�+�A�A�QT�A�U�K��c�+�.��S��!2�!2�!E�!E�!G�H��)��_�
�-��	��
107108  � 0� 0�!�1�9�9�S�>�$�a�l�l��
109  -�
��E�%�L����;!U��&s
�G�>AGc�&<�V^8�dQhRS[RS[/#)rr�rP)r(r)r)r*s"�r+r,r>�s�����e��d�r.c�b�VP'dVPPVR7#.#)zGet recent aha candidates.r�)rFr�)rLr�s&&r+�get_recent_ahas�&UnifiedAttentionSystem.get_recent_ahas�s-�������$�$�:�:�.�:�Y�Y��	r.c�&<�V^8�dQhRS[RS[/#)r�
note_filenamerP)r&r)r)r*s"�r+r,r>�s���
110  �
111  ��
112  ��
113  r.c���VP'gRR/#\VPP4V,pVP	4'gRRV2/#VPP\
V44pRVPRVPRR\RVP44R	\R
114  VP44R\RVP44//#)
zd
115  Run compaction on a daily note.
116  
117  Uses attention scores to decide what to keep, summarize, or drop.
118  �errorzCompaction not enabledzNote not found: �original_items�after_compaction�	decisions�keptc3�J"�TFqPR8XgK^x�K	R#5i)�keepN��action��.0�ds& r+�	<genexpr>�<UnifiedAttentionSystem.compact_daily_note.<locals>.<genexpr>s���N�'7�!�8�8�v�;M�A�A�'7���#�
119  #�
120  summarizedc3�J"�TFqPR8XgK^x�K	R#5i)�	summarizeNr�r�s& r+r�r�
s���!Y�-=����[�AX�!�!�-=�r��droppedc3�J"�TFqPR8XgK^x�K	R#5i)�dropNr�r�s& r+r�r�s���Q�*:�Q�h�h�&�>P�q�q�*:�r�)rJr	r=r �exists�compact_daily_noter&�original_count�final_count�sumr�)rLr��	note_path�results&&  r+r��)UnifiedAttentionSystem.compact_daily_note�s����#�#�#��5�6�6�����4�4�5�
�E�	����!�!��/�	�{�;�<�<��%�%�8�8��Y��H���f�3�3��� 2� 2����N�v�'7�'7�N�N��c�!Y�V�-=�-=�!Y�Y��3�Q�&�*:�*:�Q�Q��
121  �	
122  r.c� <�V^8�dQhRS[/#rw)r&)r)r*s"�r+r,r>s���0 �0 �3�0 r.c
123  ���VP4pRR.pVR,R,'d=VR,R,pVPRVPRVPR24VR,R,^8�d$VPR	VR,R,R
124  
24VR,R,'d4RP	VR,R,4pVPR
V24VR,R,^8�d#VPRVR,R,24VPR4VPR4VPRVR,R,24VPRVR,R,24VR,R,'d4RP	VR,R,4pVPRV24RV9d�VR,R,^8�dvVPR4VPR4VR,R,F?pVR,R8XdRMRpVPR VR!VR",R
125  
R#VR$,R%24KA	R&P	V4#)'zz
126  Generate a daily attention summary for the daily note.
127  
128  Returns markdown content suitable for injection into daily note.
129  z## Attention State�r�r�z**Current Focus**: z (�)r�z**Trajectory Confidence**: z.0%r�z, z**Active Gravity Wells**: r�z**Unresolved Items**: z### Cross-Sessionz- Active sessions: r�r|z- Context switches: r�r�z - **Cross-session attractors**: r�r�z### Aha Momentsr�r��	discoveryu💡u🔧z- z [r�z] r�z...�
130  )r�appendre�modality�join)rLr��lines�focus�	wells_strr�r��emojis&       r+�get_daily_summary�(UnifiedAttentionSystem.get_daily_summarysE����� ��
!��
131  �����o�.�.��+�&��7�E��L�L�.�u�/@�/@�.A��E�N�N�CS�ST�U�V����5�6��:��L�L�6�u�[�7I�Ja�7b�cf�6g�h�i����n�-�-��	�	�%��"4�^�"D�E�I��L�L�5�i�[�A�B����0�1�A�5��L�L�1�%��2D�EW�2X�1Y�Z�[�	���R��
���(�)�
���*�5��+A�BS�+T�*U�V�W�
���+�E�/�,B�CU�,V�+W�X�Y���!�,�/�/����5��#9�,�#G�H�J��L�L�;�J�<�H�I��E�>�e�E�l�<�8�1�<��L�L����L�L�*�+��U�|�H�-�-��"%�f�+��"<��&�����r�%���3�|�+<�S�*A��C�	�N�CS�SV�W�X�.��y�y���r.)
132  rFrGrBrIr=rDrJrCrHrE)N)r�)r0r1r2r3r4rMrKrkrtr�rr�r�r�r7r8r9s@r+r;r;%si�����2 � �B
F�
F�$��B��(
133  �
134  �:.�.�`��
135  �
136  �00 �0 r.r;c�H�V^8�dQhR\R\R\R\/#)rrr r!rP)r&rr;)r)s"r+r,r,Es0��*�*��*��*�$�*��	*r.c�4�\VVVR7p\V4#)z�
137  Create a unified attention system.
138  
139  Args:
140      sessions_dir: Path to session stream files
141      daily_notes_dir: Path to daily notes
142      permeability: How much context crosses between sessions
143  
144  Returns:
145      Configured UnifiedAttentionSystem
146  )rr r!)rr;)rr r!r=s&&& r+�create_unified_systemr�Es$�� $�!�'�!��F�
147  "�&�)�)r.�__main__z!=== Unified Attention System ===
148  z'Attention is all you need'
149  zCreating unified system...z3/Users/rcerf/repos/Sovereign_Estate/daily/sessions/z*/Users/rcerf/repos/Sovereign_Estate/daily/)rr z
150  Processing session updates...z  Active sessions: r|z  Cross-session events: rzz  Cross-session attractors: r}z
151  Generating daily summary...z
152  === Unified System Ready ===N)-r4�dataclassesrrr�typingrrrr�pathlibr	�trackerr
153  rrr�r
rr�
aha_detectionrrrrrrHrrr�
154  compactionrrrrr;r5r�r0�print�systemr��statsr�r�r/r.r+�<module>r�s/��
155  �)��.�.��N�N�a�a�k�k�P�P�X�X��$�$��$�] �] �F	'8�&B�&B�*�0�z��	�
156  .�/�	�
157  )�*�
158159  &�'�
"�J�D��F�
160  
161162  +�,��*�*�,�E�	���&7� 8�9�
163  :�;�	�$�U�>�%:�$;�
164  <�=�	�(��/I�)J�(K�
165  L�M�	�
166  )�*��&�&�(�G�	�'�N�	�
167  *�+�+r.