/ core / altitude / __pycache__ / complementary.cpython-314.pyc
complementary.cpython-314.pyc
  1  +
  2  ��fi7�	�(�Rt^RIHtHt^RIHtHt^RIHtHtH	t	H
  3  t
  4  Ht^RIH
t
^RIHtHtHtHt^RIHtHt!RR]
4t]!R	R
  5  44t!RR4t]R
8XEd'^RIt^RIt]P8P;]P<!4R4t]!]4t ]!!R4RR.3RR.3RR.3RR.3RR.3RR.3RR.3.t"]"Fwt#t$] PK]#R]$R 7K	]!] 4t&]!4t]!!R!4]F�t']!!R"]'PPR#24]&PS]'4t*]!!R$]*Uu.uFqPPNK	up24]&PW]'R^R%7t,],Fgt-] P]]-P^4t0]!!R&]-PbPPR']0PFR(,R)24]!!R*]-Pd24Ki	]!!4K�	]!!R+4]!R,]PfR-7t4]Pj!4]!^-R.7,
  6  ]4n6]&Po]44t8]!!R/]8R0,24]!!R1]8R2,24]8R3,'d]!!R4]8R3,24]Pr!]4]!!R54R#R#uupi)6a�
  7  Complementary Altitude Engine
  8  
  9  Implements the key principle: the system should operate at the
 10  OPPOSITE altitude from the operator.
 11  
 12  When they're abstract (philosophical), ground them in concrete.
 13  When they're concrete (operational), lift them to principles.
 14  
 15  This creates productive tension that:
 16  - Prevents getting lost in abstraction
 17  - Prevents getting lost in weeds
 18  - Surfaces relevant connections across altitudes
 19  - Helps operator see full picture
 20  )�	dataclass�field)�datetime�	timedelta)�Optional�List�Dict�Any�Tuple)�Enum)�Altitude�AltitudeDetector�AltitudeDetection�OperatorAltitudeState)�GodDatabase�Bulletc�.�]tRt^tRtRtRtRtRtRt	Rt
 21  R#)	�ComplementStrategyz.Strategy for complementary altitude selection.�direct_opposite�
adjacent_pull�
 22  bracketing�	grounding�lifting�N)�__name__�
 23  __module__�__qualname__�__firstlineno__�__doc__�DIRECT_OPPOSITE�
