/ core / attention / __pycache__ / context_bootstrap.cpython-314.pyc
context_bootstrap.cpython-314.pyc
  1  +
  2  �6gi�.���Rt^RIHtHt^RIHtHt^RIHtHtH	t	H
  3  t
  4  ^RIHt^RI
t
^RIHtHt^RIHtHt]!RR	44t!R
  5  R4tRR
ltRRlt]R8Xd�]!R4]!RRR7t]P7^R7t]!R]P:24]!R]P<24]!4]!]P?44]!4]!R4]!]PA4R,R,4R#R#)u2
  6  Context Bootstrap - Fast context loading for new sessions.
  7  
  8  Problem: When you open a new Claude session, it starts cold.
  9  You have to re-explain context, re-establish what you're working on.
 10  
 11  Solution: The attention system has been tracking all your sessions.
 12  When a new session starts, bootstrap it with distilled context from
 13  recent activity across all sessions.
 14  
 15  This enables:
 16  1. Cold start → warm start in seconds
 17  2. Branch sessions that share foundation
 18  3. Resume work without re-explaining
 19  4. Context continuity across session restarts
 20  
 21  Usage:
 22      bootstrap = ContextBootstrap(sessions_dir, daily_dir)
 23  
 24      # Get briefing for a new session
 25      briefing = bootstrap.get_briefing(
 26          hours_back=4,
 27          max_tokens=2000
 28      )
 29  
 30      # Inject into session as system context
 31      print(briefing.to_markdown())
 32  )�	dataclass�field)�datetime�	timedelta)�Optional�List�Dict�Tuple)�PathN)�create_cross_session_system�UnifiedAttentionState)�create_coherence_system�DecisionTypec��a�]tRt^(toRt]!]PR7tRt	^t
 33  ]!]R7t]!]R7t
]!]R7t]!]R7tRt]!]R7t]!]R7tV3RlRltV3RlRltV3R	ltR
 34  tVtR#)�ContextBriefingz�
 35  A briefing to bootstrap a new session with context.
 36  
 37  Contains distilled knowledge from recent sessions:
 38  - What topics were active
 39  - What decisions were made
 40  - What questions are unresolved
 41  - What direction attention was heading
 42  )�default_factory�@�c� <�V^8�dQhRS[/#���return��str)�format�
__classdict__s"��C/Users/rcerf/repos/Sovereign_OS/core/attention/context_bootstrap.py�__annotate__�ContextBriefing.__annotate__Ls���/ �/ �S�/ �c
 43  ��RRVPRVPR
R2R.pVP'd�VPR4VPRR	P	VPR
 44  ,4R24VP
 45  'd5VPRR	P	VP
 46  R
,424VPR4VP'd�VPR4VPR
 47  ,F[pVPRR4pVPRR4pVPRR4R,pVPRVRVRVR24K]	VPR4VP'dQVPR4VPR
 48  ,FpVPRV24K	VPR4VP'd>VPR4VPVP4VPR4VP'd�VPR4VPR
,FKpVPR4R8XdRMRpVPRVR VPR!R4R",24KM	VPR4R#P	V4#)$z+Convert briefing to markdown for injection.z## Context Briefingz*Generated from z sessions over z.1fz hours*rz### Active TopicszCurrently working on: **�, �N�Nz**zCross-session focus: �N�Nz### Recent Decisions�type�decision�topic�content:N�<Nz- [z] **z**: �...z### Unresolved Itemsz- [ ] z
### Directionz### Recent Insights�	discoveryu💡u🔧z- � �summary:N�PN�
 49  )�sessions_analyzed�
hours_covered�
 50  hot_topics�append�join�cross_session_topics�recent_decisions�get�
 51  unresolved�trajectory_summary�recent_ahas)	�self�lines�d�dtyper(r)�item�aha�emojis	&        r�to_markdown�ContextBriefing.to_markdownLsd��
"��t�5�5�6�o�d�FX�FX�Y\�E]�]d�e��
 52  ���?�?�?��L�L�,�-��L�L�3�D�I�I�d�o�o�b�>Q�4R�3S�SU�V�W��(�(�(����4�T�Y�Y�t�?X�?X�Y[�?\�5]�4^�_�`��L�L���� � � ��L�L�/�0��*�*�2�.�.�����f�j�1�����g�r�*���%�%�	�2�.�s�3�����s�5�'��e�W�D��	��E�F�	/�
 53  
�L�L����?�?�?��L�L�/�0�����+�+�����v�d�V�_�-�,��L�L����"�"�"��L�L��)��L�L��0�0�1��L�L��������L�L�.�/��'�'��+�+��"%�'�'�&�/�[�"@��f�����r�%���#�'�'�)�R�*@��*E�)F�G�H�,�
�L�L����y�y���rc� <�V^8�dQhRS[/#rr)rrs"�rrr}s���V�V�3�Vrc�.�VP4pRVR2#)z,Convert to system message format for Claude.z<context-bootstrap>
 54  z�
 55  </context-bootstrap>
 56  
 57  You are continuing work from previous sessions. The above briefing summarizes recent context.
 58  Use this to orient yourself, but the user may want to go in a different direction.)rC)r<�mds& r�to_system_message�!ContextBriefing.to_system_message}s,��
�
�
�
�����S�V�	Vrc��<�V^8�dQh/S[;R&S[;R&S[;R&S[S[,;R&S[S[,;R&S[S[,;R&S[S[,;R&S[;R&S[S[,;R	&S[S[,;R
 59  &#)r�generated_atr2r1r3r6r7r9r:r;�session_summaries)r�float�intrrr)rrs"�rrr(s������@��������$�S�	�7�%�&�s�)�A�'�,�4�j�>�-�2�S�	�7�3�8� �9�>�d��9�?�D�D�z�?�Er�N)�__name__�
 60  __module__�__qualname__�__firstlineno__�__doc__rr�nowrKr2r1�listr3r6r7r9r:r;rLrCrH�__annotate_func__�__static_attributes__�__classdictcell__�rs@rrr(s������#�8�<�<�@�L��M���"�$�7�J�&+�D�&A��$)��#>��"�$�7�J�!��$�D�9�K�%*�$�$?��/ �/ �bV�V�k�rrc�a�]tRt^�toRtV3RlRltRV3RlRlltV3RlRltV3R	lR
 61  ltV3RlRlt	RV3R
lRllt
 62  RtVtR#)�ContextBootstrapz�
 63  Generates context briefings from recent session history.
 64  
 65  Analyzes session streams, extracts key information, and
 66  produces a briefing that can bootstrap a new session.
 67  c�&<�V^8�dQhRS[RS[/#)r�sessions_dir�daily_notes_dirr)rrs"�rr�ContextBootstrap.__annotate__�s���/�/��/��/rc��\V4Vn\V4Vn\\	V44wVnVn\4wVnpVPP4VPP4R#)N)r
 68  r^r_rr�
cross_tracker�session_watcherr
�coherence_detector�
scan_sessions�process_updates)r<r^r_�_s&&& r�__init__�ContextBootstrap.__init__�sv��
 69  !��.���#�O�4���4O����4
 70  �0���D�0�&=�%>�"����	
���*�*�,����,�,�.rNc�2<�V^8�dQhRS[RS[RS[RS[/#)r�
 71  hours_back�
 72  max_tokens�
focus_sessionr)rMrNrr)rrs"�rrr`�s9���G�G��G��G��	G�
 73  
 74  �Grc�V�\P!4\VR7,
 75  pVPP	4pVP
 76  P
4UUu/uF.wrgVP'gKVPV8�gK,WgbK0	ppp\V\V4R7p	.p
 77  VP4FpV
 78  PVP4K 	/pV
 79  F:pV'gK
\V4^8�gKVPV^4^,W�&K<	\VP
4RRR7p
V
R,UUu.uFwr�VNK		uppV	nVP Uu.uF*pV'gK
\V4^8�gKRV9gK(VNK,	upR,V	nVP%W�4V	nV	P'd,VP)V	PV	P"4V	nVP-V^dR	7V	nV	#uuppiuuppiuupi)
 80  z�
 81  Generate a context briefing from recent sessions.
 82  
 83  Args:
 84      hours_back: How far back to look
 85      max_tokens: Approximate token budget for briefing
 86      focus_session: Optional session to focus on
 87  
 88  Returns:
 89      ContextBriefing ready for injection
 90  )�hours)r2r1c��V^,#)�rO)�xs&r�<lambda>�/ContextBootstrap.get_briefing.<locals>.<lambda>�s��1�Q�4rT)�key�reverse�N�
 91  Nr0r")�max_per_session)rrUrrb�	get_state�sessions�items�
last_activityr�len�values�extend�topicsr8�sortedr3�cross_session_attractorsr6�_extract_recent_decisionsr7�_build_trajectory_summaryr:�_build_session_summariesrL)r<rkrlrm�cutoff�state�sid�info�recent_sessions�briefing�
 92  all_topics�topic_countsr(�
sorted_topics�t�c�as&&&&             r�get_briefing�ContextBootstrap.get_briefing�s
��"����)�*�"=�=���"�"�,�,�.��(-�~�~�';�';�'=�
 93  �'=�)�#��!�!�
�&*�&8�&8�6�&A�
�C�I�'=�	�
 94 95  #�$�!�/�2�
 96  ���
 97  �#�*�*�,�D����d�k�k�*�-����E��u��U��a��&2�&6�&6�u�a�&@�1�&D��#� �
 98  �|�1�1�3��QU�V�
�-:�3�-?�@�-?�T�Q�q�-?�@����5�5�)
 99  �5�!��
���V�a�Z�
�$(��M�
�A�5�)
100  �
�)��%�%)�$B�$B��%
101  ��!�
102  ����*.�*H�*H��#�#��-�-�+�H�'�&*�%B�%B��S�&C�&
103  ��"����a
104  ��.A��)
105  s0�H�9H�H�
106  
H �.
107  H&�=
H&�H&�H&c�<<�V^8�dQhRS[RS[RS[S[,/#)rr{r�r)rrr)rrs"�rrr`�s-���3�3��3��3�
108  �d��	3rc�0�.p.ROpVP4EFwrV\VPPRVR244pV'gK8V^,P	4p\T4R8�dTR
RpTF�wr�\P!Y�\P4pTFqpTP^4P4p
\T
4^
109  8�gK4TPRT
110  RTPY�P44RT
RTR	,/4Ks	K�	EK	\4p.pVFLpVR,R
111  ,P4pVV9gK*VP!V4VPV4KN	VR,# EK~;i)z'Extract decisions from recent sessions.�*z	*-live.mdi'Nr&r(r)�session�N�N:N�Nrw))z,(?:decided|choosing|going with)\s+(.{10,60})r')z (?:principle|rule):\s*(.{10,60})�	principle)z%(?:architecture|design):\s*(.{10,60})�architecturei����)r|rVr^�glob�	read_textr~�re�finditer�
112  IGNORECASE�group�stripr4�_extract_topic�start�set�lower�add)r<r{r��	decisions�patternsr�r��
session_filesr)�patternr?�matches�match�text�seen�uniquer>rus&&&               rr��*ContextBootstrap._extract_recent_decisions�sk���	�
113  ��"���)�I�C� ��!2�!2�!7�!7�!�C�5�	�8J�!K�L�M� ��
�'��*�4�4�6��
114  �7�|�e�#�!�&�'�*��"*����+�+�g��
�
�F��$�E� �;�;�q�>�/�/�1�D��4�y�2�~�!�(�(�"�E�#�T�%8�%8��+�+�-�%P�%�t�%�s�2�w�	*��%�#+�*�8�u�����A��I�,�s�#�)�)�+�C��$������
��
�
�a� �	��c�{���9
��s�F�Fc�,<�V^8�dQhRS[RS[RS[/#)rr)�positionr)rrN)rrs"�rrr` s"�����c��S��S�rc��\^V^d,
115  4p\\V4V^d,4pWVp\P!RV4pV'd
116  V^,#\P!RV4pV'd
117  V^,#R#)z4Extract likely topic from context around a position.z\b([a-z]+_[a-z_]+)\bz#(\w+)�general)�max�minr~r��findall)r<r)r�r��end�context�terms�tagss&&&     rr��ContextBootstrap._extract_topic sp���A�x�#�~�&���#�g�,��3��/����$���
118119  �2�G�<�����8�O��z�z�)�W�-�����7�N�rc�L<�V^8�dQhRS[S[,RS[S[,RS[/#)rr3�cross_topicsr)rr)rrs"�rrr`2s1���
120  -�
121  -���I�
122  -��3�i�
123  -�
124125  -rc��V'd&RV^,RRPVR,42#V'dRRPVR,42#R#)z.Build a summary of where attention is heading.zConverging on: **z
**. Related: r!r$zExploring: zNo clear direction detected)r5)r<r3r�s&&&rr��*ContextBootstrap._build_trajectory_summary2sO���&�|�A��&7�}�T�Y�Y�z�Z\�~�E^�D_�`�`�
� ����:�b�>�!:� ;�<�<�,rc�<<�V^8�dQhRS[RS[RS[S[,/#)rr{ryr)rrNr)rrs"�rrr`>s-���������
126  �d��	rc
�"�.pVP4FxwrE\VP4R,pTPRVR,RTRVPRVP
127  'dVP
128  P
R4MR/4Kz	V#)	z&Build brief summaries of each session.r"r�r�r��atoms�last_activez%H:%M�?)r|rVr�r4�
129  atom_countr}�strftime)r<r{ry�	summariesr�r�r�s&&&    rr��)ContextBootstrap._build_session_summaries>s����	�!���)�I�C��$�+�+�&�r�*�F�����3�r�7��&������t�GY�GY�GY�t�1�1�:�:�7�C�_b�	�
�*��r)rdrbr_rcr^)ri�N)�d)
rPrQrRrSrTrhr�r�r�r�r�rXrYrZs@rr\r\�sO�����/�/�$G�G�R3�3�j��$
130  -�
131  -���rr\c�<�V^8�dQhR\R\R\/#)rr^r_r)rr\)rs"rrrRs&��;�;��;��;��;rc��\W4#)z"Create a context bootstrap system.)r\�r^r_s&&r�create_bootstrap_systemr�Rs��
132  �L�:�:rc�$�V^8�dQhR\/#rr)rs"rrr[s��"�"�C�"rc�`�\RRR7pVP^R7pVP4#)z,Get a quick briefing for the current moment.�3/Users/rcerf/repos/Sovereign_Estate/daily/sessions/�*/Users/rcerf/repos/Sovereign_Estate/daily/r��rk)r\r�rC)�	bootstrapr�s  r�get_quick_briefingr�[s6�� �J�D��I��%�%��%�3�H����!�!r�__main__z=== Context Bootstrap ===
133  r�r�r�r�zSessions analyzed: zHours covered: z--- System Message Format ---:Ni�Nr+)!rT�dataclassesrrrr�typingrrrr	�pathlibr
134  r��
cross_sessionrr�coherence_riskr
rrr\r�r�rP�printr�r�r�r1r2rCrHrOrr�<module>r�s���:)�(�.�.��	�M�A��\V�\V��\V�~G�G�T;�"��z��	�
135  '�(� �J�D��I�
136  �%�%��%�3�H�	��� :� :�;�
137  <�=�	�O�H�2�2�3�
138  4�5�	�G�	�(�
139  �
140  �
141   �!�	�G�	�
142  )�*�	�(�
143  $�
144  $�
145  &�t�
146  ,�u�
147  4�5�!r