/ core / altitude / __pycache__ / detector.cpython-314.pyc
detector.cpython-314.pyc
  1  +
  2  ��fi+9�	��Rt^RIHtHt^RIHtHt^RIHt^RIH	t	H
  3  t
  4  HtHtH
t
^RIt!RR]4t]!RR	44t]!R
  5  R44t!RR
4t]!RR44t]R8XEd�]!R4]!4tRR.3RR.3RR.3RR.3R.3R.3R.3R.3.t]F�wtt]P5]]R7t]!]!]4^28�dR]R ,R!2MR]R"24]!R#]24]!R$]P:P<24]!R%]P>R&
24]!R'R(PAR)]PBPE44424]!4K�	]!R*4.R2Ot#]PI]#4t%]%Fnwt&t't(]!R+]&R,]'P<R-](P<24]!R.]#]&^,
  6  ,R/,R!24]!R0]#]&,R/,R!24]!4Kp	]!R14R#R#)3u
  7  Altitude Detector
  8  
  9  Detects the cognitive altitude of content (bullets, conversations)
 10  and tracks operator state through altitude transitions.
 11  
 12  The four altitudes form a ladder:
 13      Philosophical (highest) - principles, values, meaning
 14          ↑↓
 15      Strategic - patterns, architecture, design
 16          ↑↓
 17      Tactical - decisions, tradeoffs, methods
 18          ↑↓
 19      Operational (lowest) - tasks, actions, implementation
 20  
 21  Content naturally exists at one or more altitudes.
 22  Operators shift between altitudes during thinking.
 23  )�	dataclass�field)�datetime�	timedelta)�Enum)�Optional�List�Dict�Any�TupleNc�la�]tRt^toRt^t^t^t^t]	V3RlRl4t
 24  ]V3RlRl4tRt
VtR#)�AltitudezThe four cognitive altitudes.c� <�V^8�dQhRS[/#���return��str)�format�
__classdict__s"��9/Users/rcerf/repos/Sovereign_OS/core/altitude/detector.py�__annotate__�Altitude.__annotate__#s���!�!�C�!�c�6�VPP4#�N)�name�lower��selfs&r�
 25  name_lower�Altitude.name_lower"s���y�y��� � rc�$<�V^8�dQhRS[RR/#)r�srr
r)rrs"�rrr's���3�3�C�3�J�3rc��VP4P4pVF&pVPP4V8XgK$Vu#	\RV24h)zParse altitude from string.zUnknown altitude: )r�stripr�
 26  ValueError)�clsr#�s_lower�alts&&  r�from_string�Altitude.from_string&sM���'�'�)�/�/�#���C��x�x�~�~��7�*��
 27  ���-�a�S�1�2�2r�N)�__name__�
 28  __module__�__qualname__�__firstlineno__�__doc__�OPERATIONAL�TACTICAL�	STRATEGIC�
PHILOSOPHICAL�propertyr �classmethodr*�__static_attributes__�__classdictcell__�rs@rr
r
sB����'��K��H��I��M�
�!��!��3��3rr
c�0a�]tRt^0toRtV3RltRtVtR#)�AltitudeSignalzg
 29  A signal contributing to altitude detection.
 30  
 31  Multiple signals combine to determine overall altitude.
 32  c�J<�V^8�dQh/S[;R&S[;R&S[;R&S[;R&#)r�signal_type�altitude�strength�evidence)rr
�float)rrs"�rr�AltitudeSignal.__annotate__0s7�����������O���M�rr,N)r-r.r/r0r1�__annotate_func__r8r9r:s@rr<r<0s������rr<c�Va�]tRt^=toRt]!]PR7tV3Rlt	Rt
 33  VtR#)�AltitudeDetectionz*
 34  Result of altitude detection on content.
 35  ��default_factoryc�<�V^8�dQh/S[;R&S[;R&S[;R&S[S[S[3,;R&S[S[,;R&S[;R&#)r�
 36  content_id�primary_altitude�
 37  confidence�altitude_distribution�signals�detected_at)rr
rBr	rr<r)rrs"�rr�AltitudeDetection.__annotate__=s`����
 38  �O����
���� ��%��0�0���.�
!�!���?�rr,N)r-r.r/r0r1rr�nowrOrDr8r9r:s@rrFrF=s!�����"�(�,�,�?�K��rrFc	��a�]tRt^JtoRt]P.R
O]P.RO]P.RO]P.RO/t
 39  ]P.RO]P.RO]P.RO]P.RO/t]P.RO]P.RO]P.RO]P.RO/tR.ROR.RO/t
