/ server / __pycache__ / sovereign_server.cpython-314.pyc
sovereign_server.cpython-314.pyc
  1  +
  2  �Agi���	��
  3  �Rt^RIt^RIt^RIt^RIt^RIHt^RIHt^RIH	t	H
  4  t
  5  HtHt^RI
HuHt]P"P%^]!]!]4P*P*44^RIHt^RIHt^RIHt^RIHt^R	IHtH t ^R
  6  I!H"t"^RI#H$t$^RI%H&t&H't'^R
I(H)t)H*t*^RI+H,t,H-t-^RI.H/t/H0t0^RI1H2t2H3t3Rt4]Pj!4R,t6]Pj!4R,t7]Pj!4R,t8]	!]94t:Rs;Rs<Rs=Rs>Rs?Rs@RsARtBRtCRtD]:P�R4R4tF]:P�R4R4tG]:P�R4R4tH]:P�R4R4tI]:P�R 4R!4tJ]:P�R"4R#4tK]:P�R$4R%4tL]:P�R&R'.R(7R)4tM]:P�R*4R+4tN]:P�R,R'.R(7R-4tO]:P�R.R'.R(7R/4tP]:P�R0R'.R(7R14tQ]:P�R2R3.R(7R44tR]:P�R5R'.R(7R64tS]:P�R7R3R'.R(7R84tT]:P�R9R3.R(7R:4tU]:P�R;4R<4tV]:P�R=R'.R(7R>4tW]:P�R?R'.R(7R@4tX]:P�RAR'.R(7RB4tY]:P�RCR3R'.R(7RD4tZ]:P�RER3.R(7RF4t[]:P�RGR3.R(7RH4t\]:P�RIR3.R(7RJ4t]]:P�RKR3.R(7RL4t^]:P�RM4RN4t_]:P�RO4RP4t`]:P�RQ4RR4ta]:P�RS4RT4tb]:P�RU4RV4tc]:P�RW4RX4td]:P�RY4RZ4te]:P�R[R'.R(7R\4tf]:P�R]4R^4tg]:P�R_4R`4th]:P�Ra4Rb4ti]:P�Rc4Rd4tj]:P�Re4Rf4tk]:P�Rg4Rh4tl]:P�RiR'.R(7Rj4tm]:P�RkR'.R(7Rl4tn]:P�Rm4Rn4toRoRpltp]D!4]9Rq8Xd*]q!Rr]4Rs]6Rt]7Ru24]:P�Rv]4RwRxRy7R#R#)za
  7  Sovereign OS Server
  8  
  9  The central server for all Sovereign OS services:
 10  
 11  1. Attention Daemon - Cross-session tracking, coherence risk, aha detection
 12  2. Overcast Webhook - Receives podcast OPML from iOS
 13  3. Attention API - Query attention state, stream status
 14  4. Health monitoring
 15  
 16  Run locally:
 17      python server/sovereign_server.py
 18  
 19  Run in production (with gunicorn):
 20      gunicorn -w 1 -b 0.0.0.0:5050 server.sovereign_server:app
 21  
 22  Deploy to cloud:
 23      - Fly.io: fly launch
 24      - Railway: railway up
 25      - Render: push to git
 26  N)�datetime)�Path)�Flask�request�jsonify�Response)�AttentionDaemon)�create_cross_session_system)�create_coherence_system)�create_context_stream)�NaturalContextDirector�create_natural_director)�detect_signals)�TranscriptMiner)�IngestionPipeline�create_pipeline)�MultiSourceCorrelator�correlate_sources)�ArtifactAnalyzer�analyze_artifacts)�GraphIntegration�get_graph_integration)�UnifiedCorrelator�get_unified_correlatori�z%repos/Sovereign_Estate/daily/sessionszrepos/Sovereign_Estate/dailyz repos/Sovereign_OS/data/overcastc�:�\P!4p\P!V4VP\P44VP4R# \dp\RT24Rp?L0Rp?ii;i TP4i;i)z+Run the attention daemon in its own thread.z[Daemon] Error: N)	�asyncio�new_event_loop�set_event_loop�run_until_complete�daemon�run�	Exception�print�close��loop�es  �:/Users/rcerf/repos/Sovereign_OS/server/sovereign_server.py�run_daemon_loopr(Csu���!�!�#�D����4� ������
 27 28  ��-�	
�
 29 30  ����&�
� ���$�%�%��&��	
�
 31 32  ���)�#A"�"B�-B�;B�B�B�Bc�:�\P!4p\P!V4VP\P44VP4R# \dp\RT24Rp?L0Rp?ii;i TP4i;i)z-Run the ingestion pipeline in its own thread.z[Pipeline] Error: N)	rrrr�ingestion_pipeline�	run_asyncr!r"r#r$s  r'�run_pipeline_loopr-Psy���!�!�#�D����4� ����� 2� <� <� >�?�	
�
 33 34  ����(�
�"�1�#�&�'�'��(��	
�
 35 36  ��r)c��\eR#\R4\\\4\\
 37  4R7s\PP4\PP4\\\4\\
 38  4\PR7s\R4\RR7s
\R4\4s\R	\P P"R
 39  24\%4s\R4\(P*!\,RR
7s\.P14\R4R#)z Initialize the attention daemon.Nz)[Server] Initializing attention daemon...)�sessions_dir�daily_notes_dir)r/r0�streamz-[Server] Natural context director initialized�
 40  standalone)�modez'[Server] Ingestion pipeline initializedz)[Server] Graph integration initialized - z
 atoms loadedz'[Server] Unified correlator initializedT)�targetrz![Server] Attention daemon started)rr"r�str�SESSIONS_DIR�	DAILY_DIR�session_watcher�
