/ core / attention / __pycache__ / session_injection.cpython-314.pyc
session_injection.cpython-314.pyc
  1  +
  2  l�hi�G�
  3  ��Rt^RIHtHt^RIHt^RIHtHtHtH	t	^RI
  4  Ht^RIt^RI
HtHt^RIHtHtHt]	'd^RIHtHt^R	IHt]!R
  5  R44t]!RR
44t!RR4t]P8RR3RRlltR+RRllt]R8XEd^RI t ^RI!t!]"!R4]#!]!PH!44R,t%Rt&]"!R]%R24]!]&]%RRRRRR /R!7wtt'tR"t(R#t)]PU](4]PW])4]"!R$4]"!R%4] PX!^4]"!R&4]'P[]%4t.].'d
  6  ]"!].4M]"!R'4]"!R(4]'P_]%4t0]0'd]"!]04Kp]"!R)4KzR# ]1dMi;i]Pe4]"!R*4R#),u�	
  7  Session Injection - Injects cross-session awareness into active sessions.
  8  
  9  This is the actuator that makes sessions aware of each other.
 10  When convergence is detected, this module injects a signal into
 11  the session context so the AI sees it.
 12  
 13  Methods of injection:
 14  1. System message injection (via hooks)
 15  2. Session file annotation (append to live.md)
 16  3. MCP tool response (if MCP server running)
 17  4. Gaze-based attention signals (what you're looking at)
 18  
 19  Integration with eye tracking:
 20  - The orchestrator tracks where you're looking
 21  - Gaze fixations on code/UI regions become attention signals
 22  - These signals cross the membrane to other sessions
 23  - Other Claude instances become aware of your visual focus
 24  
 25  Architecture:
 26      ┌─────────────────────────────────────────────────────────┐
 27      │                     SessionInjector                      │
 28      │                                                          │
 29      │  ┌──────────────┐  ┌──────────────┐  ┌───────────────┐  │
 30      │  │ Cross-Session│  │   Session    │  │  Attention    │  │
 31      │  │   Tracker    │  │   Membrane   │  │  Orchestrator │  │
 32      │  └──────┬───────┘  └──────┬───────┘  └───────┬───────┘  │
 33      │         │                 │                   │          │
 34      │         └─────────────────┼───────────────────┘          │
 35      │                           ▼                              │
 36      │              ┌────────────────────────┐                  │
 37      │              │    Injection Engine    │                  │
 38      │              │  - System messages     │                  │
 39      │              │  - File annotations    │                  │
 40      │              │  - Gaze awareness      │                  │
 41      │              └────────────────────────┘                  │
 42      └─────────────────────────────────────────────────────────┘
 43  )�	dataclass�field)�datetime)�List�Optional�Dict�
TYPE_CHECKING)�PathN)�CrossSessionTracker�CrossSessionEvent)�SessionMembrane�PermeabilityLevel�CrossSessionSignal)�AttentionOrchestrator�FusedAttentionEvent)�AttentionScreenc�Ba�]tRt^6toRt]!]R7tV3RltRt	Vt
 44  R#)�InjectionEventz+Record of a signal injected into a session.��default_factoryc�f<�V^8�dQh/S[;R&S[;R&S[;R&S[;R&S[S[,;R&#)��	timestamp�
 45  session_id�signal_type�content�source_sessions)r�strr)�format�
__classdict__s"��C/Users/rcerf/repos/Sovereign_OS/core/attention/session_injection.py�__annotate__�InjectionEvent.__annotate__6sH��������O�	�
 46  ����L�
��#�Y�<���N)�__name__�
 47  __module__�__qualname__�__firstlineno__�__doc__r�listr�__annotate_func__�__static_attributes__�__classdictcell__�rs@r rr6s����5�
 48  "'�t�!<�O��r#rc�xa�]tRt^@toRtRtRtRt^t]	!]
 49  PR7tV3RlRlt
