
    ]+0j                         S r SSKrSSKrSSKJr  / SQrS\S\4S jrS\S\	4S jr
S	\\   S\\   4S
 jrS\S\4S jrS\S\S\4S jrS\S\	4S jrg)u  Builds the Reflect "journal" payload the Atlas app renders on its home page.

Pure + dependency-free (no livekit / no LLM) so the lightweight web server can
import and serve it on demand from the same volume files the agent writes:
  - therapy_sessions.json  (durable per-session reflections: summary/themes/...)
  - therapy_stats.json     (usage counters: sessions, total_seconds, guided runs)

Returns {log, themes, cards}:
  log    — the usage tab (sessions, minutes, guided runs, topics tracked)
  themes — "what we're working on", aggregated theme counts (most common first)
  cards  — up to 5 reminder/touch-point cards derived from recent sessions
    N)Counter)coralgreenamberbluepurplepinktealpathreturnc                      [        U 5       n[        R                  " U5      nS S S 5        [        W[        5      (       a  U$ / $ ! , (       d  f       N'= f! [
         a    / s $ f = fN)openjsonload
isinstancelist	Exceptionr   fdatas      /app/agent/src/journal.py
_load_listr      V    $Z199Q<D !$--t525 Z  	-   A AA A 
AA A%$A%c                      [        U 5       n[        R                  " U5      nS S S 5        [        W[        5      (       a  U$ 0 $ ! , (       d  f       N'= f! [
         a    0 s $ f = fr   )r   r   r   r   dictr   r   s      r   
_load_dictr      r   r   itemsc                     [        5       / p!U  H^  nU=(       d    SR                  5       nUR                  5       nU(       d  M5  XQ;  d  M<  UR                  U5        UR	                  U5        M`     U$ )N )setstriploweraddappend)r   seenoutrawskeys         r   _deduper,   (   sX    r#YBggi1HHSMJJqM  J    textc                     U =(       d    SR                  5       R                  S5      R                  5       nU(       d  gUS   R                  5       USS -   nUS-   $ )z(Tidy a fragment into one clean sentence.r!   .r      N)r#   rstripupper)r.   r*   s     r   	_sentencer4   3   sQ    	##C(..0A	!

quAs7Nr-   nc                    U =(       d    SR                  SS5      R                  S5       Vs/ s H)  o"R                  5       (       d  M  UR                  5       PM+     nnSR                  US U 5      US U (       a  S-   $ S-   $ s  snf )Nr!   
 r0   z. )replacesplitr#   join)r.   r5   ppartss       r   _first_sentencesr>   <   sr    !% 4 4T3 ? E Ec JX J1ggiYQWWY JEX99U2AY%)3<<<< Ys   B	Bdata_dirc           
         [        [        R                  R                  U S5      5      n[	        [        R                  R                  U S5      5      n[        5       n0 nU Hx  nUR                  S/ 5       H_  nU=(       d    SR                  5       nU(       d  M%  X6R                  5       ==   S-  ss'   UR                  UR                  5       U5        Ma     Mz     UR                  S5       VVs/ s H  u  pxUR                  Xw5      US.PM     n	nn[        UR                  S5      =(       d    [        U5      5      [        UR                  S	5      =(       d    S
S-  5      [        UR                  S5      =(       d    S
5      [        U5      S.n
[        [        USS  5      5      n/ n[!        U VVs/ s H  oUR                  S/ 5        H  oPM     M     snn5      n/ SQn[#        US S 5       H8  u  nnUR%                  SUU[        U5      -     ['        U5      SU 3SS.5        M:     U(       aS  US
   R                  S5      =(       d    SR                  5       nU(       a!  UR%                  SS[)        US5      SSS.5        U	(       a4  U	S
   S   nUR%                  SU S3SS UR                  5        S!3S"S.5        U HT  nUR                  S#5      =(       d    SR                  5       nU(       d  M4  UR%                  S$S%['        U5      S&S'S.5          O   US S( n[#        U5       H!  u  p[*        U[        [*        5      -     US)'   M#     XUS*.$ s  snnf s  snnf )+Nztherapy_sessions.jsonztherapy_stats.jsonthemesr!   r1      )labelcountsessionstotal_secondsr   <   guided_runs)rE   minutesrH   topicsopen_intentions)zSomething you said you'd tryzA promise to yourselfzWorth following up on   zYou said you'd tryzLet's talk about this: zti-flag)tagtitlebodytalk_prompticonsummaryz	Last timezWhere we left off   z*Continue from where we left off last time.zti-calendar-clockrC   zWorth rememberingz keeps surfacinguG   It runs under a lot of what you bring — maybe a thread worth pulling.zLet's explore why z keeps coming up for me.zti-target-arrowwhat_helpedzWhat helpedzThis landed for youz&Can we do more of what's been helping?zti-sparkles   color)logrA   cards)r   osr   r;   r   r   getr#   r$   
setdefaultmost_commonintlenroundr   reversedr,   	enumerater&   r4   r>   _PALETTE)r?   rE   statscountsdisplayr*   tkcrA   rX   recentrY   i
intentionsintent_titlesidxintentrS   tophelpeds                        r   build_journalrr   A   s   "'',,x1HIJHrww||H.BCDE #9F Gx$Ab!A779"qwwy!, %  >D=O=OPQ=R=RTQ'++a#a0=R   		*->X?%))O49R?@599]38q9f+	C (8BC=)*FEVRVUU;Lb5Q!5Q!VRSJM
 !BQ0V+&sS-?'?@!&)!8A!	
 1 !9==+1r88:LL&0,Wa8#O/ Qi *5 01a!3CIIK=@XY)	
 %%&,"3356LL(2%f-#K)   "1IE% a#h-/0'
 ! 599Y  Ss   1 M6$M
)__doc__r   rZ   collectionsr   rc   strr   r   r   r   r,   r4   r^   r>   rr    r-   r   <module>rw      s     	  IS T S T 49 c C C =3 =3 =3 =
Z:C Z:D Z:r-   