scan_sessions�process_updatesr
�context_stream�natural_directorrr+r�graph_integration�_state�
 41  atom_countr�unified_correlator�	threading�Threadr(�
daemon_thread�start��r'�init_daemonrG]s�����	�
 42  5�6�
���&��I���F����(�(�*�
 43  ���*�*�,�/���&��I���$�$���
 44  
 45 46  9�:�)�l�;��	�
 47  3�4�.�/��	�5�6G�6N�6N�6Y�6Y�5Z�Zg�
 48  h�i�0�1��	�
 49  3�4��$�$�O�D�I�M�����
 50 51  -�.rF�/c��R#)z
Landing page.u
 52      <html>
 53      <head>
 54          <title>Sovereign OS Server</title>
 55          <style>
 56              body { font-family: system-ui; max-width: 800px; margin: 50px auto; padding: 20px; }
 57              code { background: #f0f0f0; padding: 2px 6px; border-radius: 3px; }
 58              .status { padding: 10px; border-radius: 5px; margin: 10px 0; }
 59              .healthy { background: #d4edda; }
 60              .section { margin: 20px 0; padding: 15px; border: 1px solid #ddd; border-radius: 5px; }
 61          </style>
 62      </head>
 63      <body>
 64          <h1>Sovereign OS Server</h1>
 65          <div class="status healthy">✓ Server running</div>
 66  
 67          <div class="section">
 68              <h2>Attention System</h2>
 69              <ul>
 70                  <li><a href="/attention/status">GET /attention/status</a> - Current attention state</li>
 71                  <li><a href="/attention/sessions">GET /attention/sessions</a> - Active sessions</li>
 72                  <li><a href="/attention/attractors">GET /attention/attractors</a> - Cross-session attractors</li>
 73                  <li><a href="/attention/coherence">GET /attention/coherence</a> - Coherence risk</li>
 74                  <li><a href="/attention/stream">GET /attention/stream</a> - Context stream state</li>
 75                  <li><a href="/attention/tuning">GET /attention/tuning</a> - Context tuning parameters</li>
 76                  <li><code>POST /attention/engage/&lt;item_id&gt;</code> - Record engagement (feeds tuner)</li>
 77              </ul>
 78          </div>
 79  
 80          <div class="section">
 81              <h2>Natural Context Direction</h2>
 82              <ul>
 83                  <li><code>POST /context/direct</code> - Natural language context direction</li>
 84                  <li><code>POST /context/signals</code> - Detect signal words in text</li>
 85                  <li><a href="/context/validation">GET /context/validation</a> - Items needing validation</li>
 86                  <li><code>POST /context/validate/&lt;item_id&gt;</code> - Validate or reject an item</li>
 87              </ul>
 88              <p><em>Example: POST /context/direct with {"input": "Load the last three days"}</em></p>
 89          </div>
 90  
 91          <div class="section">
 92              <h2>Transcript Mining</h2>
 93              <ul>
 94                  <li><a href="/context/mine">GET /context/mine</a> - Mine transcripts for insights (7 days default)</li>
 95                  <li><a href="/context/mine?hours=72">GET /context/mine?hours=72</a> - Last 3 days</li>
 96                  <li><a href="/context/mine?format=markdown">GET /context/mine?format=markdown</a> - Markdown report</li>
 97                  <li><a href="/context/mine/topics">GET /context/mine/topics</a> - Topic graph for visualization</li>
 98              </ul>
 99              <p><em>Extracts: unmined insights, principles, decisions, topic clusters, signal patterns</em></p>
100          </div>
101  
102          <div class="section">
103              <h2>Multi-Source Correlation & Pipeline</h2>
104              <ul>
105                  <li><a href="/correlate">GET /correlate</a> - Run multi-source correlation (Claude + Monologue + Comet)</li>
106                  <li><a href="/correlate?format=markdown">GET /correlate?format=markdown</a> - Correlation report in markdown</li>
107                  <li><a href="/correlate/aha">GET /correlate/aha</a> - Stored aha moments</li>
108                  <li><a href="/correlate/high-confidence">GET /correlate/high-confidence</a> - High-confidence correlated moments</li>
109                  <li><a href="/pipeline/status">GET /pipeline/status</a> - Pipeline status</li>
110                  <li><code>POST /pipeline/collect</code> - Trigger event collection</li>
111                  <li><code>POST /pipeline/process</code> - Trigger queue processing</li>
112                  <li><code>POST /pipeline/backfill</code> - Backfill historical data</li>
113              </ul>
114              <p><em>Triangulates insights across voice (Monologue), browser (Comet), and Claude sessions</em></p>
115          </div>
116  
117          <div class="section">
118              <h2>Artifact Analysis</h2>
119              <ul>
120                  <li><a href="/artifacts">GET /artifacts</a> - Analyze artifacts as crystallization markers</li>
121                  <li><a href="/artifacts?format=markdown">GET /artifacts?format=markdown</a> - Markdown report</li>
122                  <li><a href="/artifacts/unclosed">GET /artifacts/unclosed</a> - Unclosed OODA loops</li>
123              </ul>
124              <p><em>Artifacts = crystallization points where thinking became concrete</em></p>
125          </div>
126  
127          <div class="section">
128              <h2>Semantic Graph (from Sovereign_Estate)</h2>
129              <ul>
130                  <li><a href="/graph/status">GET /graph/status</a> - Graph state (atoms, edges, distributions)</li>
131                  <li><a href="/graph/atoms">GET /graph/atoms</a> - Recent atoms</li>
132                  <li><a href="/graph/resonance">GET /graph/resonance</a> - High-resonance atoms</li>
133                  <li><a href="/graph/gravity-wells">GET /graph/gravity-wells</a> - Highly connected nodes</li>
134                  <li><a href="/graph/search?q=attention">GET /graph/search?q=...</a> - Search atoms</li>
135                  <li><a href="/graph/stream">GET /graph/stream</a> - SSE stream of new events</li>
136                  <li><code>POST /graph/reload</code> - Reload graph data</li>
137              </ul>
138              <p><em>Streams from stream_session.py and historical_processor.py</em></p>
139          </div>
140  
141          <div class="section">
142              <h2>Unified Correlation (All Sources)</h2>
143              <ul>
144                  <li><a href="/unified/report">GET /unified/report</a> - Full correlation across all sources</li>
145                  <li><a href="/unified/report?format=markdown">GET /unified/report?format=markdown</a> - Markdown report</li>
146                  <li><a href="/unified/timeline">GET /unified/timeline</a> - Timeline of all events</li>
147                  <li><a href="/unified/stream">GET /unified/stream</a> - SSE stream of unified events</li>
148              </ul>
149              <p><em>Unifies: Claude sessions + Monologue + Browser + Graph + Artifacts</em></p>
150          </div>
151  
152          <div class="section">
153              <h2>Mobile / Shortcuts</h2>
154              <ul>
155                  <li><a href="/mobile/status">GET /mobile/status</a> - Quick status for mobile</li>
156                  <li><a href="/mobile/brief">GET /mobile/brief</a> - Today's brief (insights + next steps)</li>
157                  <li><a href="/mobile/aha">GET /mobile/aha</a> - Recent aha moments (clean format)</li>
158                  <li><code>POST /mobile/capture</code> - Capture a quick thought</li>
159              </ul>
160              <p><em>Optimized for iOS Shortcuts and mobile displays</em></p>
161          </div>
162  
163          <div class="section">
164              <h2>Overcast Webhook</h2>
165              <ul>
166                  <li><code>POST /overcast</code> - Receive OPML from iOS</li>
167                  <li><a href="/overcast/latest">GET /overcast/latest</a> - Latest sync info</li>
168              </ul>
169          </div>
170  
171          <div class="section">
172              <h2>System</h2>
173              <ul>
174                  <li><a href="/health">GET /health</a> - Health check</li>
175              </ul>
176          </div>
177  
178          <p><em>"Attention is all you need"</em></p>
179      </body>
180      </html>
181      rErErFr'�indexrJ�s��BrFz/healthc��\'d\P4'dRMRp\RRRRRVR\P!4P4/4#)	zHealth check endpoint.�running�stopped�status�healthy�servicezSovereign OS Serverr�	timestamp)rC�is_aliverr�now�	isoformat)�
daemon_statuss r'�healthrVsT��"/��=�3I�3I�3K�3K�I�QZ�M���)��(��-��X�\�\�^�-�-�/�	��rFz/attention/statusc�
182  �\'g\RR/4R3#\PP4p\PP4pVP
183  Uu.uF*pV'gK
\
V4^8�gKRV9gK(VNK,	pp\RR\
VP4R\VPP44R,/R	R
184  VR,R\
VP4R
VP/RRVPRVPRVPR
/RR\
\PP 4R\
\PP"4//4#uupi)z!Get full attention system status.�error�Daemon not initialized���
185  �sessions�count�ids�N�
186  N�
cross_session�
187  attractors�N�N�events�focusr;�items�tokens�pressure�.0%�aha�
188  candidates�	validated)rr�cross_session_tracker�	get_stater;�cross_session_attractors�lenr\�list�keys�cross_events�
focus_session�
189  item_count�total_tokensri�aha_detectorrl�validated_ahas)�state�stream_state�arbs    r'�attention_statusr}(sl���6���!9�:�;�S�@�@��(�(�2�2�4�E��(�(�2�2�4�L�#�;�;�9�;�����q�6�A�:��*.�a�-��!�;�J�9����S����(��4����+�+�-�.�s�3�
190  �	��*�S�/��c�%�,�,�-��U�(�(�
191192  	��\�,�,��l�/�/��<�0�0��5�
193194  	��#�f�1�1�<�<�=���V�0�0�?�?�@�
195  �����9s�&
196  F�5
F�F�Fz/attention/sessionsc�4�\'g\RR/4R3#\PP4p.pVPP4F�wr#TP
RTRVPRVP'dVPP4MRRVP'dVPP4MRR	\VP4R
197  ,RVP/4K�	\R\V4R
V/4#)zGet active session info.rXrYrZ�id�source�startedN�
last_activity�topicsr_r?r]r\)rrrnror\rg�appendr��
198  started_atrTr�rrr�r?rq)rzr\�sid�infos    r'�attention_sessionsr�Ks����6���!9�:�;�S�@�@��(�(�2�2�4�E��H��^�^�)�)�+�	������#��d�k�k��d�o�o�o�t���0�0�2�4��t�?Q�?Q�?Q�T�/�/�9�9�;�W[��d�4�;�;�'��,��$�/�/�

199  �	�,����X���H���rFz/attention/attractorsc��\'g\RR/4R3#\PP4p.pVPF`pV'd\V4^8gRV9dK$VPPV.4pVPRVRVR\V4/4Kb	VPRR	R
200  7\R\V4RVR
,/4#)z*Get cross-session attractors (hot topics).rXrYrZr[�topicr\�
session_countc��VR,#)r�rE��xs&r'�<lambda>�&attention_attractors.<locals>.<lambda>zs	��!�O�"4rFT��key�reverser]rb:N�N)
201  rrrnrorprq�
active_topics�getr��sort)rzrbr�r\s    r'�attention_attractorsr�ds����6���!9�:�;�S�@�@��(�(�2�2�4�E��J��/�/����E�
202  �Q��$�%�-���&�&�*�*�5�"�5������U����S��]�
203  �	�0��O�O�4�d�O�C����Z���j��o���rFz/attention/coherencec	��\'g\RR/4R3#\PPRR7p.pVFwr#pVP	RVRVR
R	V/4K!	\R
204  \V4RVR,/4#)
zGet coherence risk assessment.rXrYrZg333333�?��	thresholdr��
205  risk_scorerjr\r]�high_risk_topicsrc)rr�coherence_detector�get_high_risk_topicsr�rq)�	high_risk�risksr��scorer\s     r'�attention_coherencer��s����6���!9�:�;�S�@�@��)�)�>�>��>�M�I��E�"+���h�
����U��U�3�K���
206  �	�#,����U���E�#�J���rFz/attention/streamc��\'g\RR/4R3#\PP4p\PP	RR7p\RRVP
207  RVPR	VPR
208  
RVPRVPR

