/ core / attention / __pycache__ / loop.cpython-314.pyc
loop.cpython-314.pyc
  1  +
  2  $*gi24�	���Rt^RIHtHt^RIHtHt^RIHtHtH	t	H
  3  t
  4  Ht^RIH
t
^RIt^RIHtHtHtHt^RIHt]!RR	44t]!R
  5  R44t!RR
4tRRlt]R8Xd�^RIt]!R4Rt]!]R7t]P?]!RRR^<R74]!R]24]!R] !]PBPE4424Rt#]PH!]#!44]!R4R#R#)a�
  6  Attention Loop - The Actuator
  7  
  8  This is what makes the attention system actually DO something.
  9  The loop continuously:
 10  1. Pulls attention signals from all sources
 11  2. Records them in the tracker
 12  3. Computes what should surface
 13  4. Updates the daily note
 14  5. Triggers follow-on actions (surfacing, notifications, etc.)
 15  
 16  The key insight: attention tracking without actuation is just logging.
 17  The loop is what closes the feedback cycle.
 18  
 19  Integration points:
 20  - God Database: persists attention events
 21  - Resonance Engine: computes scores for surfacing decisions
 22  - Daily Note: the single pane where everything surfaces
 23  - Flight Protocol: adapts behavior based on cognitive phase
 24  )�	dataclass�field)�datetime�	timedelta)�Optional�List�Dict�Any�Callable)�PathN)�AttentionTracker�AttentionEvent�AttentionState�DailyNoteIntegration)�OvercastParserc�@a�]tRt^%toRtRtRtRtRtV3Rlt	Rt
 25  VtR#)�AttentionSourcez&Configuration for an attention source.N�,Tc�<�V^8�dQh/S[;R&S[;R&S[S[,;R&S[;R&S[S[,;R&S[;R&#)��name�source_type�path�poll_interval_seconds�	last_poll�enabled)�strr�intr�bool)�format�
__classdict__s"��6/Users/rcerf/repos/Sovereign_OS/core/attention/loop.py�__annotate__�AttentionSource.__annotate__%s[�����I����	�
 26  �3�-����$�
���!�(������)�__name__�
 27  __module__�__qualname__�__firstlineno__�__doc__rrrr�__annotate_func__�__static_attributes__�__classdictcell__�r s@r!rr%s&����0��D�!$��$(�I��G��r$rc�0a�]tRt^0toRtV3RltRtVtR#)�SurfacingActionz%An action to take based on attention.c�V<�V^8�dQh/S[;R&S[;R&S[;R&S[;R&S[;R&#)r�action_type�target�content�priority�reason)r�float)rr s"�r!r"�SurfacingAction.__annotate__0sB�������
�K�	�
 28  �L���O�
�
�K�r$r%N)r&r'r(r)r*r+r,r-r.s@r!r0r00s����/��r$r0c�(a�]tRt^:toRtR V3RlRlltV3RlRltV3RlRltV3RlR	ltV3R
 29  lRlt	R!V3RlR
llt
 30  V3RlRltV3RlRltV3RlRlt
