
    ^7im                         d Z ddlZddlZddlZddlmZmZmZ ddlmZ  ed      Z	e	dz  dz  Z
e	dz  d	z  Zd
ZddededefdZddededefdZdededee   fdZdededdfdZy)u(  
ATLAS — Research & Intelligence General
========================================
Fires N parallel research scout sub-agents via `claude -p` subprocess calls.

Usage:
    from core.generals.atlas import spawn_atlas
    results = spawn_atlas("Top 20 Australian digital agencies", scout_count=5)
    N)datetimetimezone	timedelta)Pathz/mnt/e/genesis-systemdataswarm_progresshiveprogressa  You are ATLAS, the Research & Intelligence General for Genesis.

Your mission: {mission}

Sub-task {task_index} of {total_tasks}: {sub_task}

Instructions:
1. Research this topic thoroughly using WebSearch and WebFetch tools
2. Extract key facts, numbers, names, URLs
3. Identify competitive intelligence relevant to Genesis (ReceptionistAI / AI voice widgets)
4. Output a structured research report with: Summary, Key Facts, Opportunities, Risks
5. Write KG entity if you discover significant intelligence (append to KNOWLEDGE_GRAPH/entities/)

Output format:
## Research Report: {sub_task}
### Summary
### Key Facts
### Competitive Intelligence
### Opportunities for Genesis
### Sources
missionscout_countreturnc                    t         j                  dd       t        j                  dd       dt        j                         j
                  dd  }t        |z  }|j                  dd       t        | |      }|d| d||dd	d	t        j                  t        j                        j                         t        |      g d
}t         | dz  }t        ||       g }t        |      D ]d  \  }}	t        j!                  | |dz   ||	      }
|d|dz   ddz  }|d|dz   ddz  j#                  |
       t%        d|dz    d| d|	dd         f ||d<   t        ||       t%        d| d| d| dd         |S )aw  
    Spawn N parallel ATLAS research scouts via subprocess.

    Parameters
    ----------
    mission : str
        High-level research mission (e.g. "Top 20 AU digital agencies Brisbane")
    scout_count : int
        Number of parallel research scouts to fire (default 5)

    Returns
    -------
    dict with keys: swarm_id, mission, agent_count, status, output_dir
    T)parentsexist_okatlas_N   ATLASzgoogle/gemini-2.5-flashrunningr   )swarm_idgeneralr   modelagent_count	sub_tasksstatusstories_completedstories_completed_this_hour
started_at
output_dir	processesz.json   )r   
task_indextotal_taskssub_taskscout_02dz.mdz
_prompt.mdz[ATLAS] Scout /z	 queued: <   r   z[ATLAS] Swarm u    launched — z scouts for: )SWARM_PROGRESS_DIRmkdirHIVE_PROGRESS_DIRuuiduuid4hex_decompose_missionr   nowr   utc	isoformatstr_save_state	enumerateATLAS_SYSTEM_PROMPTformat
write_textprint)r   r   r   r   r   swarm_state
state_filer   ir#   promptoutput_files               ,/mnt/e/genesis-system/core/generals/atlas.pyspawn_atlasr?   ,   s    TD9D48

((!,-.H"X-JTD1 #7K8I *"'(ll8<<0::<*oK  $
%&88J
K( I + L8$++1u#	 , 
 !VAaC9C#88 
qs3iz2	2>>vFqse1[M8CR=/JK)L,  )K
K(	N8*N;-}WUXVX\N
[\    c                     t        | |      S )u9   Alias for spawn_atlas — used by genesis_hive.py router.)r   )r?   )r   r   s     r>   spawnrB   w   s    wK88r@   countc                 `    d|  d|  d|  d|  d|  d|  d|  d|  d	|  d
|  g
}|d| S )z
    Break a mission into sub-tasks.
    In production this would use an LLM decomposer.
    For now: generate numbered research angles.
    zOverview and market landscape: z)Top players and competitive positioning: zPricing models and packages: z#Technology stack and capabilities: z&Contact details and outreach targets: zRecent news and developments: z$Weaknesses and gaps we can exploit: z"Customer reviews and pain points: z+Partnership and integration opportunities: z*Regulatory and compliance considerations: N )r   rC   angless      r>   r.   r.   |   s}     *'3
3G9=
'y1
-gY7
0	:
(	2
.wi8
,WI6
5gY?
4WI>F &5>r@   pathstatec                     |j                         D ci c]  \  }}|dk7  s|| }}}| j                  t        j                  |dt                     y c c}}w )Nr      )indentdefault)itemsr7   jsondumpsr2   )rG   rH   kv
state_copys        r>   r3   r3      sI    #(;;=E41aA4D!Q$EJEOODJJz!SAB Fs
   AA)   )__doc__rN   
subprocessr+   r   r   r   pathlibr   	REPO_ROOTr(   r*   r5   r2   intdictr?   rB   listr.   r3   rE   r@   r>   <module>r[      s       2 2 ()	'*:: &3  .H H3 Ht HV93 9S 9 9
 C DI *Cd C4 CD Cr@   