/RVR,Uu.uFHpRVPR,RVPR

RVPPRVP/NKJ	up/4#uupi)zGet context stream state.rXrYrZi')�
209  max_tokensrzrwr�rirjrv�
avg_attention�.2f�	top_itemsr_rrc�	attention�priorityr�)rrr;ro�get_contextrwr�rirvr�r�attention_scorer��valuer�)rzrg�items   r'�attention_streamr��s���6���!9�:�;�S�@�@��!�!�+�+�-�E��!�!�-�-��-�?�E����E�.�.��%�*�*��5�>�>�#�.��%�*�*��� 3� 3�C�8�
210  �	��c�
211  �
212  �#���d�g�g�c�l��� 4� 4�S�9��D�M�M�/�/��$�+�+�	
�#�
213  �����
214  s�-ADz/attention/inject/<session_id>�POST)�methodsc�f�\'g\RR/4R3#\PP4pVPUu.uF*pV'gK
\V4^8�gKRV9gK(VNK,	ppVPP4Uu.uF
qDV8wgKVNK	pp\PPRR7pVUUUu.uFwrtpW9gKRVRV/NK	p	pppV'g	V	'dvR	p
215  V'd0V
216  R
217  \V4RRPVR
,4R2,
p
218  V	'd+V
219  RRPRV	R,44R2,
p
220  V
221  R,
p
222  MRp
223  \RVR\V4RVR,RV	R
,RV
224  /4#uupiuupiuupppi)zy
225  Get cross-session awareness to inject into a session.
226  
227  Called by Claude Code hooks to get context about other sessions.
228  rXrYrZr[��?r�r�r�z<cross-session-awareness>
229  zHot topics across z other sessions: �, �N�NzCoherence risk: c3�2"�TF
qR,x�K	R#5i)r�NrE)�.0�rs& r'�	<genexpr>�#attention_inject.<locals>.<genexpr>�s���3[�HZ�1�g�J�J�HZ�s��N�Nz</cross-session-awareness>N�
230  session_id�other_sessionsrbr_�coherence_risks�injection_message)rrrnrorprqr\rsr�r��join)r�rzr|rb�sr�r��tr\�relevant_risks�messages&          r'�attention_injectr��s����6���!9�:�;�S�@�@��(�(�2�2�4�E�#�;�;�9�;�����q�6�A�:��*.�a�-��!�;�J�9�"'���!4�!4�!6�J�!6�A�z�/�a�a�!6�N�J��)�)�>�>��>�M�I�(��'�N�A�(��!�	!��!�W�a� �'����^�/����+�C��,?�+@�@Q�RV�R[�R[�\f�gi�\j�Rk�Ql�ln�o�o�G���)�$�)�)�3[��WY�HZ�3[�*[�)\�\^�_�_�G��/�/������j��#�n�-��j��o��>�"�-��W�����39��K��s0�
231  F"�
F"�)F"�2F"�F'�#F'�F,�!
232  F,z/attention/tuningc�v�\'g\RR/4R3#\P4p\V4#)z-Get current context stream tuning parameters.rXrYrZ)rr�get_tuning_report)�reports r'�attention_tuningr��s7���6���!9�:�;�S�@�@�
�
%�
%�
'�F��6�?�rFz/attention/engage/<item_id>c�
233  �\'g\RR/4R3#\P!4;'g/pVP	RR4pVP	R4p\PWV4\RRR	VRV/4#)
234  a
235  Record operator engagement with a context item.
236  
237  Body (JSON):
238      engagement_type: 'reference' | 'expand' | 'action' | 'ignore' | 'dismiss' | 'revive'
239      context: optional dict with additional context
240  
241  This feeds the tuner to learn operator preferences.
242  rXrYrZ�engagement_type�	reference�contextrN�ok�item_id)rrr�get_jsonr��record_engagement)r��datar�r�s&   r'�attention_engager��s����6���!9�:�;�S�@�@�����#�#��D��h�h�0�+�>�O��h�h�y�!�G�
243  ���W�w�?���$��7��?���rFz/context/directc���\'g\RR/4R3#\P!4;'g/pVP	RR4pV'g\RRRR/4R	3#\PV4p\R
244  VPRVPRVPR
VPRVPRVPRVPRVPRVP/	4#)u�
245  Natural language context direction.
246  
247  Body (JSON):
248      input: "Load the last three days" or "Remind me what I was working on"
249  
250  Supports multi-step refinement:
251      1. "Remind me what I was working on" → summary + options
252      2. "Focus on the authentication work" → narrowed
253      3. "Load that" → inject into context
254  
255  Returns conversational response with suggestions for next steps.
256  rXzDirector not initializedrZ�input�zNo input provided�hintzDTry: "Remind me what I was working on" or "Load the last three days"�r��sessions_foundr��	decisions�suggestions�items_loaded�
tokens_loaded�
257  can_refine�refinement_options)r<rrr�r��processr�r��topics_found�decisions_foundr�r�r�r�r�)r��
258  input_text�responses   r'�context_directr�
s�������!;�<�=�s�B�B�����#�#��D����'�2�&�J����(��Z�
259  ��
��	�
260   �'�'�
261  �3�H���8�#�#��(�1�1��(�'�'��X�-�-��x�+�+���-�-���/�/��h�)�)��h�9�9�
262  �
263  �
264  rFz/context/signalsc���\P!4;'g/pVPRR4pV'g\RR/4R3#\	V4p\VP44#)z�
265  Detect signal words in text and return weight/persistence info.
266  
267  Body (JSON):
268      text: "Remember this core principle: attention is all you need"
269  
270  Returns signal analysis including weight modifier and suggested tags.
271  �textr�rXzNo text providedr�)rr�r�rr�to_dict)r�r��	detections   r'�context_signalsr�7sa������#�#��D��8�8�F�B��D����!3�4�5�s�:�:��t�$�I��9�$�$�&�'�'rFz/context/validation�GETc�R�\'g\RR/4R3#\PP4p\R\	V4RVUu.uFGpRVP
272  RVPR,R	VPR
273  
R\VP4/NKI	up/4#uupi)z<Get items that need validation ('what do you think?' items).rXrYrZr]rgr�content�N��Nr�r��tags)
274  rrr;�get_items_needing_validationrqrr�r�rr�signal_tags)rgr�s  r'�context_validationr�Ls����6���!9�:�;�S�@�@��!�!�>�>�@�E����U����
275  ����d�g�g��4�<�<��-��� 4� 4�S�9���T�-�-�.�	
��
276  �����
277  s�A
B$z/context/validate/<item_id>c�(�\'g\RR/4R3#\P!4;'g/pVP	RR4p\P
278  P
W4pV'd\RRRVRV/4#\RR	/4R
279  3#)zd
280  Validate or reject an item that was seeking validation.
281  
282  Body (JSON):
283      validated: true or false
284  rXrYrZrmTrNr�r�zItem not found�)rrrr�r�r;�
validate_item)r�r�rm�successs&   r'�context_validater�bs����6���!9�:�;�S�@�@�����#�#��D�����d�+�I��#�#�1�1�'�E�G����d��w���
285  ��	���!1�2�3�S�8�8rFz
/context/minec �L�\PR8Xd!\P!4;'g/pM\Pp\	VPR^�44pVPR4p\	VPRR44pVPRR4p\
\\44pVPVVVR7pVR	8XdVP4^�R
286  R/3#\RR
VPRVPRVPRVPR
/RVP R,Uu.uFQpRVP"R,RVP$R\'VP(4RVP*RVP,/NKS	upRVP.R,Uu.uF0pRVP"R,RVP$RVP*/NK2	upRVP0R,Uu.uF0pRVP"R,RVP$RVP*/NK2	upR\3VP4P74RR R!7R,Uu.uFwpR"VP8R#VP:R$VP<R%VP>R&VP@R'\C\3VPDPG4R(R)7R*,4/NKy	upR+VPHR,U	U
287  u.uFwr�R,V	R-V
288  /NK
	up