ADJACENT_PULL�
 24  BRACKETING�	GROUNDING�LIFTING�__static_attributes__r��>/Users/rcerf/repos/Sovereign_OS/core/altitude/complementary.pyrrs��8�'�O�#�M��J��I��Gr%rc�Va�]tRt^#toRt]!]PR7tV3Rlt	Rt
 25  VtR#)�ComplementaryRecommendationzE
 26  A recommendation for complementary content at a different altitude.
 27  )�default_factoryc�b<�V^8�dQh/S[;R&S[;R&S[;R&S[;R&S[;R&S[;R&#)��bullet_uuid�bullet_altitude�relevance_score�altitude_gap�recommendation_reason�generated_at)�strr�float�intr)�format�
__classdict__s"�r&�__annotate__�(ComplementaryRecommendation.__annotate__#sS����
 28  �����
�����������@�r%rN)rrrrrrr�nowr1�__annotate_func__r$�__classdictcell__�r6s@r&r(r(#s!�����#�8�<�<�@�L��r%r(c�a�]tRt^0toRtR]P3V3RlRlltRV3RlRlltRV3RlRllt	V3R	lR
 29  lt
 30  RV3RlRlltV3R
lRltRt
VtR#)�ComplementaryAltitudeEnginez�
 31  Generates complementary altitude recommendations.
 32  
 33  When operator is at one altitude, surfaces relevant content
 34  from complementary altitudes to provide balance.
 35  Nc�<<�V^8�dQhRS[RS[S[,RS[/#)r+�god_db�detector�strategy)rrr
r)r5r6s"�r&r7�(ComplementaryAltitudeEngine.__annotate__8s/���!�!��!��+�,�!�%�	!r%c�P�WnT;'g\4VnW0nR#)z�
 36  Initialize the complementary altitude engine.
 37  
 38  Args:
 39      god_db: The God Database instance
 40      detector: Optional altitude detector (creates default if not provided)
 41      strategy: Strategy for selecting complementary altitude
 42  N)r@r
rArB)�selfr@rArBs&&&&r&�__init__�$ComplementaryAltitudeEngine.__init__8s!���� �6�6�$4�$6��
� �
r%c�L<�V^8�dQhRS[RS[S[,RS[S[,/#)r+�operator_altituderB�return)rrrr)r5r6s"�r&r7rCJs3���=#�=#�#�=#��-�.�=#�
 43  �h��	=#r%c���T;'g
VPpV\P8Xd�\P\P
 44  .\P\P.\P\P.\P
 45  \P./pW1,#V\P8Xd�\P\P.\P\P\P.\P\P\P
 46  .\P
 47  \P./pWA,#V\P8Xd�V\P8Xd!\P\P.#V\P
 48  8Xd!\P\P.#\VP^,
 49  4p\VP^,4pWV.#V\P8XdDV\P8Xd\P.#\VP^,
 50  4.#V\P8XdDV\P
 51  8Xd\P
 52  .#\VP^,4.#\P.#)z�
 53  Get complementary altitude(s) for operator's current altitude.
 54  
 55  Args:
 56      operator_altitude: Operator's current altitude
 57      strategy: Optional override strategy
 58  
 59  Returns:
 60      List of complementary altitudes to surface content from
 61  )
rBrrr�OPERATIONAL�
PHILOSOPHICAL�TACTICAL�	STRATEGICr r!�valuer"r#)rErIrB�	opposites�adjacent�lower�highers&&&    r&�get_complementary_altitude�6ComplementaryAltitudeEngine.get_complementary_altitudeJs5���,�,�t�}�}���)�9�9�9��$�$�x�'=�'=�&>��!�!�H�$6�$6�#7��"�"�X�%6�%6�$7��&�&��)=�)=�(>�	�I��/�/�
�+�9�9�
9��$�$�x�'8�'8�&9��!�!�H�$8�$8�(�:L�:L�#M��"�"�X�%6�%6��8N�8N�$O��&�&��);�);�(<�	�H��.�.�
�+�6�6�
6� �H�$8�$8�8� �)�)�8�+=�+=�>�>�"�h�&<�&<�<� �*�*�H�,=�,=�>�>�!�!2�!8�!8�1�!<�=��!�"3�"9�"9�A�"=�>����&�
�+�5�5�
5� �H�$8�$8�8� �,�,�-�-��.�4�4�q�8�9�:�:�
�+�3�3�
3� �H�$:�$:�:� �.�.�/�/��.�4�4�q�8�9�:�:��!�!�"�"r%c�X<�V^8�dQhRS[RS[RS[S[,RS[RS[S[,/#)r+rI�
 62  blanket_id�
current_topic�limitrJ)rr2rr4rr()r5r6s"�r&r7rC�sN���E'�E'�#�E'��E'� ��}�	E'�
 63  �E'�
 64  �)�	*�
E'r%c�a�VPV4pVPPV4p.pVEF�pVPP	VP
 65  VPVPR7p	V	PV9dKS\V	PPVP,
 66  4p
 67  RpS'd�SP4VP
 68  P49dRpMV\;QJd)V3RlVP4F'gKRM	RM!V3RlVP44'dRpVR,VPR	,,pVPVV	PV
 69  4pVP\!VPV	PVV
 70  VR
 71  74EK�	VP#RRR7VR
V#)a-
 72  Get bullets from complementary altitudes.
 73  
 74  Args:
 75      operator_altitude: Operator's current altitude
 76      blanket_id: Which Markov blanket to search
 77      current_topic: Optional topic for relevance filtering
 78      limit: Maximum recommendations to return
 79  
 80  Returns:
 81      List of ComplementaryRecommendation
 82  )�
 83  content_id�tagsg�?g�?c3�f<"�TF&pSP4VP49x�K(	R#5i�N)rS)�.0�tagrYs& �r&�	<genexpr>�HComplementaryAltitudeEngine.get_complementary_bullets.<locals>.<genexpr>�s'����]�I\�#��,�,�.�#�)�)�+�=�I\�s�.1TFg�������?gffffff�?g333333�?)r,r-r.r/r0c��VP#r_)r.)�rs&r&�<lambda>�GComplementaryAltitudeEngine.get_complementary_bullets.<locals>.<lambda>�s
 84  ��1�+<�+<r%)�key�reverseN)rUr@�get_bullets_for_blanketrA�detect�content�uuid�visible_tags�primary_altitude�absrPrS�any�resonance_score�_generate_reason�appendr(�sort)
rErIrXrYrZ�target_altitudes�bullets�recommendations�bullet�	detection�gap�	relevance�reasons
&&&f&        r&�get_complementary_bullets�5ComplementaryAltitudeEngine.get_complementary_bullets�s����& �:�:�;L�M���+�+�5�5�j�A��=?���F��
�
�,�,����!�;�;��(�(�-��I��)�)�1A�A���i�0�0�6�6�9J�9P�9P�P�Q�C��I�� �&�&�(�F�N�N�,@�,@�,B�B� #�I��S�]��I\�I\�]�S�S�S�]��I\�I\�]�]�]� #�I�"�C��&�*@�*@�3�*F�F�I��*�*�!��*�*���F�
�"�"�#>�"�K�K� )� :� :� )� �&,�$�
�C�T	���!<�d��K��v��&�&r%c�2<�V^8�dQhRS[RS[RS[RS[/#)r+rIr-r{rJ)rr4r2)r5r6s"�r&r7rC�s9���N�N�#�N�"�N��	N�
 85  
 86  
�Nr%c��VPVP8�d:RVPP4RVPP4R2#RVPP4RVPP4R2#)z2Generate human-readable reason for recommendation.zGrounding: You're thinking at z level. Here's a z
 perspective.zLifting: You're working at )rP�namerS)rErIr-r{s&&&&r&rs�,ComplementaryAltitudeEngine._generate_reason�s����"�"�_�%:�%:�:�3�4E�4J�4J�4P�4P�4R�3S�Sd�et�ey�ey�e�e�fB�eC�CP�Q�
Q�1�1B�1G�1G�1M�1M�1O�0P�Pa�bq�bv�bv�b|�b|�b~�a�@M�N�
Nr%c�B<�V^8�dQhRS[RS[RS[S[S[3,/#)r+�operator_state�threshold_minutesrJ)rr4rr2r	)r5r6s"�r&r7rC�s1���)�)�-�)��)�
 87  �c�3�h��	)r%c
 88  �>�RVPRVPPRRRRRR/p\P!4pVP
 89  'd�WAP
 90  ,
 91  pV\
VR78�dzR	VR&VPP^8�d.R
 92  VR&R\VP4^<,4R2VR&M,R
VR&R\VP4^<,4R2VR&VP4pWaP8wdVPVR&V#)z`
 93  Analyze if operator needs altitude balancing.
 94  
 95  Returns:
 96      Analysis dict with recommendations
 97  �operator_id�current_altitude�needs_balancingF�recommended_directionNr}��minutesT�downz$You've been thinking abstractly for z* minutes. Consider grounding in specifics.�upzYou've been in the weeds for z1 minutes. Consider stepping back to see patterns.�dominant_altitude)r�r�r�rr9�last_transitionrrPr4�
total_seconds�get_dominant_altitude)rEr�r��analysis�current_time�time_at_current�dominants&&&    r&�analyze_altitude_balance�4ComplementaryAltitudeEngine.analyze_altitude_balance�s4��
�>�5�5��� ?� ?� D� D��u�#�T��d�
 98  �� �|�|�~���)�)�)�*�-K�-K�K�O���3D�!E�E�.2��*�+�!�2�2�8�8�A�=�8>�H�4�5�+O�PS�Tc�Tq�Tq�Ts�vx�Tx�Py�Oz�{e�*f�H�X�&�9=�H�4�5�+H��_�Mj�Mj�Ml�oq�Mq�Ir�Hs�te�*f�H�X�&�"�7�7�9���6�6�6�,4�M�M�H�(�)��r%c�<<�V^8�dQhRS[RS[S[,RS[/#)r+rI�complementary_bulletsrJ)rrr(r2)r5r6s"�r&r7rC	s/���* �* �#�* � $�$?�@�* �
 99  
�	* r%c���V'gR#/pVFCpVPV9d.W4P&W4P,PV4KE	.pVP^8�d�VPR4\P\P
100  3FLpWc9gK\
W6,4pVPRVRVPP4R24KN	M�VPR4\P\P3FLpWc9gK\
W6,4pVPRVRVPP4R24KN	RPV4#)	z�
101  Generate a prompt/nudge for altitude awareness.
102  
103  Args:
104      operator_altitude: Current operator altitude
105      complementary_bullets: Recommendations from other altitudes
106  
107  Returns:
108      Human-readable prompt
109  �z$While you're thinking big picture...u  • � z items might ground thiszWhile you're in the details...z items might illuminate this�
110  )r-rtrPrrLrN�lenr�rSrOrM�join)rErIr��by_altitude�rec�lines�alt�counts&&&     r&�generate_altitude_prompt�4ComplementaryAltitudeEngine.generate_altitude_prompt	s@��%��JL��(�C��"�"�+�5�35��/�/�0��+�+�,�3�3�C�8�)�
111  ���"�"�a�'��L�L�?�@� �,�,�h�.?�.?�@���%��� 0�1�E��L�L�6�%���#�(�(�.�.�2B�1C�C[�!\�]�A�
�L�L�9�:� �*�*�H�,B�,B�C���%��� 0�1�E��L�L�6�%���#�(�(�.�.�2B�1C�C_�!`�a�D�
112  �y�y���r%)rAr@rBr_)N�)�)rrrrrrrrFrUr~rsr�r�r$r;r<s@r&r>r>0s[�����04�'9�'I�'I�	!�!�$=#�=#�~E'�E'�NN�N�)�)�V* �* r%r>�__main__Nztest_complementary.dbz$=== Complementary Altitude Test ===
113  z'Truth requires both honesty and couragez
114  #principlez-Our architecture follows domain-driven designz
#architecturez-Should we use Redis or Memcached for caching?z	#decisionz*Implement the user authentication endpointz#taskz,The meaning of security is maintaining trustz#philosophyz'Our caching strategy needs three layersz	#strategyzDeploy to staging by end of dayz#action�test)rlrXrnz'Testing complementary recommendations:
115  zOperator at �:z  Complementary altitudes: )rIrXrZu  • [z] :N�(Nz...z    Reason: z"=== Altitude Balance Analysis ===
116  �rick)r�r�r�z	Current: r�zNeeds balancing: r�r}zReason: z
117  === Test Complete ===):r�dataclassesrrrr�typingrrrr	r
118  �enumrrArr
rr�databaserrrr(r>r�tempfile�os�pathr��
119  gettempdir�db_path�db�print�bullets_datarlr]�
create_bullet�engine�operator_altr�rU�
complementaryr~�recsr��
120  get_bulletr,ryr-r0rM�stater9r�r�r��remove)�as0r&�<module>r�s���� )�(�3�3��Z�Z�*�����	A�	A��	A�C �C �N�z���
��g�g�l�l�8�.�.�0�2I�J�G�	�W�	�B�	�
121  1�2�
122  3�\�N�C�	8�?�:K�L�	8�;�-�H�	5��y�A�	7�-��I�	2�[�M�B�	*�Y�K�8��L�&�
���
123  ������	�	
124  �&�)��
,�F��!�H�
125126  4�5� ��
��\�.�.�/�q�1�2��9�9�,�G�
�
�+�]�,K�]��V�V�]�,K�+L�M�N��/�/�*���0�
127  ���C��]�]�3�?�?�3�F��G�C�/�/�4�4�5�R����s�8K�7L�C�P�Q��L��!:�!:� ;�<�=��	��!�$
128129  /�0�!��!�/�/�
�E�%�L�L�N�Y�r�-B�B�E���.�.�u�5�H�	�I�h�1�2�3�
130  4�5�	��h�'8�9�:�
131  ;�<�����
���(�+�,�-�.��I�I�g��	�
132  #�$�K��L-Ls�2J