
    7iN                         d Z ddlZddlZddlmZmZ ddlmZ  ed      Zedz  dz  Zedz  d	z  Z	ed
z  dz  Z
ed
z  dz  ZdZdZdZdedefdZdedefdZdededdfdZy)u9  
MNEMOSYNE — Memory & Intelligence General
==========================================
Fires KG extractor + RLM worker agents to ingest content into memory.

Usage:
    from core.generals.mnemosyne import spawn_mnemosyne
    results = spawn_mnemosyne("/mnt/e/genesis-system/hive/progress/session_52_handoff.md")
    N)datetimetimezone)Pathz/mnt/e/genesis-systemdataswarm_progresshiveprogressKNOWLEDGE_GRAPHentitiesaxiomsa  You are MNEMOSYNE, the Memory & Intelligence agent for Genesis.

Content to ingest: {content_path}

Your mission: Extract knowledge entities and axioms from this content.

Instructions:
1. Read the content at {content_path}
2. Extract entities: people, companies, products, capabilities, metrics, events
3. Extract axioms: rules, patterns, learnings, best practices discovered
4. Format entities as JSONL (one JSON object per line)
5. Format axioms as JSONL (one JSON object per line)
6. Write entities to: {entities_output}
7. Write axioms to: {axioms_output}

Entity format:
{{"id": "snake_case_id", "type": "entity_type", "name": "Human Name", "description": "...", "source": "filename", "created": "ISO8601", "tags": []}}

Axiom format:
{{"id": "axiom_id", "text": "The learning/rule/pattern", "domain": "domain_area", "confidence": 0.9, "source": "filename", "created": "ISO8601"}}

Focus on extracting ACTIONABLE intelligence relevant to Genesis operations.
av  You are running an ALPHA EVOLVE cycle for Genesis MNEMOSYNE.

Content: {content_path}

Alpha Evolve 4-phase cycle:
1. INGEST: Read and understand all content
2. EXTRACT: Pull out learnings, failures, wins, patterns
3. SYNTHESIZE: Combine with existing KG to find new truths
4. HARDCODE: Write final axioms to KNOWLEDGE_GRAPH/axioms/

Output your synthesis to: {output_file}
a  You are a MNEMOSYNE RLM (Reward Learning Model) worker.

Session content: {content_path}

Your task:
1. Extract preference pairs from this session (what worked vs what didn't)
2. Rate quality of decisions made (1-10 scale with reasoning)
3. Identify reward signals for the Genesis reward model
4. Write preference data to: {output_file}

Format: JSON array of preference pairs:
[{{"prompt": "...", "chosen": "...", "rejected": "...", "reward_delta": 0.5}}]
content_to_ingestreturnc                 X   t         j                  dd       t        j                  dd       t        j                  dd       t        j                  dd       dt        j                         j                  dd  }t        |z  }|j                  dd       t        |       j                         rt        |       nd}|duxr |j                         }|duxr |j                         }g }|r|g}n<|rt        |j                  d            dd }n|dz  }|j                  | dd	        |g}d
}t        |      D ][  \  }	}
|
j                   j#                  dd      dd }t        d| d|dd  dz  }t        d| d|dd  dz  }t$        j'                  t)        |
      t)        |      t)        |            }|d|	dz   ddz  j                  |       |d|	dz   ddz  }t*        j'                  t)        |
      t)        |            }|d|	dz   ddz  j                  |       |d|	dz   ddz  }t,        j'                  t)        |
      t)        |            }|d|	dz   ddz  j                  |       |dz  }t/        d|
j0                          ^ |dd| dd  d |t3        |      d
d
d!t5        j6                  t8        j:                        j=                         t)        |      d"}t         | dz  }t?        ||       t/        d#| d$| d%t3        |       d&       |S )'z
    Spawn KG + RLM workers to process content into Genesis memory.

    Parameters
    ----------
    content_to_ingest : str
        Path to file or directory to ingest, OR raw text content

    Returns
    -------
    dict with swarm metadata
    T)parentsexist_ok
mnemosyne_N   z**/*.md   zraw_input.mdiP  r    _      z.jsonl)content_pathentities_outputaxioms_outputkg_extractor_   02dz
_prompt.mdalpha_evolve_z.md)r   output_file
rlm_prefs_z.jsonrlm_   z"[MNEMOSYNE] 3 workers queued for: 	MNEMOSYNEzIngest: P   zdeepseek/deepseek-chatrunning)swarm_idgeneralmissionmodelagent_countfiles_processedstories_completedstories_completed_this_hourstatus
started_at
output_dirz[MNEMOSYNE] Swarm u    — z workers for z files) SWARM_PROGRESS_DIRmkdirHIVE_PROGRESS_DIRKG_ENTITIES_DIRKG_AXIOMS_DIRuuiduuid4hexr   existsis_fileis_dirsortedglob
write_text	enumeratestemreplaceKG_EXTRACTOR_PROMPTformatstrALPHA_EVOLVE_PROMPTRLM_WORKER_PROMPTprintnamelenr   nowr   utc	isoformat_save_state)r   r'   r1   r   r;   r<   files_to_process	temp_fileworkers_spawnedi	file_pathslugentities_out
axioms_out	kg_prompt	ae_output	ae_prompt
rlm_output
rlm_promptswarm_state
state_files                        0/mnt/e/genesis-system/core/generals/mnemosyne.pyspawn_mnemosyner_   J   s    TD9D48$6t4DJJL,,Ra012H"X-JTD1.23D.E.L.L.N4)*TXL$&A<+?+?+AG%?,*=*=*?F $&(>	!,"3"3I">?D /	.v67%;O!"23 E9~~%%c3/4 ':dV1Xbq\N&)QQ"z$q"1f%MM
'..Y-j/ / 
	
 
ac#Yj9	9EEiP =1S	!==	'..YI / 
	 
ac#Yj9	9EEiP  Jqs3iu"==
&--YJ . 

 
QqSIZ0	0<<ZH129>>2BCD=EB /456)&/0'(ll8<<0::<*oK $
%&88J
K(	xjo->mCP`LaKbbh
ij    c                     t        |       S )u=   Alias for spawn_mnemosyne — used by genesis_hive.py router.)r_   )r   s    r^   spawnrb      s    ,--r`   pathstatec                 Z    | j                  t        j                  |dt                     y )N   )indentdefault)r?   jsondumpsrE   )rc   rd   s     r^   rN   rN      s    OODJJuQ<=r`   )__doc__ri   r7   r   r   pathlibr   	REPO_ROOTr2   r4   r5   r6   rC   rF   rG   rE   dictr_   rb   rN    r`   r^   <module>rp      s      ' ()	'*:: &3 //*<--8 0  Zs Zt Zz.S .T .
>d >4 >D >r`   