V3RltRtVtR#)	�GazeAwarenessStatez*Tracks gaze-based attention for injection.�centerNrc� <�V^8�dQhRS[/#�r�return�r)rrs"�r r!�GazeAwarenessState.__annotate__Is���!�!�3�!r#c��RVP2.pVP'dVPRVP24VP'dVPRVP24RP	V4#)z'Format as awareness line for injection.zScreen: zApp: zRegion: � | )�current_screen�current_app�append�current_region�join)�self�partss& r �to_awareness_line�$GazeAwarenessState.to_awareness_lineIss���D�/�/�0�1�2�������L�L�5��!1�!1� 2�3�4������L�L�8�D�$7�$7�#8�9�:��z�z�%� � r#c�v<�V^8�dQh/S[;R&S[S[,;R&S[S[,;R&S[;R&S[;R&#)rr9r:r<�fixation_count�last_update)rr�intr)rrs"�r r!r6@sN�����"���#��%�	�
 50  �S�M�(����
��?�r#r$)r%r&r'r(r)r9r:r<rCrr�nowrDr@r+r,r-r.s@r r0r0@s;����4�"�N�!%�K�$(�N��N�!�(�,�,�?�K�!�!��r#r0c��a�]tRt^StoRtV3RlRltV3RlRltV3RlRltV3RlR	ltV3R
 51  lRlt	V3RlR
lt
 52  V3RlRltV3RlRltV3RlRlt
V3RlRltRtVtR#)�SessionInjectorai
 53  Injects cross-session awareness signals into active sessions.
 54  
 55  Now includes gaze-based attention awareness from the orchestrator.
 56  
 57  Usage:
 58      injector = SessionInjector(
 59          sessions_dir="/path/to/sessions/",
 60          tracker=cross_session_tracker,
 61          membrane=session_membrane
 62      )
 63  
 64      # Connect to attention orchestrator for gaze awareness
 65      injector.connect_orchestrator(orchestrator)
 66  
 67      # Generate injection content for current session
 68      content = injector.get_injection_for_session("current_session_id")
 69  
 70      # Or write directly to session file
 71      injector.inject_to_session_file("session_id")
 72  c�,<�V^8�dQhRS[RS[RS[/#)r�sessions_dir�tracker�membrane)rr
 73  r)rrs"�r r!�SessionInjector.__annotate__js.���E�E��E�%�E�"�	Er#c��\V4VnW nW0n.Vn/Vn^<Vn\4VnRVn	R#)�<N)
 74  r	rJrKrL�_injection_history�_last_injection�injection_cooldown_secondsr0�_gaze_state�
_orchestrator)r>rJrKrLs&&&&r �__init__�SessionInjector.__init__jsJ��!��.����� �
�8:���46���+-��'�.�/���@D��r#c�"<�V^8�dQhRRRR/#)r�orchestratorrr4Nr$)rrs"�r r!rM}s���
 75  >�
 76  >�1H�
 77  >�T�
 78  >r#c�~�WnVPVP4VPVP4R#)z�
 79  Connect to the attention orchestrator for gaze-based awareness.
 80  
 81  This enables injection of what you're looking at into sessions.
 82  N)rT�on_attention_change�_on_attention_change�on_screen_change�_on_screen_change)r>rXs&&r �connect_orchestrator�$SessionInjector.connect_orchestrator}s4��*��	�(�(��)B�)B�C��%�%�d�&<�&<�=r#c�"<�V^8�dQhRRRR/#)r�eventrr4Nr$)rrs"�r r!rM�s���6�6�*?�6�D�6r#c�J�VPPVPnVPVPnVPVPnVP;P^,
un\P!4VPnR#)z*Handle attention change from orchestrator.N)�screen�valuerSr9�app_namer:�
target_regionr<rCrrFrD)r>ras&&r r[�$SessionInjector._on_attention_change�sk��*/�,�,�*<�*<����'�',�~�~����$�*/�*=�*=����'����'�'�1�,�'�'/�|�|�~����$r#c�(<�V^8�dQhRRRS[RR/#)rrcr�namer4Nr5)rrs"�r r!rM�s#���
 83  �
 84  �(9�
 85  ��
 86  ��
 87  r#c	��W PnVPP\	\
 88  P!4RRRV2R74R#)z'Handle screen change from orchestrator.��
screen_changezOperator attention moved to: )rrrrN)rSr9rPr;rrrF)r>rcris&&&r r]�!SessionInjector._on_screen_change�sD��*.���'�	
���&�&�~��l�l�n��'�3�D�6�:�	(
 89  �	r#c�&<�V^8�dQhRS[RS[/#�rrr4�r�bool)rrs"�r r!rM�s���:�:��:��:r#c��VPPV4pV'gR#\P!4V,
 90  P	4pW0P
 91  8�#)z;Check if we should inject to this session (cooldown check).T)rQ�getrrF�
total_secondsrR)r>r�last�elapseds&&  r �
should_inject�SessionInjector.should_inject�sF���#�#�'�'�
 92  �3�����<�<�>�D�(�7�7�9���9�9�9�9r#c�6<�V^8�dQhRS[RS[S[,/#ro�rr)rrs"�r r!rM�s���* �* �C�* �H�S�M�* r#c�&�VPV4'gR#VPPV4pV'gR#VPP	4pVP
 93  pRRR\P!4PR4R2R.pV'dyVUu.uF)qf'gK\V4^8�gKRV9gK'VNK+	ppV'd<VPRR	PVR
 94  ,424VPR4VR,F=pVPRVPR
,RVPR,R24K?	VPR4VPR4RPV4#uupi)zn
 95  Generate injection content for a session.
 96  
 97  Returns markdown content to inject, or None if nothing to inject.
 98  Nrkz---z**Cross-Session Awareness** _z%H:%M�_�
 99  z**Hot across sessions**: �, �N�N:N�Nz- From `�N�Nz`: :N�PN�...)rwrL�get_signals_for_sessionrK�	get_state�cross_session_attractorsrrF�strftime�lenr;r=�source_sessionr)	r>r�signals�state�
100  attractors�lines�a�clean_attractors�signals	&&       r �get_injection_for_session�)SessionInjector.get_injection_for_session�s^���!�!�*�-�-���-�-�7�7�
101  �C�������&�&�(���3�3�
102  �
��+�H�L�L�N�,C�,C�G�,L�+M�Q�O��	
103  ���+5�\�:�a���s�1�v��z��d�Z[�m���:��\�����8����CS�TV�CW�9X�8Y�Z�[����R� ��b�k�k�F��L�L�8�F�$9�$9�"�$=�#>�c�&�.�.�QT�BU�AV�VY�Z�[�"�	���U��
���R���y�y����� ]s�	F�+
F�=F�Fc�&<�V^8�dQhRS[RS[/#rorp)rrs"�r r!rM�s��������r#c
104  ���VPV4pV'gR#\VPPRVR244pV'gR#V^,p\	VR4;_uu_4pVPV4RRR4VPP\\P!4VRVR,.R74\P!4VPV&R	# +'giLw;i)
105  z~
106  Inject cross-session awareness directly into a session file.
107  
108  This appends to the -live.md file so it appears in the stream.
109  F�*z	*-live.mdr�N�convergence:N�dN)rrrrrT)r�r*rJ�glob�open�writerPr;rrrFrQ)r>rr�
session_files�session_file�fs&&    r �inject_to_session_file�&SessionInjector.inject_to_session_file�s����0�0��<�����T�.�.�3�3�a�
110  �|�9�4M�N�O�
���$�Q�'���,��
$�
$��
�G�G�G��%�	
���&�&�~��l�l�n�!�%��D�M��(
111  �	�,4�<�<�>����Z�(��%�
$�s�+C,�,C<	c�6<�V^8�dQhRS[RS[S[,/#rorz)rrs"�r r!rM�s���% �% �#�% �(�3�-�% r#c�l�VPP4p.pVPP4Uu.uF
qDV8wgKVNK	ppVPpVUu.uF)qw'gK\V4^8�gKRV9gK'VNK+	ppV'g	V'dzVP
R4V'd+VP
RRPVR,424V'dVP
R\V424VP
R4VP'd�\P!4VPP,
112  P4p	V	^8d�VP
R4VP
R	4VP
R
113  VPP424VPP^8�d)VP
RVPP24VP
R4V'gR
#RPV4#uupiuupi)z�
114  Generate a system message for injection via hooks.
115  
116  This can be used by Claude Code hooks to inject awareness.
117  Now includes gaze-based attention awareness.
118  r}z<cross-session-awareness>zTopics active across sessions: r~rzOther active sessions: z</cross-session-awareness>rkz<operator-attention>zCurrent focus: zFixation count this session: z</operator-attention>N)rKr��sessions�keysr�r�r;r=rTrrFrSrDrtr@rC)
119  r>rr�r��s�other_sessionsr�r�r��recencys
120  &&        r �generate_system_message�'SessionInjector.generate_system_message�s������&�&�(����&+�^�^�%8�%8�%:�N�%:��:�o�!�!�%:��N��3�3�
121  �'1�X�z�!�Q�A�3�q�6�A�:�A�$�VW�-�A�A�z��X��~��L�L�4�5�����>�t�y�y�IY�Z\�I]�?^�>_�`�a�����6�s�>�7J�6K�L�M��L�L�5�6������|�|�~��(8�(8�(D�(D�D�S�S�U�G���|����R� ����3�4�����t�/?�/?�/Q�/Q�/S�.T�U�V��#�#�2�2�Q�6��L�L�#@��AQ�AQ�A`�A`�@a�!b�c����4�5����y�y�����5O��Xs#�H,�H,�	H1�,
H1�>H1�H1c�0<�V^8�dQhRS[S[,/#r3)rr)rrs"�r r!rMs��� � �x��}� r#c�B�VP'gR#\P!4VPP,
122  P4pV^<8�dR#RRVPP2.pVPP'd)VPRVPP24VPP'd)VPRVPP24VPR4RPV4#)zs
123  Generate a gaze-awareness block for Claude context.
124  
125  This tells Claude what the operator is currently looking at.
126  Nz<gaze-awareness>z"Operator is currently looking at: zActive application: zFocused region: z</gaze-awareness>r})rTrrFrSrDrtr9r:r;r<r=)r>r�r�s&  r �generate_gaze_awareness_block�-SessionInjector.generate_gaze_awareness_blocks����!�!�!���<�<�>�D�$4�$4�$@�$@�@�O�O�Q���R�<��
�0��1A�1A�1P�1P�0Q�R�
127  ��
128  ���'�'�'��L�L�/��0@�0@�0L�0L�/M�N�O����*�*�*��L�L�+�D�,<�,<�,K�,K�+L�M�N�
���(�)��y�y���r#c�&<�V^8�dQhRS[RS[/#ror5)rrs"�r r!rM4s���3�3�c�3�c�3r#c��.pVPV4pV'dVPV4VP4pV'd"YC;'gR9dVPV4VPP	V4pVP
129  'd VPVP
44V'dRPV4#R#)zx
130  Get unified context combining cross-session and gaze awareness.
131  
132  This is the complete injection payload for a session.
133  rkz
134  
135  )r�r;r�rL�get_context_for_sessionr��to_context_blockr=)r>rr?�sys_msg�
136  gaze_block�membrane_contexts&&    r �get_unified_context�#SessionInjector.get_unified_context4s������.�.�z�:����L�L��!��7�7�9�
137  ��*�]�]��;��L�L��$� �=�=�@�@��L���#�#�#��L�L�)�:�:�<�=�%*�v�{�{�5�!�2��2r#)rSrPrQrTrRrLrJrKN)r%r&r'r(r)rUr^r[r]rwr�r�r�r�r�r,r-r.s@r rHrHSss�����,E�E�&
138  >�
139  >�6�6�
140  �
141  �:�:�* �* �X��B% �% �N � �63�3r#rHTc
142  �T�V^8�dQhR\R\R\R\R\/#)rrJ�permeability�with_orchestratorrr4)rr
rqrH)rs"r r!r!Ns:��2�2��2�#�2��2��	2�
143  �2r#c��^RIHp^RIHpV!V4wrgV!V4wr�VP	4VP4\
VVVR7p
144  V'dT^RIHpV!VVR7pVP4'dV
145  PV4\R4V
146  #\R4V
147  #V
148  # \dp
\RT
24R	p
?
T
149  #R	p
?
ii;i)
150  aW
151  Create a session injector with all dependencies.
152  
153  Args:
154      sessions_dir: Directory where session files live
155      permeability: How permeable the membrane should be
156      with_orchestrator: Whether to start attention orchestrator
157      session_id: Session ID for orchestrator registration
158  
159  Returns:
160      Configured SessionInjector ready to inject.
161  ��create_cross_session_system��create_membrane_system�rJrKrL)�create_orchestrator)rrJz2[SessionInjector] Attention orchestrator connectedz8[SessionInjector] Orchestrator available but not startedz0[SessionInjector] Could not start orchestrator: N)
�
cross_sessionr�rLr��
scan_sessions�process_updatesrHrXr��startr^�print�	Exception)rJr�r�rr�r�rK�watcherrLr|�injectorr�rX�es&&&&          r �create_session_injectorr�Ns���$;�0�2�<�@��G�(��6�K�H����������!����H��	J�9�.�%�)��L��!�!�#�#��-�-�l�;��J�K��O�	�P�Q��O�8�O���	J��D�Q�C�H�I�I��O��	J�s$�%B,�>B,�B,�,C�7C�Cc�j�V^8�dQhR\R\R\\\3,R\/#)rrJr�
screen_layoutr4)rr�tuple)rs"r r!r!�s8��=,�=,��=,��=,���S��>�=,��	=,r#c
162  �aa�^RIHpHp^RIHpV!\
163  P4wop^RIHpV!V4wr�V	P4V	P4T!STT;'g	RRRRRR	/R
164  7p
165  V!V
166  4p\VVSR7pVP4'd*VPV4VV3Rlp
VPV
4W�S3#)
a0
167  Create a fully integrated attention + injection system.
168  
169  This is the main entry point for the complete system.
170  
171  Args:
172      sessions_dir: Where session files live
173      session_id: ID for this session
174      screen_layout: Screen position to name mapping
175  
176  Returns:
177      (orchestrator, injector, membrane) tuple
178  )r�OrchestratorConfigr�r��left�MacBookr1zMain Monitor�right�iPad)rrJ�screen_namesr�c�t<�VP4pV'dS'dSPSV4R#R#R#)N)�to_session_topics�update_session_topics)ra�topicsrLrs& ��r �on_attention�.create_integrated_system.<locals>.on_attention�s-����,�,�.�F��*��.�.�z�6�B�%�vr#)rXrr�rLr�r
�
179  ATTRACTORSr�r�r�r�rHr�r^rZ)rJrr�rr�r��context_injectorr�rKr��configrXr�r�rLs&f&           @r �create_integrated_systemr��s����$H�0�"8�8I�8T�8T�!U��H��;�2�<�@��G��������� ��!�"�
180  �
181  ��I��n��V�'
182  ��F�)��0�L��!����H�������%�%�l�3�	C�
183  	�(�(��6��8�+�+r#�__main__z5=== Integrated Attention + Injection System Test ===
184  r�z3/Users/rcerf/repos/Sovereign_Estate/daily/sessions/z'Creating integrated system for session r�r�zMacBook Pror1zStudio Displayr�ziPad Pro)rJrr�c��VP;'gRpVPPpVP;'gRp\	RVRVRV24R#)�?z  [Attention] r8N)rercrdrfr�)ra�apprc�regions&   r r�r��sP���n�n�#�#������#�#���$�$�+�+���
��v�h�c�#��c�&��:�;r#c�$�\RVR24R#)z
185    *** Screen: z ***
186  N)r�)rcris&&r �	on_screenr��s��
� ���f�-�.r#z5
187  System running. Move eyes, switch apps, turn head...zPress Ctrl+C to stop
188  z
189  --- Unified Context ---z(no context to inject)z
190  --- System Message ---z(no system message)z
191  === Test Complete ===)NN)3r)�dataclassesrrr�typingrrrr�pathlibr	�jsonr�r
192  rrLrr
rrXrr�	head_poserrr0rHr�r�r�r%�time�uuidr�r�uuid4�test_session_idrJr�r�r�rZr\�sleepr��contextr��msg�KeyboardInterrupt�stopr$r#r �<module>r�s���%�N)��6�6���A�L�L��H�*��=�=��=��!�!��!�$x3�x3�z'8�&B�&B�"��	2�j=,�@�z����	�
193  B�C��$�*�*�,�'��+�O�H�L�	�3�O�3D�C�
194  H�I�'?�!�"��M��&��Z�
195  �(�$�L�(�H�<�/��$�$�\�2��!�!�)�,�	�
196  B�C�	�
197  "�#�
���J�J�q�M�
�-�.��2�2�?�C�G���g���.�/��,�-��2�2�?�C�C���c�
198  ��+�,�o��r�
��
������	�
199  #�$s�&3F"�1F"�F"�"F,�+F,