V3RlRltV3RlRltV3RlRltV3RlRltV3RlRltRtVtR#)"�
AttentionLoopa@
 31  The main attention processing loop.
 32  
 33  Continuously:
 34  1. Polls attention sources for new events
 35  2. Records events in the tracker
 36  3. Computes surfacing actions
 37  4. Executes actions (update daily note, notify, etc.)
 38  
 39  Usage:
 40      loop = AttentionLoop(
 41          daily_note_path="/path/to/daily/2026-01-13.md"
 42      )
 43  
 44      # Add sources
 45      loop.add_source(AttentionSource(
 46          name="overcast",
 47          source_type="podcast",
 48          path="~/Downloads/overcast.opml"
 49      ))
 50  
 51      # Run the loop (blocks)
 52      await loop.run()
 53  
 54      # Or run one iteration
 55      actions = await loop.tick()
 56  c�,<�V^8�dQhRS[RS[RS[/#)r�daily_note_path�history_size�min_resonance_to_surface)rrr7)rr s"�r!r"�AttentionLoop.__annotate__Ws.���G�G��G��G�#(�	Gr$c�4�\V4VnW0n\VR7Vn\VP\
VP44Vn/VnRVPRVP/VnRVnRVn
.Vn.VnR#))r=�add_to_daily�logFN)rr<r>r�trackerrr�daily_integration�sources�_handle_add_to_daily�_handle_log�_action_handlers�_running�
 57  _last_tick�
_on_attention�_on_surface)�selfr<r=r>s&&&&r!�__init__�AttentionLoop.__init__Ws��� $�O�4���(@�%�(�\�B���!5��L�L���$�$�%�"
 58  ���46���
�D�5�5��4�#�#�6
 59  �����
�.2���FH���DF��r$c�$<�V^8�dQhRS[RR/#)r�source�returnN)r)rr s"�r!r"r?xs���+�+��+�T�+r$c�6�WPVP&R#)z Add an attention source to poll.N)rEr)rMrQs&&r!�
 60  add_source�AttentionLoop.add_sourcexs��$*���V�[�[�!r$c�$<�V^8�dQhRS[RR/#)rrrRN)r)rr s"�r!r"r?|s���%�%�#�%�$�%r$c�>�VPPVR4R#)zRemove an attention source.N)rE�pop)rMrs&&r!�
remove_source�AttentionLoop.remove_source|s��������t�$r$c�:<�V^8�dQhRS[S[.R3,RR/#�r�callbackNrR)r
 61  r
)rr s"�r!r"r?�s(���,�,�X�~�.>��.D�%E�,�$�,r$c�<�VPPV4R#)z'Register callback for attention events.N)rK�append�rMr]s&&r!�on_attention�AttentionLoop.on_attention�s�����!�!�(�+r$c�:<�V^8�dQhRS[S[.R3,RR/#r\)r
 62  r0)rr s"�r!r"r?�s(���*�*�8�_�,=�t�,C�#D�*��*r$c�<�VPPV4R#)z(Register callback for surfacing actions.N)rLr_r`s&&r!�
 63  on_surface�AttentionLoop.on_surface�s��������)r$c�$<�V^8�dQhRS[RR/#)r�tick_interval_secondsrRN)r)rr s"�r!r"r?�s���7�7�s�7�D�7r$c��d"�RVn\RVR24VP'dZVP4GRjx�L
 64  pV'd\R\V4R24\
 65  P!T4GRjx�L
 66  KkR#LF \dp\RT24Rp?LBRp?ii;iL05i)zj
 67  Run the attention loop continuously.
 68  
 69  Args:
 70      tick_interval_seconds: How often to check for new events
 71  Tz([AttentionLoop] Starting loop, interval=�sNz[AttentionLoop] Tick produced z actionsz[AttentionLoop] Error in tick: )rI�print�tick�len�	Exception�asyncio�sleep)rMrh�actions�es&&  r!�run�AttentionLoop.run�s������
�
�8�9N�8O�q�Q�R��m�m�m�
=� $�	�	��+����:�3�w�<�.��Q�R��-�-� 5�6�6�6��+���
=��7��s�;�<�<��
=��
7�sQ�(B0�B�B�B�B�$B0�=B.�>B0�B�B+�B&�!B0�&B+�+B0c�<�V^8�dQhRR/#)rrRNr%)rr s"�r!r"r?�s�����d�r$c��RVnR#)zStop the attention loop.FN)rI)rMs&r!�stop�AttentionLoop.stop�s	����
r$c�0<�V^8�dQhRS[S[,/#)rrR)rr0)rr s"�r!r"r?�s���4�4�D��1�4r$c���"�\P!4Vn.pVPP	4F�pVP
 72  'gKVP'dG\P!4VP,
 73  P4pW2P8dKoVPV4GRjx�L
 74  p\P!4VnVF:pVPPV4VPFpV!V4K	K<	K�	VPP4pVP!V4p	V	FIp
 75  VP#V
 76  4GRjx�L
 77  VP%V
 78  4VP&FpV!V
 79  4K	KK	V#L� \dp\RT24Rp?K�Rp?ii;iL` \dp\RT24Rp?K`Rp?ii;i5i)zX
 80  Run one iteration of the attention loop.
 81  
 82  Returns:
 83      List of surfacing actions taken
 84  Nz [AttentionLoop] Callback error: z([AttentionLoop] Surface callback error: )r�nowrJrE�valuesrr�
total_secondsr�_poll_sourcerC�recordrKrnrk�	get_state�_compute_actions�_execute_actionr_rL)rM�all_actionsrQ�elapsed�events�eventr]rr�staterq�actions&          r!rl�AttentionLoop.tick�s����#�,�,�.������l�l�)�)�+�F��>�>�>������#�<�<�>�F�,<�,<�<�K�K�M���9�9�9�� �,�,�V�4�4�F�'�|�|�~�F�� �����#�#�E�*�!%� 2� 2�H�F� ���!3�	 �,�4���&�&�(���'�'��.���F��&�&�v�.�.�.����v�&�!�,�,��J��V�$�-����=5��%�F�� @���D�E�E��F��
/��!�J��D�Q�C�H�I�I��J�s{�AG-�"AG-�<F�=A
G-�F�AG-�#G�$$G-�	G�G-�G	�(F<	�6G-�<G	�G-�G*�G%�G-�%G*�*G-c�6<�V^8�dQhRS[RS[S[,/#�rrQrR�rrr
)rr s"�r!r"r?�s ���
�
��
�T�.�=Q�
r$c���"�.pVPR8Xd.VP'dVPV4GRjx�L
 85  pV#VPR8XdV#VPR8XdV#L.5i)z'Poll a source for new attention events.�podcastN�conversation�browser)rr�
_poll_podcast)rMrQr�s&& r!r~�AttentionLoop._poll_source�sq���������*�v�{�{�{��-�-�f�5�5�F��
��
�
�>�
1��
 86  �
�	�
�
�9�
,���
�6�s�%A-�A-�A+�/A-c�6<�V^8�dQhRS[RS[S[,/#r�r�)rr s"�r!r"r?�s �����/��d�>�>R�r$c��D"�.p\VP4P4pVP4'gV#\	\V44pVP
^^R7pVF�p\VP;'g\P!4VPRRVP'd
VPMRVP'dRMRRR7pVPV4K�	V# \dp\!R	T24Rp?T#Rp?ii;i5i)
 87  z$Poll podcast source (Overcast OPML).)�days�limit�episode�listenNg�?��?r�)�	timestamp�	target_id�target_type�modality�duration_seconds�	intensityrQz'[AttentionLoop] Error polling podcast: )rr�
 88  expanduser�existsrr�get_recently_playedr
�user_updated_daterr{�overcast_id�played�progress_secondsr_rnrk)	rMrQr�r�parser�recentr�r�rrs	&&       r!r��AttentionLoop._poll_podcast�s�������F�K�K� �+�+�-���{�{�}�}��M�	A�#�C��I�.�F��/�/�Q�b�/�A�F�!��&�%�7�7�I�I�8�<�<�>�%�1�1� )�%�AH����W�%=�%=�UY�%,�^�^�^�c��$����
�
�e�$�"� �
���	A��;�A�3�?�@�@��
��	A�sB�>D �AC9�3C9�9C9�C9�7D �9D�D�D �D�D c�6<�V^8�dQhRS[RS[S[,/#)rr�rR)rrr0)rr s"�r!r"r?s ���#�#�n�#��o�9N�#r$c�B�.pVPF%pVP\RVRV2RRR74K'	VP'dcVPP'dGVPPR,F%pVP\RVRV2RR	R74K'	VP
 89  'dbVP\R
 90  VP
 91  PRVP
 92  PRVP
 93  P2R
RR74V#)z6Compute what actions to take based on attention state.rAzUnresolved: g�������?zOn nag list - unresolved)r2r3r4r5r6:N�NzAhead on trajectory: g333333�?z In direction of attention travelrBzFocus: z via g333333�?zCurrent attention focus)	�
 94  unresolvedr_r0�
 95  trajectory�ahead�focusr�r�r�)rMr�rqr�s&&  r!r��AttentionLoop._compute_actionss	�����)�)�I��N�N�?�*� �&�y�k�2��1��
�*������ 0� 0� 6� 6� 6�"�-�-�3�3�B�7�7�	����� .�$�3�I�;�?� �=� ��8��;�;�;��N�N�?�!��{�{�,�,�!�%�+�+�"9�"9�!:�%����@T�@T�?U�V��0��
��r$c�$<�V^8�dQhRS[RR/#�rr�rRN�r0)rr s"�r!r"r?(s���"�"�O�"��"r$c��"�VPPVP4pV'dV!V4GRjx�L
 96  R#R#L5i)zExecute a surfacing action.N)rH�getr2)rMr��handlers&& r!r��AttentionLoop._execute_action(s9����'�'�+�+�F�,>�,>�?����&�/�!�!��!�s�9A�A�	Ac�$<�V^8�dQhRS[RR/#r�r�)rr s"�r!r"r?.s���(5�(5��(5�T�(5r$c���"�VPP4'gR#VPP4pRV9dORV9dVPRR4pM4VP	R4pVP^R4RP
V4pRVPR
R	VPR
 97  VPR2pRpVPV4pV^8�d�V\V4,pV\V48dW',R8XdV^,
pK(W'V^,R
8Xd#VPRV4pV^8�d
 98  V^,pVRVV,W'R,pVPPV4R#R#5i)zAdd an item to the daily note.Nz## Attention Surfacez## Action ItemszO## Attention Surface
 99  
100  *Auto-surfaced by attention system*
101  
102  ---
103  
104  ## Action Items�
105  z;
106  ## Attention Surface
107  
108  *Auto-surfaced by attention system*
109  z- [z.1f�] z *(reason: z)*
110  z## Attention Surface
111  �*)
r<r��	read_text�replace�split�insert�joinr5r4r6�findrm�
112  write_text)	rMr�r4�lines�	item_line�marker�idx�insert_point�next_newlines	&&       r!rF�"AttentionLoop._handle_add_to_daily.se����#�#�*�*�,�,���&�&�0�0�2��"��0� �G�+�!�/�/�%�k��� �
�
�d�+�����Q� a�b��)�)�E�*���&�/�/�#�.�b����0@��F�M�M�?�Z^�_�	�*���l�l�6�"���!�8���V��,�L���W��-�'�2G�4�2O���!���L�1�$4�5��<�&�|�|�D�,�?���1�$�#/�!�#3�L��m�|�,�y�8�7�=�;Q�Q�G�� � �+�+�G�4��s�E7E9c�$<�V^8�dQhRS[RR/#r�r�)rr s"�r!r"r?Xs���/�/��/�D�/r$c��>"�\RVP24R#5i)zLog an attention event.z[Attention] N)rkr4)rMr�s&&r!rG�AttentionLoop._handle_logXs���
��V�^�^�,�-�.�s�)
113  rHrJrKrLrIrDr<r>rErCN)�dr�)�<)r&r'r(r)r*rNrTrYrarersrwrlr~r�r�r�rFrGr,r-r.s@r!r:r::s������8G�G�B+�+�%�%�,�,�*�*�7�7�(��4�4�l
�
���<#�#�J"�"�(5�(5�T/�/r$r:c�0�V^8�dQhR\R\/#)r�daily_note_dirrR)rr:)rs"r!r"r"]s������
�r$c	���\P!4PR4p\V4VR2,p\	\V4R7pVP
\RRRRR74V#)	z�
114  Create an attention loop with default sources.
115  
116  Args:
117      daily_note_dir: Directory containing daily notes (e.g., Sovereign_Estate/daily/)
118  
119  Returns:
120      Configured AttentionLoop
121  z%Y-%m-%dz.md�r<�overcastr��~/Downloads/overcast.opmlr�rrrr)rr{�strftimerr:rrTr)r��todayr<�loops&   r!�create_default_loopr�]sf��
�L�L�N�#�#�J�/�E��>�*��w�c�]�:�O���_�)=�>�D�	�O�O�O�
��
(�!�	���Kr$�__main__z=== Attention Loop Test ===
122  z7/Users/rcerf/repos/Sovereign_Estate/daily/2026-01-13.mdr�r�r�r�r�zDaily note: z	Sources: c���"�\P4GRjx�L
123  p\R\V4R24VF0p\RVPRVP
124  R,R24K2	R#LT5i)Nz
125  Tick produced z	 actions:z  - [r�:N�2Nz...)r�rlrkrmr2r4)rqr�s  r!�	test_tickr��s`����	�	��#��
� ��W���i�8�9��F��E�&�,�,�-�R����s�0C�/D�C�H�I��$�s�A1�A/�AA1z
126  === Test Complete ===)%r*�dataclassesrrrr�typingrrrr	r
127  �pathlibrrorCrr
rr�podcast_pipelinerrr0r:r�r&�sysrk�
128  test_dailyr�rT�listrE�keysr�rsr%r$r!�<module>r�s���*)�(�6�6�����-�����������`/�`/�F	�@�z���	�
129  )�*�K�J���4�D�	�O�O�O�
��
(� �	��
130  �L���
131  %�&�	�I�d�4�<�<�,�,�.�/�0�
132  1�2�J��K�K�	���	�
133  #�$�;r$