289  p	/4#uupiuupiuupiuupiuup
290  p	i).a
291  Mine transcripts for insights, patterns, and unmined content.
292  
293  GET parameters or POST body (JSON):
294      hours: Hours to look back (default 168 = 7 days)
295      speaker: Filter by speaker ('Rick', 'Claude', or null for all)
296      min_weight: Minimum weight threshold (default 0.0)
297      format: 'json' or 'markdown' (default 'json')
298  
299  Returns:
300      - unmined_insights: High-weight items not yet integrated
301      - principles: Identified principles
302      - decisions: Decisions made
303      - topic_clusters: Topics with related items
304      - signal_patterns: Your common signal word usage
305      - validation_seeking_rate: How often you ask "what do you think?"
306  r��hours�speaker�
307  min_weight��format�json)�
308  hours_back�speaker_filterr��markdown�Content-Type�
text/markdown�summary�sessions_analyzed�atoms_processed�time_window_hours�validation_seeking_ratez.1%�unmined_insightsrcr�:Ni,N�weightr��session�
309  principles�N�Nr�r��N�N�topic_clustersc��VP#�N)�total_weight)�cs&r'r��context_mine.<locals>.<lambda>�s��a�n�nrFTr�r�r�
insight_count�decision_count�principle_count�related_topicsc��V^,)#)�rEr�s&r'r�r�s
310  ��1�Q�4�%rF)r�r��signal_patterns�signalr])%r�methodr��args�floatr�rr5r6�mine�to_markdownrrr	r
311  rrr�r
rrr�r�r�rr��sortedr�valuesr�rrrr�dictrrg�your_common_signals)r�r�r�r��
output_format�minerr��atom�clusterr!r]s           r'�context_miner/~s)��&�~�~������!�'�'�R���|�|���$�(�(�7�C�(�)�E��h�h�y�!�G��t�x�x��c�2�3�J��H�H�X�v�.�M�
�C��-�.�E�
�Z�Z������F��
312  �"��!�!�#�S�>�?�*K�K�K�����!9�!9��v�5�5���!9�!9�%�&�*H�*H��)M�	
313  �	��/�/��4�	
314  �5��
�4�<�<��-��$�+�+���T�Y�Y���4�?�?��4�<�<�
�5�	
315  �	��)�)�#�.�

316  �/��	�4�<�<��-��$�+�+��4�?�?�
�
317  /�

318  �	��(�(��-�

319  �.��	�4�<�<��-��$�+�+��4�?�?�
�
320  .�

321  �	�"��%�%�,�,�.�,����	�
322  ��������� 4� 4���!6�!6� �'�"8�"8�!�7�#:�#:� �$�v��*�*�0�0�2�'�(��(�#�
323  
��
324  �$	�!'�!;�!;�C�!@�
325  �!@�
���v�w��.�!@�
326  �g7�7�7��	
327  ��
328  ��
329  ��
330  ��$
331  s �6AL�%6L�36L�A=L�2L  z/context/mine/topicsc
�L�\\PPR^�44p\	\\44pVPVR7.p.pVPP4F�wrEVPRVRVPRVPRVPRVP/4VPP4F%wrgV^8�gKVPRVR	VRV/4K'	K�	\!R
332  VRVR\#V4R
\#V4/4#)z]
333  Get topic map for visualization.
334  
335  Returns nodes and edges suitable for graph visualization.
336  r��rrr
�insightsr�rr�r4�nodes�edges�
337  node_count�
338  edge_count)r$rr#r�rr5r6r%�_topic_clustersrgr�rrrrrrrq)r�r,r3r4r�r.�relatedr]s        r'�context_mine_topicsr9�s��
�'�,�,�"�"�7�C�0�1�E��C��-�.�E�	�J�J�%�J� �
�E��E��/�/�5�5�7���
����%��g�*�*���-�-���/�/��'�1�1�
339  �	�&�4�4�:�:�<�N�G��q�y�����e��g��e���=�8�"������c�%�j��c�%�j�	��rFz/pipeline/statusc�r�\'g\RR/4R3#\\P44#)zGet ingestion pipeline status.rX�Pipeline not initializedrZ)r+rrorErFr'�pipeline_statusr<s5������!;�<�=�s�B�B��%�/�/�1�2�2rFz/pipeline/collectc�~�\'g\RR/4R3#\P4p\RRRV/4#)z(Trigger manual collection of new events.rXr;rZrNr��events_collected)r+r�collect_new_events)�	collecteds r'�pipeline_collectrAsJ������!;�<�=�s�B�B�"�5�5�7�I���$��I���rFz/pipeline/processc�~�\'g\RR/4R3#\P4p\RRRV/4#)z+Trigger manual processing of queued events.rXr;rZrNr��events_processed)r+r�
process_queue)�	processeds r'�pipeline_processrF"sJ������!;�<�=�s�B�B�"�0�0�2�I���$��I���rFz/pipeline/backfillc���\'g\RR/4R3#\P!4;'g/p\	VPR^�44p\P
VR7p\V4#)zo
340  Backfill historical data from all sources.
341  
342  Body (JSON):
343      hours: Hours to look back (default 168 = 7 days)
344  rXr;rZr�r1)r+rrr�r$r��backfill)r�r��results   r'�pipeline_backfillrJ/sh������!;�<�=�s�B�B�����#�#��D��$�(�(�7�C�(�)�E�
�
(�
(�E�
(�
:�F��6�?�rFz
345  /correlatec��\PR8Xd!\P!4;'g/pM\Pp\	VPR^�44pVPRR4p\
VR7pVR8XdVP4^�RR/3#\R	R
346  VPRVPRVPR
VP/RVPR,Uu.uFqDP4NK	upRVPR,Uu.uFqDP4NK	upRVP R,Uu.uFqDP4NK	upR\#VP$P'44R,UUu/uFwrVWVR,bK	upp/4#uupiuupiuupiuuppi)aM
347  Run multi-source correlation.
348  
349  GET parameters or POST body:
350      hours: Hours to look back (default 168)
351      format: 'json' or 'markdown' (default 'json')
352  
353  Correlates across:
354      - Claude sessions
355      - Monologue voice transcripts
356      - Comet browser history
357  
358  Returns aha moments, validation-seeking, research-corroborated insights.
359  r�r�rrr1rrrrr
360  �total_events�multi_source_moments�sources�aha_momentsr�validation_seeking�research_corroborated�topic_research_mapr_r�)rr"r�r#r$r�rr&rr
361  rLrM�
sources_foundrOr�rPrQrrrRrg)r�r�r+r��m�k�vs       r'�	correlaterWAs��� �~�~������!�'�'�R���|�|���$�(�(�7�C�(�)�E��H�H�X�v�.�M�
�%�
0�F��
362  �"��!�!�#�S�>�?�*K�K�K�����!9�!9��F�/�/�"�F�$?�$?��v�+�+�	
363  �	�V�-?�-?��-D�E�-D��	�	��-D�E��F�4M�4M�c�4R�S�4R�q�y�y�{�4R�S��v�7S�7S�TW�7X�!Y�7X�!�)�)�+�7X�!Y��D��9R�9R�9X�9X�9Z�4[�\_�4`�a�4`�D�A�q�B�%�x�4`�a�����F��S��!Y��as�(F-�F2�F7�F<z/correlate/ahac���\'g\RR/4R3#\\PPR^44p\P
VR7p\R\V4RV/4#)z2Get stored aha moments from the pipeline database.rXr;rZ�limit�rYr]rO)r+r�intrr#r��get_aha_momentsrq)rY�momentss  r'�
correlate_ahar^lsn������!;�<�=�s�B�B����� � ��"�-�.�E� �0�0�u�0�=�G����W���w���rFz/correlate/high-confidencec�>�\'g\RR/4R3#\\PPRR44p\
\PPR^244p\PVVR7p\R\V4RVR	V/4#)
364  z'Get high-confidence correlated moments.rXr;rZ�min_confidencer�rY)r`rYr]r])	r+rr$rr#r�r[�get_high_confidence_momentsrq)r`rYr]s   r'�correlate_high_confidencerb{s�������!;�<�=�s�B�B��7�<�<�+�+�,<�c�B�C�N����� � ��"�-�.�E� �<�<�%��=��G�
365  ���W���.��7���rFz
366  /artifactsc��\\PPRR44p\PPRR4p\	VR7pVR8XdVP4^�RR/3#\
R	R
367  VPRVPR\VP4R
VP/RVPR,Uu.uF�pRVPPRVPP!4RVPP"RVPP$RVPP&R\)VP*4R,/NK�	upRVPR,Uu.uFSpRVPRVP,P!4RVP$R\)VP*4R,/NKU	upRVP.R,RVP0R,R\)VP2P544R,UUu/uFwrVV\V4bK	upp/4#uupiuupiuuppi)a)
368  Analyze Claude.ai artifacts as crystallization markers.
369  
370  GET parameters:
371      hours: Hours to look back (default 336 = 2 weeks)
372      format: 'json' or 'markdown' (default 'json')
373  
374  Artifacts represent moments where thinking crystallized into
375  something concrete - they're high-weight signal markers.
376  r��Prrr1rrrr�artifacts_analyzedr
377  �unclosed_loops�artifact_types�crystallization_momentsr�namerQ�duration_hoursr
�typer�r_�createdr�rr��topic_distribution)r$rr#r�rr&rrer
378  rqrfrgrh�artifact�conversation_namerQrTrjr
�
artifact_typerrr��
379  created_at�principles_in_artifacts�decisions_in_artifacts�topic_to_artifactsrg)r�r+r��cmr|rUrVs       r'�	artifactsrv�s��
�'�,�,�"�"�7�C�0�1�E��L�L�$�$�X�v�6�M�
�%�
0�F��
380  �"��!�!�#�S�>�?�*K�K�K��� �&�";�";���!9�!9��c�&�"7�"7�8��f�3�3�	
381  �	"��4�4�S�9�
382  $
383  �:������5�5��R�\�\�3�3�5� �"�+�+�"<�"<��"�+�+�,�,�����1�1��$�r�y�y�/�#�.�

�:�
384  $
385  �	��*�*�3�/�
386  �0����+�+��1�<�<�1�1�3��!�(�(��$�q�x�x�.��,�	
�0�
387  �	�f�4�4�S�9��V�2�2�3�7��T�&�:S�:S�:Y�:Y�:[�5\�]`�5a�b�5a�T�Q�q�#�a�&�y�5a�b�;����
388  $
389  ��
390  ��cs�BI�9AI
�(I z/artifacts/unclosedc��\\PPRR44p\	VR7p\R\
VP4RVPUu.uFXpRVPRVPP4RVPR	VPR
391  \VP4/NKZ	up/4#uupi)z�
392  Get unclosed OODA loops - artifacts created but never revisited.
393  
394  These represent ideas that crystallized but weren't integrated.
395  r�rdr1r]rfrirlr
rkr�)r$rr#r�rrrqrfrorqrTr
rprrr�)r�r�r|s   r'�artifacts_unclosedrx�s���
�'�,�,�"�"�7�C�0�1�E�
�%�
0�F����V�*�*�+���*�*�	
396  �+��
��+�+��1�<�<�1�1�3��!�(�(������$�q�x�x�.�
�+�	
397  �����	
398  s�ACz
/graph/statusc�v�\'g\RR/4R3#\P4p\V4#)zq
399  Get semantic graph status from Sovereign_Estate.
400  
401  Shows atoms, edges, gravity wells, and altitude distribution.
402  rX�!Graph integration not initializedrZ)r=rro)rzs r'�graph_statusr{�s8������!D�E�F��K�K��'�'�)�E��5�>�rFz/graph/atomsc�z�\'g\RR/4R3#\\PPR^244p\PPR4p\
\PPRR44p\PVVVR7p\R	\V4R
403  V/4#)z�
404  Get recent atoms from the semantic graph.
405  
406  GET parameters:
407      limit: Max atoms to return (default 50)
408      source_type: Filter by 'user' or 'assistant'
409      min_weight: Minimum weight threshold
410  rXrzrZrY�source_typer�r�)rYr}r�r]�atoms)	r=rr[rr#r�r$�get_recent_atomsrq)rYr}r�r~s    r'�graph_atomsr��s�������!D�E�F��K�K����� � ��"�-�.�E��,�,�"�"�=�1�K��w�|�|�'�'��c�:�;�J��.�.����
/�
�E����U������rFz/graph/atom/<uuid>c��\'g\RR/4R3#\PV4pV'g\RR/4R3#\V4#)zGet a specific atom by UUID.rXrzrZzAtom not foundr�)r=r�get_atom)�uuidr-s& r'�
411  graph_atomr�sS������!D�E�F��K�K��%�%�d�+�D����!1�2�3�S�8�8��4�=�rFz/graph/resonancec���\'g\RR/4R3#\\PPR^44p\P
VR7p\R\V4RV/4#)zw
412  Get high-resonance atoms - the most significant content.
413  
414  GET parameters:
415      limit: Max atoms to return (default 20)
416  rXrzrZrYrZr]�high_resonance_atoms)r=rr[rr#r��get_high_resonance_atomsrq)rYr~s  r'�graph_resonancer�sn������!D�E�F��K�K����� � ��"�-�.�E��6�6�U�6�C�E����U������rFz/graph/gravity-wellsc��\'g\RR/4R3#\P4p\R\V4RV/4#)zv
417  Get gravity wells - highly connected nodes in the graph.
418  
419  Gravity wells have 10+ edges and represent central topics.
420  rXrzrZr]�
gravity_wells)r=r�get_gravity_wellsrq)�wellss r'�graph_gravity_wellsr�/sN������!D�E�F��K�K��/�/�1�E����U������rFz
/graph/searchc�X�\'g\RR/4R3#\PP	RR4pV'g\RR/4R3#\\PP	R^44p\P
WR	7p\R
421  VR\V4RV/4#)
zh
422  Search atoms by text content.
423  
424  GET parameters:
425      q: Search query
426      limit: Max results (default 20)
427  rXrzrZ�qr�zNo query providedr�rYrZ�queryr]�results)r=rrr#r�r[�search_atomsrq)r�rYr�s   r'�graph_searchr�As�������!D�E�F��K�K��L�L���S�"�%�E����!4�5�6��;�;����� � ��"�-�.�E��,�,�U�,�@�G������W���7���rFz
/graph/streamc
428  ��aa�\'g\RR/4R3#^RIoSP4oV3Rlp\P	RV4VV3Rlp\V!4RR	R
429  RRR
R/R7#)aC
430  Server-Sent Events stream of new graph events.
431  
432  Connect with EventSource to receive real-time updates:
433      - atom: New atom added
434      - edge: New edge formed
435      - gravity_well: New gravity well detected
436  
437  Example:
438      const es = new EventSource('/graph/stream');
439      es.onmessage = (e) => console.log(JSON.parse(e.data));
440  rXrzrZNc�*<�SPV4R#r��put��event�client_queues&�r'�on_event�graph_stream.<locals>.on_eventq��������rF�allc
441  3�<"�R\P!RRR\PP/4R2x�SP^R7pR\P!RVPRVPRVPP4/4R2x�Kd SPd#R\P!RR/4R2x�K�i;i5i)	�data: rk�	connectedr?�
442  
443  ��timeoutr�rQ�	heartbeat)r�dumpsr=r>r?r��
444  event_typer�rQrT�Empty�r�r��queues ��r'�generate�graph_stream.<locals>.generatews������t�z�z�6�;��FW�F^�F^�Fi�Fi�"j�k�l�lp�q�q��
G�$�(�(��(�4���t�z�z�6�5�3C�3C�V�U�Z�Z�Yd�fk�fu�fu�f�f�gB�+C� D�E�EI�J�J���;�;�
G��t�z�z�6�;�*?�@�A��F�F�
G�s)�:C�A B �C� /C�C�C�C�text/event-stream�
Cache-Control�no-cache�
445  Connection�
446  keep-alive�X-Accel-Buffering�no��mimetype�headers)r=rr��Queue�	subscriber�r�r�r�r�s  @@r'�graph_streamr�[sy�������!D�E�F��K�K���;�;�=�L� �����x�0�G���
447  �$��Z��,���
448  ��rFz
/graph/reloadc��\'g\RR/4R3#\P!4;'g/p\	VPR^44pV^8Xd\P
4pM\PVR7p\RRRVPR	VPR
449  \VP4/4#)zd
450  Reload graph data from files.
451  
452  POST body (JSON):
453      days: Days to load (default 1 for today only)
454  rXrzrZ�days)�	days_backrN�reloadedr~r4r�)r=rrr�r[r��
455  load_today�
456  load_ranger?r6rqr�)r�r�rzs   r'�graph_reloadr��s�������!D�E�F��K�K�����#�#��D��t�x�x���"�#�D��q�y�!�,�,�.��!�,�,�t�,�<����*���!�!���!�!���U�0�0�1�	��rFz/unified/reportc���\'g\RR/4R3#\\PPR^44p\PPRR4p\P
VR7pVR8XdVP4^�R	R
457  /3#\RVP4RVPR
,Uu.uFq3P4NK	upRVPR
,Uu.uFq3P4NK	upRVPR,R\VPP44R
,UUu/uFwrEWER,bK	upp/4#uupiuupiuuppi)a
458  Get unified correlation report across ALL sources.
459  
460  Combines:
461  - Claude sessions
462  - Monologue transcripts
463  - Browser history
464  - Semantic graph
465  - Artifacts
466  
467  GET parameters:
468      hours: Hours to look back (default 24)
469      format: 'json' or 'markdown' (default 'json')
470  rX�"Unified correlator not initializedrZr�rrr1rrrrrOr�high_resonancer�r_r�r�)r@rr$rr#r��get_unified_reportr&r�rOr�r�rr�unified_topic_maprg)r�r+r�r&rUrVs      r'�unified_reportr��s?�� ����!E�F�G��L�L��'�,�,�"�"�7�B�/�0�E��L�L�$�$�X�v�6�M�
�
2�
2�e�
2�
D�F��
471  �"��!�!�#�S�>�?�*K�K�K���6�>�>�#��V�-?�-?��-D�E�-D��	�	��-D�E���0E�0E�c�0J�K�0J�1�9�9�;�0J�K���-�-�c�2���V�-E�-E�-K�-K�-M�(N�s�(S�T�(S���1��e�8�(S�T�����E��K��Ts�E*�2E/�
E4z/unified/timelinec���\'g\RR/4R3#\\PPR^44p\PPRR4pV'dVP
R4MRp\\PPR	^d44p\PVVR
472  7RVp\R\V4RTRVUu.uFqUP4NK	up/4#uupi)
z�
473  Get timeline of all events across all sources.
474  
475  GET parameters:
476      hours: Hours to look back (default 24)
477      types: Comma-separated event types to include (optional)
478      limit: Max events (default 100)
479  rXr�rZr��typesr��,NrY)r�event_typesr]re)r@rr$rr#r��splitr[�get_timelinerqr�)r��	types_strr�rYrer&s      r'�unified_timeliner��s�������!E�F�G��L�L��'�,�,�"�"�7�B�/�0�E���� � ��"�-�I�*3�)�/�/�#�&��K����� � ��#�.�/�E�
�
,�
,���-��
�u��F�
480  ���V������/��1�9�9�;��/�����0s�C:z/unified/streamc
481  ��aa�\'g\RR/4R3#^RIoSP4oV3Rlp\P	RV4VV3Rlp\V!4RR	R
482  RRR
R/R7#)aP
483  Server-Sent Events stream of unified events from ALL sources.
484  
485  Connect with EventSource to receive real-time updates from:
486  - Graph (atoms, edges, gravity wells)
487  - Correlations (aha moments)
488  - High resonance content
489  
490  Example:
491      const es = new EventSource('/unified/stream');
492      es.onmessage = (e) => console.log(JSON.parse(e.data));
493  rXr�rZNc�*<�SPV4R#rr�r�s&�r'r�� unified_stream.<locals>.on_eventr�rFr�c3�<<"�R\P!RRR.RO/4R2x�SP^R7pR\P!VP44R2x�K@ SPd#R\P!RR/4R2x�Kri;i5i)r�rkr�rNr�r�r�)�graph�
494  correlatorrv)rr�r�r�r�r�s ��r'r�� unified_stream.<locals>.generates������t�z�z�6�;�	�Cg�"h�i�j�jn�o�o��
G�$�(�(��(�4���t�z�z�%�-�-�/�:�;�4�@�@���;�;�
G��t�z�z�6�;�*?�@�A��F�F�
G�s(�$B�<A&�$B�&/B�B�B�Br�r�r�r�r�r�r�r�)r@rr�r�r�rr�s  @@r'�unified_streamr��sw�������!E�F�G��L�L���;�;�=�L� �� � ���1�G���
495  �$��Z��,���
496  ��rFz/mobile/statusc	�@�.p\'d;\P4pVPRVR,RVR,R24\'d4\P^dR7pVPR\	V424\
497  'dL\
498  PP4pVPRVPR	VPR
499  
R24\RR
RRPV4R\P!4P4/4#)zo
500  Quick status optimized for mobile displays.
501  
502  Returns a compact summary suitable for iOS Shortcuts or widgets.
503  z
504  Pipeline: r>z collected, �correlations_foundz
 correlationsrZz
Aha moments: z	Context: z items, rjz	 pressurerNr�rz | rQ)r+ror�r\rqrr;rvrirr�rrSrT)�status_partsrzrkr{s    r'�
mobile_statusr�s���L���"�,�,�.�����j��/A�)B�(C�<�PU�Vj�Pk�Ol�ly�z�{��� �0�0�s�0�;�����m�C��H�:�6�7��v��,�,�6�6�8�����i��(?�(?�'@���I^�I^�_b�Hc�cl�m�n���$��5�:�:�l�+��X�\�\�^�-�-�/���rFz
/mobile/briefc
505  �\�RR.p\'d�\P^R7pV'd�VPR4VR,FlpVPR4'd)RP	VPR.4R,4MRpVPR	VR
506  VPR^4R
24Kn	VPR4\
507  'd\
508  PP4pV'dYVPR
4VR,F)pVPRVPR,R24K+	VPR4VPR4VPR4VPR4VPR4RP	V4^�RR/3#)zh
509  Today's brief - insights and suggested next steps.
510  
511  Returns plain text suitable for reading on mobile.
512  z# Today's Briefr�rZz## Recent Insightsr�r�r��generalz- [z
] confidence �
513  confidencerjz## Needs Your Inputz- :N�PN�...z## Suggested Actionsz#- Review validation-seeking momentsz$- Check high-confidence correlationsz- Run backfill if data is staler[r�
514  text/plain)	r+r\r�r�r�rr;r�r�)�linesrkrTr��validation_itemsr�s      r'�mobile_briefr�:se����#�E��� �0�0�q�0�9����L�L�-�.���W�W��?@�u�u�X������1�5�5��2�#6�r�#:�;�T]�����s�6�(�-����l�A�8N�s�7S�T�U��
�L�L����v�!�0�0�M�M�O����L�L�.�/�(��,�,�����r�$�,�,�s�"3�!4�C�8�9�-��L�L���
515  �L�L�'�(�	�L�L�6�7�	�L�L�7�8�	�L�L�2�3��9�9�U��S�>�<�"@�@�@rFz/mobile/ahac���\'gR#\\PP	R^
516  44p\PVR7pR\
V4R2R.p\V^4EF^wr4VP	RR4R,pVP	R4'd)R	PVP	R.4R
517  ,4MRpVP	R^4pVP	RR4pVPR
VRV24V'dVPRV24VPRVR
24V'dVPRVR,24VP	R.4p	V	'dEV	^,'d6V	^,R,PRR4p
518  VPRV
519  R24VPR4EKa	RPV4^�RR/3#)z\
520  Recent aha moments in clean, readable format.
521  
522  Returns plain text list of recent insights.
523  rYrZz# z Recent Aha Momentsr�rQr_r�r�:N�Nr��browser_contextz## z. zTopics: zConfidence: rjz
Researching: :N�<N�claude_contentrr[� z> r�rr�)r;rZ)r+r[rr#r�r\rq�	enumerater�r��replace)rYr]r��irT�tsr��conf�browser�claude�previews           r'�
524  mobile_ahar�_s�����.�.����� � ��"�-�.�E� �0�0�u�0�=�G��#�g�,��2�
3�R�8�E��'�1�%���
�U�U�;��
#�C�
(��78�u�u�X������1�5�5��2�.�r�2�3�B���u�u�\�1�%���%�%�)�2�.��
���s�1�#�R��t�_�%���L�L�8�F�8�,�-�
���|�D��:�.�/���L�L�=�����7�8����'��,���f�Q�i�i��Q�i��o�-�-�d�C�8�G��L�L�2�g�Y�c�*�+�
���R��'&�*�9�9�U��S�>�<�"@�@�@rFz/mobile/capturec��\'g\RR/4R3#\P'd;\P!4pVPRR4pVPR.4pM!\PPR4p.pV'g\RR/4R	3#\V4p^R
525  I	H
526  pHpV!R\P!4PR42VR
VPVP P#\%V44VP&R,RV9R7p\P(P+V4\RRRVP,RVP.R\1VP24/4#)z�
527  Capture a quick thought from mobile.
528  
529  Body (JSON or plain text):
530      thought: The thought to capture
531      tags: Optional list of tags
532  
533  Injects directly into context stream with high weight.
534  rXrYrZ�thoughtr�r��utf-8zNo thought providedr�)�
535  StreamItem�Priorityzmobile-z%Y%m%d%H%M%S�mobile_captureg�?�?)rr�r�r�r��
signal_weight�needs_validationrN�capturedrr
)rrr�is_jsonr�r�r��decoder�core.attention.context_streamr�r�rrS�strftime�HIGH�suggested_tags�union�set�weight_modifierr;�add_itemrr�rrr�)r�r�r��signalsr�r�r�s       r'r�r��sO���6���!9�:�;�S�@�@��������!���(�(�9�b�)���x�x���#���,�,�%�%�g�.�������!6�7�8�#�=�=��W�%�G�C��
�X�\�\�^�,�,�^�<�=�>�������*�*�0�0��T��;��-�-��3�����D����"�"�4�(���*��d�g�g��$�$�$���T�%�%�&�	��rFz	/overcastc
536  ��\PPR4pV'dRV9d\RRRR/4R3#\PRRR	7\P!4PR
537  4p\RVR2,pVPV4\R
,pVPV4\V4p\R\V4R
RVPRR4R24\RRR\V4RVRV/4#)zReceive OPML from iOS Shortcut.r�z<opmlrNrXr�zInvalid OPML contentr�T)�parents�exist_okz%Y-%m-%d_%H%M%S�	overcast_z.opml�latest.opmlz[Overcast] Received: r�z bytes, �podcastsr�z	 podcastsr��bytesrQ�stats)rr�r�r�OVERCAST_DIR�mkdirrrSr�
538  write_text�parse_opml_statsr"rqr�)�opml_contentrQ�timestamped_path�latest_pathrs     r'�receive_overcastr�s���<�<�&�&�w�/�L��7�,�6���g��-�
539  ��
��	����t�d��3�����'�'�(9�:�I�#�	�)��E�&B�B������-���.�K����<�(�
�\�*�E�	�!�#�l�"3�A�!6�h�u�y�y��UX�?Y�>Z�Zc�
540  d�e���$���\�"��Y���	��rFz/overcast/latestc
541  �L�\R,pVP4'g\RRRR/4#VP4p\	V4p\
542  P!VP4P4p\RRRVP4R\V4R	V/4#)
543  z$Get info about latest Overcast sync.r
rN�no_syncr�zNo OPML received yetr��	last_syncrr)r�existsr�	read_textrr�
fromtimestamp�stat�st_mtimerTrq)rr�r�mtimes    r'�overcast_latestr"�s�����.�K��������i��-�
544  ��	�
545  �#�#�%�G��W�%�E��"�"�;�#3�#3�#5�#>�#>�?�E���$��U�_�_�&���W����	��rFc�0�V^8�dQhR\R\/#)�r�return)r5r))rs"r'�__annotate__r&�s��!�!�3�!�4�!rFc��\P!V4pVPR4p^;p;rEVPR4FfpVP	R4R8XdV^,
pK$VP	R4R8XgK<V^,
pVP	R4R8XgK]V^,
pKh	RVR	VRV/# \
546  dpR
547  \
T4/uRp?#Rp?ii;i)zExtract stats from OPML.�body�outlinerk�rsszpodcast-episode�played�1r�episodesrXN)�ET�
548  fromstring�find�iterr�r!r5)r�rootr(rr-r+r)r&s&       r'rr�s���!��}�}�\�*���y�y�� ��'(�(��(�8��y�y��+�G��{�{�6�"�e�+��A�
�����V�$�(9�9��A�
���;�;�x�(�C�/��a�K�F�
,��H�j�(�H�f�M�M���!���Q�� � ��!�s*�A4B1�;B1�B1�1C�<C�C�C�__main__u�
549  ╔══════════════════════════════════════════════════════════════╗
550  ║                  Sovereign OS Server                          ║
551  ╠══════════════════════════════════════════════════════════════╣
552  ║  Port: uF                                                   ║
553  ║  Sessions: u

554  ║  Daily: u�
555  ║                                                              ║
556  ║  Endpoints:                                                  ║
557  ║    /                      - Dashboard                        ║
558  ║    /health                - Health check                     ║
559  ║    /attention/status      - Attention state                  ║
560  ║    /attention/sessions    - Active sessions                  ║
561  ║    /attention/attractors  - Cross-session topics             ║
562  ║    /attention/coherence   - Coherence risk                   ║
563  ║    /attention/stream      - Context stream                   ║
564  ║    /overcast              - POST OPML webhook                ║
565  ║                                                              ║
566  ║  "Attention is all you need"                                 ║
567  ╚══════════════════════════════════════════════════════════════╝
568  z0.0.0.0FT)�host�port�debug�threaded)s�__doc__rr�sysrAr�pathlibr�flaskrrrr�xml.etree.ElementTree�etree�ElementTreer.�path�insertr5�__file__�parent�core.attention.daemonr�core.attention.cross_sessionr	�core.attention.coherence_riskr
569  rr�core.attention.natural_directorrr
�core.attention.signal_wordsr�core.attention.transcript_minerr�!core.attention.ingestion_pipelinerr�&core.attention.multi_source_correlatorrr� core.attention.artifact_analyzerrr� core.attention.graph_integrationrr�!core.attention.unified_correlatorrr�PORT�homer6r7r�__name__�apprrCr<r+�pipeline_threadr=r@r(r-rG�routerJrVr}r�r�r�r�r�r�r�r�r�r�r�r/r9r<rArFrJrWr^rbrvrxr{r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr"rr"r rErFr'�<module>rTs����,��
570  ����3�3�"�"�������3�t�H�~�,�,�3�3�4�5�1�D�A�?�[�6�;�P�[�P�T�W����y�y�{�D�D���I�I�K�8�8�	��y�y�{�?�?���H�o��
571  ���
�����������
572  �
573  �//�h���3��D��D�N���9��	��	������� ��D��� �!��"��0���"�#��$��:���!�"��#��*������ ��8���+�f�X��>�+�?�+�`������ �����(�6�(��;��<��8����v�h��/�&�0�&�R�����x��0�(�1�(�(��� �5�'��2��3��*���(�6�(��;�9�<�9�6���?�U�F�O��4�_�5�_�D���!�E�7��3�%�4�%�T�����3��3��������1�	�2�	��������1�	�2�	�����&���2��3��"���<�%����1�'�2�'�T����e�W��-��.�����'�%���9��:��,���<�%���)�1�*�1�h��� �5�'��2��3��6���?��
574  ��
575  ����>�����8���� �	�!�	���������&���!�"��#��"���?�����2���?��-��-�`���?�V�H��-��.��8����� �� �F������ ��:�����*��*�^��������<���?��!A��!A�H���=��#A��#A�L����v�h��/�1�0�1�l���;����)� �*� �F��������,!�.�
��z��	��
�6���~�
�
�K��
��*�G�G���U�T�G�B�-rF