RtRV3RlRlltV3RlR	ltRV3R
 40  lRlltRtVtR#)�AltitudeDetectorz�
 41  Detects cognitive altitude of content.
 42  
 43  Uses multiple signal types:
 44  - Explicit tags (#principle, #task, etc.)
 45  - Keywords and phrases
 46  - Question types (why vs how vs what)
 47  - Sentence structure and abstraction level
 48  �high�lowc
���VPP4UUUu/uF:wrYUu.uF(p\P!V\P4NK*	upbK<	upppVnVPP4UUUu/uF:wrBYBUu.uF(p\P!V\P4NK*	upbK<	upppVnR#uupiuupppiuupiuupppi)z!Initialize the altitude detector.N)�QUESTION_PATTERNS�items�re�compile�
 49  IGNORECASE�_compiled_questions�ABSTRACTION_PATTERNS�_compiled_abstraction)rr)�patterns�p�levels&    r�__init__�AltitudeDetector.__init__�s���
 50  "&�!7�!7�!=�!=�!?�$
 51  �!?�
��
��A��1�"�*�*�Q��
�
�.��A�A�!?�$
 52  �� �$(�#<�#<�#B�#B�#D�&
 53  �#D���
�(�C�(�Q�B�J�J�q�"�-�-�0�(�C�C�#D�&
 54  ��"��B��$
 55  ��
 56  D��&
 57  s.�C�.C�C�C$�.C�C$�C�C$Nc�R<�V^8�dQhRS[RS[RS[S[S[,,RS[/#)r�contentrJ�tagsr)rrrrF)rrs"�rr�AltitudeDetector.__annotate__�sB���`
 58  �`
 59  ��`
 60  ��`
 61  ��t�C�y�!�	`
 62 63  
 64  �`
 65  rc�aa�.pT;'g.pVF_pVP4pVPP4F.wrxWh9gK
VP\	RVRRV2R74K0	Ka	SP4p	VP
 66  P4F7wrzV
 67  F,pW�9gKVP\	RVRRV2R74K.	K9	VPP4FRwr|VFGp
V
PS4'gKVP\	RVR	R
 68  V
P2R74KI	KT	\V3RlVPR,44p\V3R
lVPR,44pW�8�d1VP\	R\PRRV2R74M5W�8�d0VP\	R\PRRV2R74VPV4o\SP!4V3RlR7pSV,p\#VVVSV\$P&!4R7#)z�
 69  Detect the altitude of content.
 70  
 71  Args:
 72      content: Text content to analyze
 73      content_id: Optional identifier
 74      tags: Optional explicit tags
 75  
 76  Returns:
 77      AltitudeDetection with results
 78  �tagg�������?zTag: )r>r?r@rA�keywordg�?z	Keyword: �
question_typegffffff�?zQuestion pattern: c3�Z<"�TF pVPS4'gK^x�K"	R#5i��N��search��.0r`res& �r�	<genexpr>�*AltitudeDetector.detect.<locals>.<genexpr>�s&����%
 79  �9�!��x�x�� �
�A�9���+�
 80  +rTc3�Z<"�TF pVPS4'gK^x�K"	R#5irmrorqs& �rrsrt�s&����$
 81  �8�!��x�x�� �
�A�8�rurU�abstractiong�������?zHigh abstraction indicators: zLow abstraction indicators: c�<�SV,#rr,)�a�distributions&�r�<lambda>�)AltitudeDetector.detect.<locals>.<lambda>	s	���,�q�/r��key)rJrKrLrMrNrO)r�
ALTITUDE_TAGSrX�appendr<�ALTITUDE_KEYWORDSr\rp�pattern�sumr^r
r4r2�_compute_distribution�max�keysrFrrQ)rrerJrfrNri�	tag_lowerr?�
altitude_tags�
content_lower�keywordsrjr_r��high_abstraction_count�low_abstraction_countrKrLrzs&f&&              @r�detect�AltitudeDetector.detect�sJ���")+���z�z�r���C��	�	��I�+/�+=�+=�+C�+C�+E�'���-��N�N�>�$)�!)�!$�#(����	$��,F�� �
�
��
�"&�"8�"8�">�">�"@��H�#���+��N�N�>�$-�!)�!$�#,�W�I�!6�	$��$�#A�#'�":�":�"@�"@�"B��H�#���>�>�'�*�*��N�N�>�$3�!)�!$�#5�g�o�o�5F�!G�	$��$�#C�"%�%
 82  ��1�1�&�9�%
 83  �"
 84  ��!$�$
 85  ��1�1�%�8�$
 86  �!
 87  ��
 88  "�9��N�N�>�)�!�+�+��8�9O�8P�Q�	�
�#�
;��N�N�>�)�!�-�-��7�8M�7N�O�	�
��1�1�'�:���|�0�0�2�8Q�R��"�"2�3�
 89  � �!�-�!�".�� ����

 90  �	
 91  rc�L<�V^8�dQhRS[S[,RS[S[S[3,/#)rrNr)rr<r	r
rB)rrs"�rrrgs-������n�%��
 92  �h��o�	�rc�t�\Uu/uFq"RbK	ppVF+pW4P;;,VP,
uu&K-	Rp\FpW2;;,V,
uu&K	\VP	44pVP4UUu/uFwr'W'V,bK	pppV#uupiuuppi)z�
 93  Compute probability distribution over altitudes from signals.
 94  
 95  Args:
 96      signals: List of altitude signals
 97  
 98  Returns:
 99      Dict mapping each altitude to probability (sums to 1.0)
100  gg�������?)r
r?r@r��valuesrX)	rrNr)�votes�signal�prior�total�voterzs	&&       rr��&AltitudeDetector._compute_distributions���=E�'E�H�S�S��H��'E��F��/�/�"�f�o�o�5�"�����C��J�%��J���E�L�L�N�#��;@�;�;�=�I�=�i�c��E�\�)�=��I����(F��Js�B/�B4c
101  �f<�V^8�dQhRS[S[,RS[RS[S[S[S[S[3,,/#)r�contents�window_sizer)rr�intrr
)rrs"�rrrg5s>������s�)����
102  �e�C��8�+�,�	-�	rc�:�\V4^8d.#VUu.uFq0PV4NK	pp.p\^\V44FIpWF^,
103  ,PpWF,PpWx8wgK6VP	WgV34KK	V#uupi)z�
104  Detect altitude transitions in a sequence of content.
105  
106  Args:
107      contents: List of content items in order
108      window_size: How many items to look back for transitions
109  
110  Returns:
111      List of (index, from_altitude, to_altitude) tuples
112  )�lenr��rangerKr�)	rr�r��c�
113  detections�transitions�i�prev_alt�curr_alts	&&&      r�detect_transition�"AltitudeDetector.detect_transition5s����x�=�1���I�/7�7�h��k�k�!�n�h�
114  �7����q�#�j�/�*�A�!�a�%�(�9�9�H�!�}�5�5�H��#��"�"�A��#:�;�+����8s�B)r^r\)
115116  #principlez#philosophyz#valuez#meaningz#beliefz#ethicsz#wisdomz#truthz#purposez#essence)
117  z	#strategyz#pattern�
#architecturez#designz#systemz
118  #frameworkz
119  #structurez#modelz	#approachz#vision)
120  �	#decisionz#optionz	#tradeoffz#methodz
121  #techniquez#choicez#alternativez#comparisonz#evaluationz	#criteria)
122  �#taskz#actionz#todoz#implementationz#stepz#doz#executez#buildz#fixz#create)
zwhy doeszwhat matters�
fundamentallyz
123  in essencez
the nature ofz
124  meaning ofz
125  purpose ofzvalue of�	principle�belief�truth�
126  ultimately�deeply)r��architecture�design�system�	framework�overallzbig picturez	long-term�	structure�approach�strategy�vision�	direction�model)
�	should we�option�tradeoff�decide�choose�compare�versus�alternative�method�	techniquezapproach forzway tozhow to)zneed to�must�todozaction itemz	next step�	implement�build�create�fixzdo this�run�execute�deploy�test)zwhy (?:do|does|is|are|should)z.what (?:matters|is the meaning|is the purpose)zwhat does .+ mean)zhow (?:does|do) .+ fitz'what (?:pattern|structure|architecture)z how (?:should|do) we think about)r�z which (?:option|approach|method)z&how (?:do|should) we (?:decide|choose)z"what are the (?:tradeoffs|options))zhow do Iz%what (?:is the|are the) (?:step|next)zcan you (?:do|make|create|fix)zplease (?:do|make|create|fix))z.\b(?:always|never|universally|fundamentally)\bz0\b(?:in general|as a rule|typically|generally)\bz+\b(?:concept|principle|theory|philosophy)\b)z1\b(?:specifically|exactly|precisely|concretely)\bz \b(?:this|that|here|now|today)\bz\b(?:step \d|item \d|task \d)\b)�N)�)r-r.r/r0r1r
r5r4r3r2rr�rWr]rbr�r�r�r8r9r:s@rrSrSJs(�����	���!
127  �	���
128  �	���
129  �	���
130  ��M�*	���!
131132  	���
133134  	���
135136  	���
137  �!��2	���!
138139  	���
140141  	���
142  �	���
143  �#��6	�
144145  	�
146  �
��
147  
148  �`
149  �`
150  �D��<��rrSc�|a�]tRtRtoRt]!]R7t]!]R7t	Rt
151  V3RlRltV3RlRltV3R	lt
R
152  tVtR#)�OperatorAltitudeStateiVz4
153  Tracks an operator's current altitude and history.
154  rGNc� <�V^8�dQhRS[/#)r�new_altitude�r
)rrs"�rr�"OperatorAltitudeState.__annotate__as���#�#�(�#rc��\P!4pVP'dpW P,
155  pVPVP9d+VPVP;;,V,
uu&MW0PVP&VP
156  P
W!34WnW nR#)z&Record a transition to a new altitude.N)rrQ�last_transition�current_altitude�time_at_altitude�altitude_historyr�)rr�rQ�durations&&  r�
transition_to�#OperatorAltitudeState.transition_toas����l�l�n�������1�1�1�H��$�$��(=�(=�=��%�%�d�&;�&;�<��H�<�?G�%�%�d�&;�&;�<�	
���$�$�c�%8�9� ,��"�rc� <�V^8�dQhRS[/#rr�)rrs"�rrr�rs���;�;�x�;rc�a�SP'g
SP#\SPP4V3RlR7#)z1Get the altitude where operator spends most time.c�*<�SPV,#r)r�)ryrs&�rr{�=OperatorAltitudeState.get_dominant_altitude.<locals>.<lambda>xs����!6�!6�q�!9rr})r�r�r�r�rsfr�get_dominant_altitude�+OperatorAltitudeState.get_dominant_altituders<����$�$�$��(�(�(��4�(�(�-�-�/�9�;�	;rc�<�V^8�dQh/S[;R&S[;R&S[S[S[S[3,,;R&S[S[S[3,;R&S[S[,;R&#)r�operator_idr�r�r�r�)rr
rrrr	rr)rrs"�rrr�Vsd����
157  �����
��5��8�!3�4�5�S���8�Y�.�/�M���h�'�.�r)r�r�)r-r.r/r0r1r�listr��dictr�r�r�r�rDr8r9r:s@rr�r�VsB�����
158  9>�d�8S��27��2M��*.�O�#�#�";�;�9�rr��__main__z === Altitude Detection Test ===
159  z2We need to implement the login feature by tomorrowr�z.Should we use OAuth or JWT for authentication?r�z8The overall architecture follows a microservices patternr�z'Truth requires both honesty and courager�zWhy does this matter?zFix the bug in line 42z#What is the meaning of good design?zStep 1: Install dependencies)rfz
160  Content: ":N�2Nz..."�"z  Tags: z  Altitude: z  Confidence: �.2fz  Distribution: z, c#�J"�TFwrVPRVR
2x�K	R#5i)�=r�N)r)rrryr`s&  rrsrs�s%���*s�Kr�4�1�a�f�f�X�Q�q��g�+>�Kr�s�!#z=== Transition Detection ===
161  zTransition at z: u → z  Before: ":N�(Nz
162    After: "z=== Test Complete ===)zWe need to fix the login bugz2But wait, should we use a different auth strategy?z6Actually, what does secure authentication really mean?z(Okay, let's just implement OAuth for now))r1�dataclassesrrrr�enumr�typingrrr	r
163  rrYr
r<rFrSr�r-�print�detector�
164  test_casesrerfr��	detectionr�rKrrL�joinrMrX�sequencer�r��idx�from_alt�to_altr,rr�<module>r�sb���&)�(��3�3�	�3�t�3�*�	�	��	��	@�	@��	@�I�I�X�!;�!;��!;�J�z��	�
165  -�.��!�H�
166  >��y�I�	9�K�=�I�	C�o�EV�W�	2�\�N�C�	 �"�%�	!�2�&�	.��3�	'��,�	�J�$�
����O�O�G�$�O�7�	�
�3�w�<�"�3D��G�C�L�>��/�K�X_�W`�`b�Jc�d�
����� �
��Y�7�7�<�<�=�>�?�
��y�3�3�C�8�9�:�
� ����*s�9�Kj�Kj�Kp�Kp�Kr�*s�!s� t�u�v�
��$�
167168  *�+��H��,�,�X�6�K�!,���X�v�
��s�e�2�h�m�m�_�E�&�+�+��G�H�
��X�c�!�e�_�S�1�2�%�8�9�
��H�S�M�#�.�/�u�5�6�
��	"-�
169170  !�"�Sr